zhubaomin
2025-02-21 f4d1e8f5e01e12a90050d94e50571b9cb1ebe109
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.dy.pipIrrIrrigate.irrigateUnit;
 
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pipIrrGlobal.daoIr.IrGroupUnitMapper;
import com.dy.pipIrrGlobal.daoIr.IrIrrigateUnitMapper;
import com.dy.pipIrrGlobal.daoIr.IrUnitClientMapper;
import com.dy.pipIrrGlobal.pojoIr.IrIrrigateUnit;
import com.dy.pipIrrGlobal.pojoIr.IrUnitClient;
import com.dy.pipIrrGlobal.voIr.VoUnit;
import com.dy.pipIrrGlobal.voIr.VoUnitOne;
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.List;
import java.util.Map;
 
/**
 * @author :WuZeYu
 * @Date :2024/5/16  18:11
 * @LastEditTime :2024/5/16  18:11
 * @Description
 */
@Slf4j
@Service
public class IrrigateUnitSv {
    @Autowired
    private IrIrrigateUnitMapper irIrrigateUnitMapper;
    @Autowired
    private IrGroupUnitMapper irGroupUnitMapper;
 
    @Autowired
    private IrUnitClientMapper irUnitClientMapper;
 
    /**
     * 创建灌溉单元
     *
     * @param po
     * @return
     */
    public Integer addIrrigateUnit(IrIrrigateUnit po) {
        po.setOperateDt(new Date());
        po.setDeleted((byte) 0);
        int rows = irIrrigateUnitMapper.insertSelective(po);
        if (rows == 0) {
            return 0;
        }
        return 1;
    }
 
    /**
     * 删除灌溉单元
     *
     * @param id
     */
    public Integer deleteUnit(Long id) {
        int rows = irIrrigateUnitMapper.deleteLogicById(id);
        irGroupUnitMapper.deleteByUnitId(id);
        if (rows == 0) {
            return 0;
        }
        return 1;
    }
 
    /**
     * 修改灌溉单元
     * @param po
     * @return
     */
    public Integer updateUnit(IrIrrigateUnit po){
        po.setOperateDt(new Date());
        int rows = irIrrigateUnitMapper.updateByPrimaryKeySelective(po);
        if (rows == 0){
            return 0;
        }
        return 1;
    }
 
    /**
     * 获取一个灌溉单元
     * @param id
     * @return
     */
    public VoUnitOne selectById(Long id){
        VoUnitOne unit = irIrrigateUnitMapper.selectById(id);
        return unit;
    }
 
    /**
     * 分页查询项目
     * @param queryVo
     * @return
     */
    public QueryResultVo<List<VoUnit>> getUnits(QueryVo queryVo){
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        Long itemTotal = irIrrigateUnitMapper.getRecordCount(params);
 
        QueryResultVo<List<VoUnit>> rsVo = new QueryResultVo<>();
        rsVo.pageSize = queryVo.pageSize;
        rsVo.pageCurr = queryVo.pageCurr;
        rsVo.calculateAndSet(itemTotal, params);
        rsVo.obj = irIrrigateUnitMapper.getUnits(params);
        return rsVo;
    }
 
    //灌溉单元分配(农户租地)
    public Long addUnitClient(IrUnitClient po) {
        irUnitClientMapper.insert(po);
        return po.getId();
    }
 
    /**
     * 删除灌溉单元与农户关联
     * @param id
     * @return
     */
    public Integer deleteUnitClient(Long id) {
        return irUnitClientMapper.deleteByPrimaryKey(id);
    }
 
}