ke
2024-05-15 ab5c1c6cbcdeb98d84bdde3c111fe871466d3a5c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.sm.sjztmd.entity.*;
import cn.gistack.sm.sjztmd.mapper.TbDykeInvestigationMapper;
import cn.gistack.sm.sjztmd.mapper.TbResGeneralInvestigationMapper;
import cn.gistack.sm.sjztmd.service.*;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsBar;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsParams;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsPie;
import cn.gistack.sm.sjztmd.vo.TbDykeInvestigationParam;
import cn.gistack.sm.sjztmd.vo.TbResGeneralInvestigationParam;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @PROJECT_NAME: skjcmanager
 * @DESCRIPTION:
 * @USER: aix
 * @DATE: 2024/1/3 14:36
 */
@Service
@DS("zt")
@Transactional(rollbackFor = Exception.class)
public class TbDykeInvestigationServiceImpl extends ServiceImpl<TbDykeInvestigationMapper, TbDykeInvestigation> implements ITbDykeInvestigationService {
 
    @Autowired
    private ITbDykeInvestigationStateService tbDykeInvestigationStateService;
 
    @Autowired
    private IAttAdBaseService attAdBaseService;
 
    @Override
    @Transactional
    public R saveOrUpdateBy(TbDykeInvestigation entity) {
 
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("\"dyke_guid\"",entity.getDykeGuid());
        queryWrapper.eq("\"tb_year\"",entity.getTbYear());
//        queryWrapper.eq("\"tb_quarter\"",entity.getTbQuarter());
        TbDykeInvestigationState state = tbDykeInvestigationStateService.getOne(queryWrapper);
        if (null == state) {
            state = new TbDykeInvestigationState();
            state.setDykeGuid(entity.getDykeGuid());
            state.setTbQuarter(entity.getTbQuarter());
            state.setTbYear(entity.getTbYear());
            state.setCreateTime(entity.getCreateTime());
            state.setCreateUser(entity.getCreateUser());
        } else {
            if (state.getCheckState() == 1 || state.getCheckState() == 2) {
                return R.fail(entity.getDykeName() + "本年度已经普查完成,不能在提交了。");
            }
        }
 
        // 是否普查完成 1是 0否
        if (entity.getCheckState() != 0) {
            state.setCheckState(entity.getIsInvCom());
        }else{
            state.setCheckState(0);
        }
 
        tbDykeInvestigationStateService.saveOrUpdate(state);
 
        entity.setTbStateId(state.getGuid());
//        return R.status(this.saveOrUpdate(entity));
        this.saveOrUpdate(entity);
        return R.data(entity);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveOrUpdateByBatch(TbDykeInvestigationParam tbDykeInvestigationParam) {
        List<TbDykeInvestigation> list = tbDykeInvestigationParam.getList();
        TbDykeInvestigation entity = list.get(0);
 
        //查询该水库本年度是否有填报状态记录
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("\"dyke_guid\"",entity.getDykeGuid());
        queryWrapper.eq("\"tb_year\"",entity.getTbYear());
        TbDykeInvestigationState state = tbDykeInvestigationStateService.getOne(queryWrapper);
        if (null == state) {
            //无填报状态记录则新建
            state = new TbDykeInvestigationState();
            state.setDykeGuid(entity.getDykeGuid());
            state.setTbQuarter(entity.getTbQuarter());
            state.setTbYear(entity.getTbYear());
            state.setCreateTime(entity.getCreateTime());
            state.setCreateUser(entity.getCreateUser());
        } else {
            //查看填报状态,只有0填报中才可以一直填报
            if (state.getCheckState() == 1 || state.getCheckState() == 2) {
                return R.fail(entity.getDykeName() + "本年度已经普查完成,不能在提交了。");
            }
        }
 
        state.setCheckState(tbDykeInvestigationParam.getCheckState());
        tbDykeInvestigationStateService.saveOrUpdate(state);
        //先把数据移除
//        QueryWrapper delete = new QueryWrapper();
//        delete.eq("\"tb_state_id\"",state.getGuid());
//        boolean remove = remove(delete);
 
        for (int i = 0; i < list.size(); i++) {
            TbDykeInvestigation tbDykeInvestigation = list.get(i);
            //id清空方便批量新增
//                tbDykeInvestigation.setGuid("");
 
            if (tbDykeInvestigation.getCreateTime() == null){
                tbDykeInvestigation.setCreateTime(DateUtil.now());
            }
 
            if (tbDykeInvestigation.getCreateUser() == null){
                tbDykeInvestigation.setCreateUser(AuthUtil.getUserId().toString());
            }
 
            //设置状态表id
            tbDykeInvestigation.setTbStateId(state.getGuid());
        }
 
        return R.status(saveOrUpdateBatch(list));
 
    }
 
    @Override
    public StatisticsPie statisticsPie(StatisticsParams statisticsParams) {
        if (StringUtil.isNotBlank(statisticsParams.getAdCode())){
            //若行政区划不为空
            String adCode =statisticsParams.getAdCode();
 
            if (adCode.substring(0,4).indexOf("00") > -1) {
                //前四位包含00说明是湖北省      4200/00000000
                adCode =StringUtil.format("%{}%",adCode.substring(0,2));
            } else if (adCode.substring(0,6).indexOf("00") > -1) {
                //前六位包含00说明是市级    420100/000000
//                adCode = paramAd.substring(0,4);
                adCode =StringUtil.format("%{}%",adCode.substring(0,4));
            }else if (adCode.substring(0,8).indexOf("00") > -1){
                //前8位包含00 说明是区级     42011700/0000
//                adCode = paramAd.substring(0,6);
                adCode =StringUtil.format("%{}%",adCode.substring(0,6));
            }
            statisticsParams.setAdCode(adCode);
        }
 
        return baseMapper.statisticsPie(statisticsParams);
    }
 
    @Override
    public List<StatisticsBar> statisticsBar(StatisticsParams statisticsParams) {
//        String adCode = statisticsParams.getAdCode();
//        String adGuid = "";
//        //默认省
//        String adGrad = "1";
//
//        //若行政区划不为空
//        if (StringUtil.isNotBlank(adCode)){
//            if (adCode.substring(0,4).indexOf("00") > -1) {
//                //前四位包含00说明是湖北省      4200/00000000
//                adGrad = "1";
//                adGuid =StringUtil.format("%{}%",adCode.substring(0,2));
//                statisticsParams.setAdGuid(adGuid);
//            } else if (adCode.substring(0,6).indexOf("00") > -1) {
//                //前六位包含00说明是市级    420100/000000
//                adGrad = "2";
//                adGuid =StringUtil.format("%{}%",adCode.substring(0,4));
//                statisticsParams.setAdGuid(adGuid);
//            }else if (adCode.substring(0,8).indexOf("00") > -1){
//                //前8位包含00 说明是区级     42011700/0000
//                adGrad = "3";
//            }
//        }
//
//        List<StatisticsBar> list = new ArrayList<>();
//
//        if (adGrad.equals("3")){
//            //区级展示自己
//            list =  baseMapper.getCountyStatisticsBar(statisticsParams);
//        }else if (adGrad.equals("2")){
//            //市级展示区
//            list =  baseMapper.getCityStatisticsBar(statisticsParams);
//        }else  if (adGrad.equals("1")){
//            //省级展示市
//            list =  baseMapper.getProvinceStatisticsBar(statisticsParams);
//        }
 
 
        AttAdBase  attAdBase = attAdBaseService.getYwxtAdDetail(statisticsParams.getAdCode());
        statisticsParams.setAdGrad(attAdBase.getAdGrad());
        List list = baseMapper.getStatisticsBar(statisticsParams);
        return list;
    }
 
}