nidapeng
2024-03-20 c9f07c1f79e7ea9eb00925975d3ae2c9e8dcbd25
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package com.doumee.service.business.impl;
 
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.UnionApplyMapper;
import com.doumee.dao.business.dto.SaveUnionApplyDTO;
import com.doumee.dao.business.join.InsuranceApplyJoinMapper;
import com.doumee.dao.business.model.InsuranceApply;
import com.doumee.dao.business.model.Solutions;
import com.doumee.dao.business.model.UnionApply;
import com.doumee.service.business.UnionApplyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 合并投保单信息表Service实现
 * @author 江蹄蹄
 * @date 2024/03/12 11:34
 */
@Service
public class UnionApplyServiceImpl implements UnionApplyService {
 
    @Autowired
    private UnionApplyMapper unionApplyMapper;
 
    @Autowired
    private InsuranceApplyJoinMapper insuranceApplyJoinMapper;
 
    @Override
    public Integer create(UnionApply unionApply) {
        unionApplyMapper.insert(unionApply);
        return unionApply.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        unionApplyMapper.deleteById(id);
    }
 
    @Override
    public void delete(UnionApply unionApply) {
        UpdateWrapper<UnionApply> deleteWrapper = new UpdateWrapper<>(unionApply);
        unionApplyMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        unionApplyMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(UnionApply unionApply) {
        unionApplyMapper.updateById(unionApply);
    }
 
    @Override
    public void updateByIdInBatch(List<UnionApply> unionApplys) {
        if (CollectionUtils.isEmpty(unionApplys)) {
            return;
        }
        for (UnionApply unionApply: unionApplys) {
            this.updateById(unionApply);
        }
    }
 
    @Override
    public UnionApply findById(Integer id) {
        return unionApplyMapper.selectById(id);
    }
 
    @Override
    public UnionApply findOne(UnionApply unionApply) {
        QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
        return unionApplyMapper.selectOne(wrapper);
    }
 
    @Override
    public List<UnionApply> findList(UnionApply unionApply) {
        QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
        return unionApplyMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<UnionApply> findPage(PageWrap<UnionApply> pageWrap) {
        IPage<UnionApply> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<UnionApply> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(UnionApply::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(UnionApply::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(UnionApply::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(UnionApply::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(UnionApply::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(UnionApply::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(UnionApply::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(UnionApply::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(UnionApply::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(UnionApply::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.lambda().eq(UnionApply::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        if (pageWrap.getModel().getEndTime() != null) {
            queryWrapper.lambda().ge(UnionApply::getEndTime, Utils.Date.getStart(pageWrap.getModel().getEndTime()));
            queryWrapper.lambda().le(UnionApply::getEndTime, Utils.Date.getEnd(pageWrap.getModel().getEndTime()));
        }
        if (pageWrap.getModel().getStartTime() != null) {
            queryWrapper.lambda().ge(UnionApply::getStartTime, Utils.Date.getStart(pageWrap.getModel().getStartTime()));
            queryWrapper.lambda().le(UnionApply::getStartTime, Utils.Date.getEnd(pageWrap.getModel().getStartTime()));
        }
        if (pageWrap.getModel().getCheckDate() != null) {
            queryWrapper.lambda().ge(UnionApply::getCheckDate, Utils.Date.getStart(pageWrap.getModel().getCheckDate()));
            queryWrapper.lambda().le(UnionApply::getCheckDate, Utils.Date.getEnd(pageWrap.getModel().getCheckDate()));
        }
        if (pageWrap.getModel().getCheckInfo() != null) {
            queryWrapper.lambda().eq(UnionApply::getCheckInfo, pageWrap.getModel().getCheckInfo());
        }
        if (pageWrap.getModel().getCheckUserId() != null) {
            queryWrapper.lambda().eq(UnionApply::getCheckUserId, pageWrap.getModel().getCheckUserId());
        }
        if (pageWrap.getModel().getCode() != null) {
            queryWrapper.lambda().eq(UnionApply::getCode, pageWrap.getModel().getCode());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(UnionApply::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getCurrentFee() != null) {
            queryWrapper.lambda().eq(UnionApply::getCurrentFee, pageWrap.getModel().getCurrentFee());
        }
        if (pageWrap.getModel().getFee() != null) {
            queryWrapper.lambda().eq(UnionApply::getFee, pageWrap.getModel().getFee());
        }
        if (pageWrap.getModel().getSignApplyNo() != null) {
            queryWrapper.lambda().eq(UnionApply::getSignApplyNo, pageWrap.getModel().getSignApplyNo());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(unionApplyMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(UnionApply unionApply) {
        QueryWrapper<UnionApply> wrapper = new QueryWrapper<>(unionApply);
        return unionApplyMapper.selectCount(wrapper);
    }
 
 
    @Override
    public void merge(SaveUnionApplyDTO saveUnionApplyDTO){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.TWO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
        }
        if(Objects.isNull(saveUnionApplyDTO)
            || Objects.isNull(saveUnionApplyDTO.getApplyIds())
            || Objects.isNull(saveUnionApplyDTO.getStartDate())
            || Objects.isNull(saveUnionApplyDTO.getEndDate())
        ){
            throw new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        List<InsuranceApply> insuranceApplyList = insuranceApplyJoinMapper.selectJoinList(InsuranceApply.class,
                new MPJLambdaWrapper<InsuranceApply>()
                        .selectAll(InsuranceApply.class)
                        .selectAs(InsuranceApply::getSolutionBaseId,Solutions::getBaseId)
                        .leftJoin(Solutions.class,Solutions::getId,InsuranceApply::getSolutionId)
                        .eq(InsuranceApply::getIsdeleted, Constants.ZERO)
                        .eq(InsuranceApply::getStatus,Constants.InsuranceApplyStatus.PLATFORM_CHECK_PASS.getKey())
                        .eq(Solutions::getBaseId,saveUnionApplyDTO.getBaseSolutionId())
                        .in(InsuranceApply::getId,saveUnionApplyDTO.getApplyIds())
                        .isNull(InsuranceApply::getUnionApplyId)
        );
        //查询数据是否存在未处于审批通过的数据
        if(insuranceApplyList.size()!=saveUnionApplyDTO.getApplyIds().size()){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"存在数据已处理,请刷新重试");
        }
 
        UnionApply unionApply = new UnionApply();
        unionApply.setCreateDate(new Date());
        unionApply.setCreator(user.getId());
        unionApply.setCompanyId(user.getCompanyId());
        unionApply.setStartTime(saveUnionApplyDTO.getStartDate());
        unionApply.setEndTime(saveUnionApplyDTO.getEndDate());
        unionApply.setCheckDate(new Date());
        unionApply.setStatus(Constants.UnionApplyStatus.UPLOAD.getKey());
        unionApply.setCheckUserId(user.getId());
        unionApply.setFee(insuranceApplyList.stream().map(i->i.getFee()).reduce(BigDecimal.ZERO,BigDecimal::add));
        unionApply.setCurrentFee(BigDecimal.ZERO);
        unionApplyMapper.insert(unionApply);
 
        insuranceApplyJoinMapper.update(null,new UpdateWrapper<InsuranceApply>().lambda()
                .set(InsuranceApply::getUnionApplyId,unionApply.getId())
                .set(InsuranceApply::getCheckDate,new Date())
                .set(InsuranceApply::getCheckUserId,user.getId())
                .in(InsuranceApply::getId,saveUnionApplyDTO.getApplyIds()));
 
    }
 
 
    public void cancelMerge(Integer id){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(user.getType().equals(Constants.TWO)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非商户用户,无法进行该操作");
        }
 
    }
 
 
}