ScheduleRule1FlatController.java 3.05 KB
package com.bsth.controller.schedule;

import com.bsth.controller.BaseController;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.GuideboardInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.repository.schedule.ScheduleRule1FlatRepository;
import com.bsth.service.schedule.EmployeeConfigInfoService;
import com.bsth.service.schedule.GuideboardInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xu on 16/7/4.
 */
@RestController
@RequestMapping("sr1fc")
public class ScheduleRule1FlatController extends BaseController<ScheduleRule1Flat, Long> {

    @Autowired
    private ScheduleRule1FlatRepository scheduleRule1FlatRepository;
    @Autowired
    private GuideboardInfoService guideboardInfoService;
    @Autowired
    private EmployeeConfigInfoService employeeConfigInfoService;

    @Override
    public ScheduleRule1Flat findById(@PathVariable("id") Long aLong) {
        return scheduleRule1FlatRepository.findOneExtend(aLong);
    }

    /**
     * 覆写方法,因为form提交的方式参数不全,改用 json形式提交 @RequestBody
     * @Title: save
     * @Description: TODO(持久化对象)
     * @param @param t
     * @param @return    设定文件
     * @return Map<String,Object>  {status: 1(成功),-1(失败)}
     * @throws
     */
    @RequestMapping(method = RequestMethod.POST)
    public Map<String, Object> save(@RequestBody ScheduleRule1Flat t){
        // TODO:根据编码查找id,不做错误检测,暂时这样做,以后前端直接传过来
        // 1、查找路牌配置id
        Map<String, Object> param1 = new HashMap<>();
        param1.put("xl.id_eq", t.getXl().getId());
        param1.put("lpName_eq", null);

        String[] lpNames = t.getLpNames().split(",");
        String[] lpIds = new String[lpNames.length];
        for (int i = 0; i < lpNames.length; i++) {
            param1.put("lpName_eq", lpNames[i]);
            Iterable<GuideboardInfo> guideboardInfos = guideboardInfoService.list(param1);
            lpIds[i] = guideboardInfos.iterator().next().getId().toString();
        }
        t.setLpIds(StringUtils.join(lpIds, ","));

        // 2、查找人员配置id
        Map<String, Object> param2 = new HashMap<>();
        param2.put("xl.id_eq", t.getXl().getId());
        param2.put("dbbm_eq", null);

        String[] ryDbbms = t.getRyDbbms().split(",");
        String[] ryIds = new String[ryDbbms.length];
        for (int j = 0; j < ryDbbms.length; j++) {
            param2.put("dbbm_eq", ryDbbms[j]);
            Iterable<EmployeeConfigInfo> employeeConfigInfos = employeeConfigInfoService.list(param2);
            ryIds[j] = employeeConfigInfos.iterator().next().getId().toString();
        }
        t.setRyConfigIds(StringUtils.join(ryIds, ","));

        return baseService.save(t);
    }

}