zhubaomin
2025-03-29 4297d17c914dc6b2d64388776ba0db7fb093c1b9
pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupSv.java
@@ -1,18 +1,24 @@
package com.dy.pipIrrIrrigate.irrigateGroup;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoIr.IrGroupClientMapper;
import com.dy.pipIrrGlobal.daoIr.IrGroupIntakeMapper;
import com.dy.pipIrrGlobal.daoIr.IrGroupUnitMapper;
import com.dy.pipIrrGlobal.daoIr.IrIrrigateGroupMapper;
import com.dy.pipIrrGlobal.pojoIr.IrGroupClient;
import com.dy.pipIrrGlobal.pojoIr.IrGroupIntake;
import com.dy.pipIrrGlobal.pojoIr.IrGroupUnit;
import com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup;
import com.dy.pipIrrGlobal.voIr.VoGroup;
import com.dy.pipIrrGlobal.voIr.VoGroupOne;
import com.dy.pipIrrIrrigate.irrigateGroup.dto.IrrigateGroup;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,11 +31,16 @@
@Slf4j
@Service
public class IrrigateGroupSv {
    @Autowired
    private IrIrrigateGroupMapper irIrrigateGroupMapper;
    @Autowired
    private IrGroupUnitMapper irGroupUnitMapper;
    @Autowired
    private IrGroupClientMapper irGroupClientMapper;
    @Autowired
    private IrGroupIntakeMapper irGroupIntakeMapper;
    /**
     * 创建轮灌组
@@ -38,7 +49,7 @@
     * @return
     */
    public Integer addIrrigateGroup(IrIrrigateGroup po) {
        po.setOperateDt(new Date());
        po.setOperateTime(new Date());
        po.setDeleted((byte) 0);
        int rows = irIrrigateGroupMapper.insertSelective(po);
        if (rows == 0) {
@@ -67,7 +78,7 @@
     * @return
     */
    public Integer updateIrrigateGroup(IrIrrigateGroup po){
        po.setOperateDt(new Date());
        po.setOperateTime(new Date());
        int rows = irIrrigateGroupMapper.updateByPrimaryKeySelective(po);
        if (rows == 0){
            return 0;
@@ -110,7 +121,6 @@
     */
    public Integer addGroupUnit(IrGroupUnit po) {
        po.setOperateDt(new Date());
        po.setDeleted((byte) 0);
        int rows = irGroupUnitMapper.insertSelective(po);
        if (rows == 0) {
            return 0;
@@ -125,11 +135,118 @@
     * @return
     */
    public Integer deleteGroupUnit(IrGroupUnit po) {
        po.setOperateDt(new Date());
        int rows = irGroupUnitMapper.deleteByUnitIdGroupId(po);
        if (rows == 0) {
            return 0;
        }
        return 1;
    }
    /**
     * 查一个轮灌组绑定的灌溉单元id
     * @param groupId
     * @return
     */
    public List<Long> getGroupBindUnits(Long groupId) {
        List<Long> groupBindUnits = irGroupUnitMapper.getGroupBindUnits(groupId);
        return groupBindUnits;
    }
    /**
     *     //查未绑定轮灌组的灌溉单元id
     * @return
     */
    public List<Long> getNotBindUnits() {
        List<Long> notBindUnits = irGroupUnitMapper.getNotBindUnits();
        return notBindUnits;
    }
    //轮灌组关联农户
    public Long addGroupClient(IrGroupClient po) {
        irGroupClientMapper.insert(po);
        return po.getId();
    }
    /**
     * 删除轮灌组与农户管理
     * @param id
     * @return
     */
    public Integer deleteGroupClient (Long id) {
        return irGroupClientMapper.deleteByPrimaryKey(id);
    }
    /**
     * 创建轮灌组
     * @param po
     * @return
     */
    public Map addIrrigateGroup(IrrigateGroup po) {
        IrIrrigateGroup irrigateGroup = new IrIrrigateGroup();
        irrigateGroup.setGroupCode(po.getGroupCode());
        irrigateGroup.setDefaultDuration(po.getDefaultDuration());
        irrigateGroup.setOperator(po.getOperator());
        irrigateGroup.setOperateTime(new Date());
        irrigateGroup.setDeleted((byte) 0);
        irIrrigateGroupMapper.insertSelective(irrigateGroup);
        Long groupId = irrigateGroup.getId();
        if(groupId == null) {
            Map map = new HashMap<>();
            map.put("success", false);
            map.put("msg", "创建轮灌组失败");
            map.put("content", null);
            return map;
        }
        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;
    }
    /**
     * 根据组ID删除取水口关联
     * @param groupId
     * @return
     */
    public Map deleteGroup(Long groupId) {
        try {
            irGroupIntakeMapper.deleteByGroupId(groupId);
            irIrrigateGroupMapper.deleteByPrimaryKey(groupId);
            Map map = new HashMap<>();
            map.put("success", true);
            map.put("msg", "灌溉项目删除成功");
            map.put("content", null);
            return map;
        } catch (Exception e) {
            Map map = new HashMap<>();
            map.put("success", false);
            map.put("msg", "轮灌组删除失败");
            map.put("content", null);
            return map;
        }
    }
}