guoshilong
2023-11-28 ae37e30dcf71113f69d11fbe7cfef389a1fb9a01
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package cn.gistack.sm.sjztmd.service.impl;
 
import cn.gistack.sm.sjztmd.entity.TbAttResProjectUtilize;
import cn.gistack.sm.sjztmd.mapper.TbAttResProjectUtilizeMapper;
import cn.gistack.sm.sjztmd.service.ITbAttResBaseService;
import cn.gistack.sm.sjztmd.service.ITbAttResProjectUtilizeService;
import cn.gistack.system.user.feign.IUserClient;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.Date;
 
/**
 * @ClassName TbAttResProjectUtilizeServiceImpl
 * @Description TODO
 * @author zhongrj
 * @date 2023/8/14
 * @Version 1.0
 */
@Service
@DS("zt")
public class TbAttResProjectUtilizeServiceImpl extends ServiceImpl<TbAttResProjectUtilizeMapper, TbAttResProjectUtilize> implements ITbAttResProjectUtilizeService {
 
    @Autowired
    private IUserClient userClient;
 
    @Autowired
    private ITbAttResBaseService tbAttResBaseService;
 
    /**
     * 查询水库填报详情信息
     * @param guid
     * @return
     */
    @Override
    public TbAttResProjectUtilize getDetailByGuid(String guid) {
        return baseMapper.getDetailByResGuid(guid);
    }
 
    /**
     * 编辑
     * @param tbAttResProjectUtilize
     * @return
     */
    @Override
    public boolean updateByGuid(TbAttResProjectUtilize tbAttResProjectUtilize) {
        boolean edit = false;
        // 编辑标记
        if (tbAttResProjectUtilize.getCheckState()==4){
            edit = true;
        }
        // 查询是否存在
        TbAttResProjectUtilize detail = baseMapper.getDetailByResGuid(tbAttResProjectUtilize.getResGuid());
        // 更新日志
        setUpdateLog(detail,tbAttResProjectUtilize);
        // 修改
        int i = addOrUpdateByGuid(detail,tbAttResProjectUtilize);
        if (i>0){
//            if (!edit) {
//                tbAttResBaseService.updateFinalState(tbAttResProjectUtilize.getResGuid(), 0);
//            }
            return true;
        }
        return false;
    }
 
    /**
     * 审核
     * @param tbAttResProjectUtilize
     * @return
     */
    @Override
    public boolean auditByGuid(TbAttResProjectUtilize tbAttResProjectUtilize) {
        boolean edit = false;
        // 编辑标记
        if (tbAttResProjectUtilize.getCheckState()==4){
            edit = true;
        }
        // 查询是否存在
        TbAttResProjectUtilize detail = baseMapper.getDetailByResGuid(tbAttResProjectUtilize.getResGuid());
        // 更新操作日志
        setUpdateLog(detail,tbAttResProjectUtilize);
        // 更新审核日志
        setUpdateCheckLog(detail,tbAttResProjectUtilize);
        if (null!=detail){
            tbAttResProjectUtilize.setGuid(detail.getGuid());
        }
        // 驳回情况下将状态修改回0即已填写未提交状态
        if (tbAttResProjectUtilize.getCheckState()==3){
            tbAttResProjectUtilize.setCheckState(0);
        }
 
        detail.setCheckState(tbAttResProjectUtilize.getCheckState());
 
        // 更新数据
        int i = baseMapper.updateById(detail);
        if (i>0){
            if (!edit) {
                tbAttResBaseService.updateFinalState(tbAttResProjectUtilize.getResGuid(), tbAttResProjectUtilize.getCheckState());
            }
            return true;
        }
        return false;
    }
 
    /**
     * 更新
     * @param tbAttResProjectUtilize
     * @return
     */
    private int addOrUpdateByGuid(TbAttResProjectUtilize oldAbAttResBase,TbAttResProjectUtilize tbAttResProjectUtilize){
        int i = 0;
        if (null!=oldAbAttResBase){
            tbAttResProjectUtilize.setGuid(oldAbAttResBase.getGuid());
            // 更新
            i = baseMapper.updateById(tbAttResProjectUtilize);
            tbAttResBaseService.updateFinalState(tbAttResProjectUtilize.getResGuid(),tbAttResProjectUtilize.getCheckState());
        }else {
            tbAttResProjectUtilize.setCreateTime(new Date());
            i = baseMapper.insert(tbAttResProjectUtilize);
        }
        // 返回
        return i;
    }
 
    /**
     * @param oldAbAttResBase
     * @param newTbAttResProjectUtilize
     * 更新审核记录
     */
    private void setUpdateCheckLog(TbAttResProjectUtilize oldAbAttResBase,TbAttResProjectUtilize newTbAttResProjectUtilize) {
        String fillName = "";
        if (newTbAttResProjectUtilize.getCheckState()==2){
            fillName = "审核";
        }
        if (newTbAttResProjectUtilize.getCheckState()==3){
            fillName = "退回" + (null==newTbAttResProjectUtilize.getCheckLog()?"":":" + newTbAttResProjectUtilize.getCheckLog());
        }
 
        // 拼接
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
        String userName = AuthUtil.getUser().getUserName();
        String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
        StringBuilder builder = new StringBuilder();
        builder.append(time)
            .append(",")
            .append(fillName)
            .append(",")
            .append(userName)
            .append(",")
            .append(phone)
            .append(";");
        // 判断是否存在
        if (null==oldAbAttResBase){
            // 填报
            newTbAttResProjectUtilize.setCheckLog(builder.toString());
        }else {
            StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getCheckLog()?"":oldAbAttResBase.getCheckLog());
            stringBuilder.append(builder);
            // 填报
            newTbAttResProjectUtilize.setCheckLog(stringBuilder.toString());
        }
    }
 
    /**
     * @param oldAbAttResBase
     * @param newTbAttResProjectUtilize
     * 更新操作记录
     */
    private void setUpdateLog(TbAttResProjectUtilize oldAbAttResBase,TbAttResProjectUtilize newTbAttResProjectUtilize) {
        String fillName = "";
        if (newTbAttResProjectUtilize.getCheckState()==0){
            fillName = "编辑";
        }
        if (newTbAttResProjectUtilize.getCheckState()==1){
            fillName = "提交";
        }
        if (newTbAttResProjectUtilize.getCheckState()==2){
            fillName = "审核";
        }
        if (newTbAttResProjectUtilize.getCheckState()==3){
            fillName = "退回" + (null==newTbAttResProjectUtilize.getCheckLog()?"":":" + newTbAttResProjectUtilize.getCheckLog());
        }
        // 管理员编辑
        if (newTbAttResProjectUtilize.getCheckState()==4){
            fillName = "编辑";
            newTbAttResProjectUtilize.setCheckState(oldAbAttResBase.getCheckState());
        }
 
        // 拼接
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
        String userName = AuthUtil.getUser().getUserName();
        String phone = userClient.userInfoById(AuthUtil.getUserId()).getData().getPhone();
        StringBuilder builder = new StringBuilder();
        builder.append(time)
            .append(",")
            .append(fillName)
            .append(",")
            .append(userName)
            .append(",")
            .append(phone)
            .append(";");
        // 判断是否存在
        if (null==oldAbAttResBase){
            // 填报
            newTbAttResProjectUtilize.setLog(builder.toString());
        }else {
            StringBuilder stringBuilder = new StringBuilder(null==oldAbAttResBase.getLog()?"":oldAbAttResBase.getLog());
            stringBuilder.append(builder);
            // 填报
            newTbAttResProjectUtilize.setLog(stringBuilder.toString());
        }
    }
}