EmployeeConfigInfoServiceImpl.java 2.1 KB
package com.bsth.service.schedule;

import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.schedule.EmployeeConfigInfo;
import com.bsth.entity.schedule.rule.ScheduleRule1Flat;
import com.bsth.repository.schedule.EmployeeConfigInfoRepository;
import com.bsth.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.*;

/**
 * Created by xu on 16/5/10.
 */
@Service
public class EmployeeConfigInfoServiceImpl extends BaseServiceImpl<EmployeeConfigInfo, Long> implements EmployeeConfigInfoService {
    @Autowired
    private EmployeeConfigInfoRepository employeeConfigInfoRepository;
    @Autowired
    private ScheduleRule1FlatService scheduleRule1FlatService;


    @Override
    @Transactional
    public Map<String, Object> delete(Long aLong) {
        // 获取待作废的人员配置
        EmployeeConfigInfo employeeConfigInfo = employeeConfigInfoRepository.findOne(aLong);
        // 获取线路
        Line xl = employeeConfigInfo.getXl();
        // 查找线路的规则,比较人员配置信息
        Map<String, Object> param = new HashMap<>();
        param.put("xl.id_eq", xl.getId());
        Iterator<ScheduleRule1Flat> employeeConfigInfoIterator = scheduleRule1FlatService.list(param).iterator();
        List<String> ryConfigIds = new ArrayList<>();
        while (employeeConfigInfoIterator.hasNext()) {
            ScheduleRule1Flat scheduleRule1Flat = employeeConfigInfoIterator.next();
            ryConfigIds.addAll(Arrays.asList(scheduleRule1Flat.getRyConfigIds().split(",")));
        }

        Map<String, Object> map = new HashMap<>();

        if (ryConfigIds.contains(employeeConfigInfo.getId().toString())) {
            throw new RuntimeException("人员配置已被规则使用,不能删除,请先修改规则!");
        } else {
            employeeConfigInfo.setIsCancel(true);
            map.put("status", ResponseCode.SUCCESS);
        }

        return map;
    }

}