liurunyu
5 天以前 e8937f27fce194d015ce6c27d286e7fc89f5e580
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupSv.java
@@ -10,8 +10,11 @@
import com.dy.pipIrrGlobal.pojoIr.IrGroupUnit;
import com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup;
import com.dy.pipIrrGlobal.voIr.VoGroup;
import com.dy.pipIrrGlobal.voIr.VoGroupDetail;
import com.dy.pipIrrGlobal.voIr.VoGroupOne;
import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
import com.dy.pipIrrIrrigate.irrigateGroup.dto.IrrigateGroup;
import com.dy.pipIrrIrrigate.irrigateGroup.qo.QoGroup;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,6 +36,7 @@
public class IrrigateGroupSv {
    @Autowired
    private IrIrrigateGroupMapper irIrrigateGroupMapper;
    @Autowired
    private IrGroupUnitMapper irGroupUnitMapper;
@@ -168,6 +172,31 @@
    }
    /**
     * 根据轮灌组名称查询是否存在(添加轮灌组时使用)
     * @param groupCode 轮灌组名称
     * @return 是否存在
     */
    public boolean existsByGroupCode(String groupCode) {
        if (groupCode == null || "".equals(groupCode.trim())) {
            return false;
        }
        return irIrrigateGroupMapper.countByGroupCode(groupCode) > 0;
    }
    /**
     * 根据轮灌组名称查询是否存在(修改轮灌组时使用,排除当前ID)
     * @param groupCode 轮灌组名称
     * @param excludeId 需要排除的ID
     * @return 是否存在
     */
    public boolean existsByGroupCodeExcludeId(String groupCode, Long excludeId) {
        if (groupCode == null || "".equals(groupCode.trim())) {
            return false;
        }
        return irIrrigateGroupMapper.countByGroupCodeExcludeId(groupCode, excludeId) > 0;
    }
    /**
     * 删除轮灌组与农户管理
     * @param id
     * @return
@@ -249,4 +278,112 @@
            return map;
        }
    }
    /**
     * 修改轮灌组
     * @param po
     * @return
     */
    public Map updateIrrigateGroup(IrrigateGroup po) {
        // 修改轮灌组
        IrIrrigateGroup irrigateGroup = new IrIrrigateGroup();
        irrigateGroup.setId(po.getGroupId());
        irrigateGroup.setGroupCode(po.getGroupCode());
        irrigateGroup.setDefaultDuration(po.getDefaultDuration());
        irrigateGroup.setOperator(po.getOperator());
        irrigateGroup.setOperateTime(new Date());
        irrigateGroup.setDeleted((byte) 0);
        irIrrigateGroupMapper.updateByPrimaryKeySelective(irrigateGroup);
        // 删除轮灌组与取水口关联
        Long groupId = po.getGroupId();
        irGroupIntakeMapper.deleteByGroupId(groupId);
        // 添加轮灌组与取水口关联
        String[] intakeArr = po.getIntakes().split(",");
        Integer sort = 1;
        for(String intekeId : intakeArr) {
            String trimmed = intekeId.trim();
            if(trimmed.isEmpty()) {
                continue;
            }
            try {
                Long intakeIdLong = Long.parseLong(trimmed);
                IrGroupIntake irGroupIntake = new IrGroupIntake();
                irGroupIntake.setGroupId(groupId);
                irGroupIntake.setIntakeId(intakeIdLong);
                irGroupIntakeMapper.insert(irGroupIntake);
            } catch (NumberFormatException  e) {
                Map map = new HashMap<>();
                map.put("success", false);
                map.put("msg", "取水口ID格式错误");
                map.put("content", null);
                return map;
            }
        }
        Map map = new HashMap<>();
        map.put("success", true);
        map.put("msg", "修改轮灌组成功");
        map.put("content", null);
        return map;
    }
    /**
     * 查询轮灌组列表
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoGroupSimple>> getSimpleGroups(QoGroup queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        Long itemTotal = irIrrigateGroupMapper.getSimpleGroupCount(params);
        QueryResultVo<List<VoGroupSimple>> rsVo = new QueryResultVo<>();
        rsVo.pageSize = queryVo.pageSize;
        rsVo.pageCurr = queryVo.pageCurr;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = irIrrigateGroupMapper.getSimpleGroups(params);
        return rsVo;
    }
    /**
     * 查询全部轮灌组
     * @return
     */
    public List<VoGroupSimple> getAllGroups() {
        //Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        //Long itemTotal = irIrrigateGroupMapper.getSimpleGroupCount(params);
        //QueryResultVo<List<VoGroupSimple>> rsVo = new QueryResultVo<>();
        //rsVo.pageSize = queryVo.pageSize;
        //rsVo.pageCurr = queryVo.pageCurr;
        //rsVo.calculateAndSet(itemTotal, params);
        //rsVo.obj = irIrrigateGroupMapper.getSimpleGroups(null);
        //return rsVo;
        return irIrrigateGroupMapper.getSimpleGroups(null);
    }
    /**
     * 获取轮灌组详情
     * @param groupId
     * @return
     */
    public Map getGroupDetail(Long groupId) {
        try {
            VoGroupDetail voGroupDetail = irIrrigateGroupMapper.getGroupDetail(groupId);
            Map map = new HashMap<>();
            map.put("success", true);
            map.put("msg", "获取轮灌组详情成功");
            map.put("content", voGroupDetail);
            return map;
        } catch (Exception e) {
            Map map = new HashMap<>();
            map.put("success", false);
            map.put("msg", "获取轮灌组详情失败");
            map.put("content", null);
            return map;
        }
    }
}