k94314517
2025-06-16 15286a9ab39823ddbbf682e1049f39dfc5dd024f
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
package com.doumee.service.business.impl;
 
import com.doumee.biz.system.SystemDictDataBiz;
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.CompanyMapper;
import com.doumee.dao.business.CompanySolutionMapper;
import com.doumee.dao.business.MultifileMapper;
import com.doumee.dao.business.SolutionsMapper;
import com.doumee.dao.business.join.CompanySolutionJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.system.model.SystemUser;
import com.doumee.service.business.CompanySolutionService;
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.doumee.service.business.third.SignService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import oshi.driver.linux.Sysfs;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
 
/**
 * 企业可用保险方案关联表Service实现
 * @author 江蹄蹄
 * @date 2024/01/16 10:03
 */
@Service
public class CompanySolutionServiceImpl implements CompanySolutionService {
 
    @Autowired
    private CompanySolutionJoinMapper companySolutionJoinMapper;
    @Autowired
    private CompanySolutionMapper companySolutionMapper;
    @Autowired
    private CompanyMapper companyMapper;
    @Autowired
    private MultifileMapper multifileMapper;
    @Autowired
    private SolutionsMapper solutionsMapper;
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private SignService signService;
 
    @Override
    public Integer create(CompanySolution companySolution) {
        companySolutionMapper.insert(companySolution);
        return companySolution.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        companySolutionMapper.deleteById(id);
    }
 
    @Override
    public void delete(CompanySolution companySolution) {
        UpdateWrapper<CompanySolution> deleteWrapper = new UpdateWrapper<>(companySolution);
        companySolutionMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        companySolutionMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(CompanySolution companySolution) {
        companySolutionMapper.updateById(companySolution);
    }
 
    @Override
    public void updateByIdInBatch(List<CompanySolution> companySolutions) {
        if (CollectionUtils.isEmpty(companySolutions)) {
            return;
        }
        for (CompanySolution companySolution: companySolutions) {
            this.updateById(companySolution);
        }
    }
 
    @Override
    public CompanySolution findById(Integer id) {
        return companySolutionMapper.selectById(id);
    }
 
    @Override
    public CompanySolution findOne(CompanySolution companySolution) {
        QueryWrapper<CompanySolution> wrapper = new QueryWrapper<>(companySolution);
        return companySolutionMapper.selectOne(wrapper);
    }
    @Override
    public List<CompanySolution> findListForCompany(CompanySolution companySolution) {
        MPJLambdaWrapper<CompanySolution> csWrapper = new MPJLambdaWrapper<>();
        csWrapper.selectAll(CompanySolution.class);
        csWrapper.selectAs(Solutions::getType,CompanySolution::getSolutionType);
        csWrapper.selectAs(Solutions::getName,CompanySolution::getSolutionName);
        csWrapper.selectAs(Company::getName,CompanySolution::getCompanyName);
        csWrapper.selectAs(SystemUser::getRealname,CompanySolution::getSignUserName);
        csWrapper.select(" t4.name as shopName ");
        csWrapper.leftJoin(Solutions.class,Solutions::getId,CompanySolution::getSolutionBaseId);
        csWrapper.leftJoin(Company.class, Company::getId,CompanySolution::getCompanyId);
        csWrapper.leftJoin(SystemUser.class, SystemUser::getId,CompanySolution::getSignUserId);
        csWrapper.leftJoin(" company t4 on t4.id = t.shop_id ");
        csWrapper.eq(Objects.nonNull(companySolution.getCompanyId()),CompanySolution::getCompanyId,companySolution.getCompanyId());
        csWrapper.eq(Objects.nonNull(companySolution.getSolutionId()),CompanySolution::getSolutionBaseId,companySolution.getSolutionId());
        csWrapper.eq(CompanySolution::getIsdeleted, Constants.ZERO);
        csWrapper.eq(Solutions::getIsdeleted, Constants.ZERO);
        csWrapper.orderByAsc(CompanySolution::getCreateDate);
        csWrapper.orderByAsc(CompanySolution::getSortnum);
        List<CompanySolution> companySolutionList = companySolutionJoinMapper.selectJoinList(CompanySolution.class,csWrapper);
        if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(companySolutionList)){
            String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                    systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode();
            for (CompanySolution c:companySolutionList) {
                if(StringUtils.isNotBlank(c.getFileSignUrl())){
                    c.setFileSignUrl(url + c.getFileSignUrl());
                }
            }
        }
        return companySolutionList;
    }
    @Override
    public List<CompanySolution> findList(CompanySolution companySolution) {
        QueryWrapper<CompanySolution> wrapper = new QueryWrapper<>(companySolution);
        return companySolutionMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<CompanySolution> findPage(PageWrap<CompanySolution> pageWrap) {
        IPage<CompanySolution> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        QueryWrapper<CompanySolution> queryWrapper = new QueryWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        if (pageWrap.getModel().getId() != null) {
            queryWrapper.lambda().eq(CompanySolution::getId, pageWrap.getModel().getId());
        }
        if (pageWrap.getModel().getCreator() != null) {
            queryWrapper.lambda().eq(CompanySolution::getCreator, pageWrap.getModel().getCreator());
        }
        if (pageWrap.getModel().getCreateDate() != null) {
            queryWrapper.lambda().ge(CompanySolution::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate()));
            queryWrapper.lambda().le(CompanySolution::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate()));
        }
        if (pageWrap.getModel().getEditor() != null) {
            queryWrapper.lambda().eq(CompanySolution::getEditor, pageWrap.getModel().getEditor());
        }
        if (pageWrap.getModel().getEditDate() != null) {
            queryWrapper.lambda().ge(CompanySolution::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate()));
            queryWrapper.lambda().le(CompanySolution::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate()));
        }
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.lambda().eq(CompanySolution::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getRemark() != null) {
            queryWrapper.lambda().eq(CompanySolution::getRemark, pageWrap.getModel().getRemark());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.lambda().eq(CompanySolution::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.lambda().eq(CompanySolution::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getSortnum() != null) {
            queryWrapper.lambda().eq(CompanySolution::getSortnum, pageWrap.getModel().getSortnum());
        }
        if (pageWrap.getModel().getSolutionBaseId() != null) {
            queryWrapper.lambda().eq(CompanySolution::getSolutionBaseId, pageWrap.getModel().getSolutionBaseId());
        }
        if (pageWrap.getModel().getCanAdd() != null) {
            queryWrapper.lambda().eq(CompanySolution::getCanAdd, pageWrap.getModel().getCanAdd());
        }
        if (pageWrap.getModel().getCanReduce() != null) {
            queryWrapper.lambda().eq(CompanySolution::getCanReduce, pageWrap.getModel().getCanReduce());
        }
        for(PageWrap.SortData sortData: pageWrap.getSorts()) {
            if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                queryWrapper.orderByDesc(sortData.getProperty());
            } else {
                queryWrapper.orderByAsc(sortData.getProperty());
            }
        }
        return PageData.from(companySolutionMapper.selectPage(page, queryWrapper));
    }
 
    @Override
    public long count(CompanySolution companySolution) {
        QueryWrapper<CompanySolution> wrapper = new QueryWrapper<>(companySolution);
        return companySolutionMapper.selectCount(wrapper);
    }
 
 
 
    @Override
    public  String getCompanySolutionSignLink(Integer id) {
        if(id == null ){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        MPJLambdaWrapper<CompanySolution> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(CompanySolution.class);
        queryWrapper.selectAs(Company::getName,CompanySolution::getShopName);
        queryWrapper.leftJoin(Company.class,Company::getId,CompanySolution::getCompanyId);
        queryWrapper.eq(CompanySolution::getId,id);
        queryWrapper.last(" limit 1");
        CompanySolution companySolution = companySolutionJoinMapper.selectJoinOne(CompanySolution.class,queryWrapper);
        if(companySolution == null ||!Constants.equalsInteger(companySolution.getIsdeleted(),Constants.ZERO) ){
            throw  new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        Company company = companyMapper.selectById(companySolution.getCompanyId());
        if(Objects.isNull(company)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到企业信息!");
        }
        Solutions solutions = solutionsMapper.selectById(companySolution.getSolutionId());
        if(Objects.isNull(solutions)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"未查询到关联方案信息!");
        }
        //如果是驳回,只能可驳回已签章状态下的退回申请状态进行操作
        if(!Constants.equalsInteger(companySolution.getStatus(),Constants.ZERO)){
            throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"对不起,该企业的方案确认书状态已流转,当前不支持该操作~");
        }
        Multifile f = multifileMapper.selectOne(new QueryWrapper<Multifile>().lambda()
                .eq(Multifile::getObjId,companySolution.getSolutionId())
                .eq(Multifile::getObjType,Constants.MultiFile.SOLUTIONS_CONFIRMATION_LATTER.getKey())
                .eq(Multifile::getIsdeleted,Constants.ZERO).last("limit 1"));
        if(f == null || StringUtils.isBlank(f.getFileurl())){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取待签章文件失败,请联系确认签署文件是否正确!");
        }
        String url = systemDictDataBiz.queryByCode(Constants.OSS,Constants.RESOURCE_PATH).getCode()+
                systemDictDataBiz.queryByCode(Constants.OSS,Constants.APPLY_FILE).getCode()+f.getFileurl();
        String notifyUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SIGN_DONE_NOTIFY_URL).getCode();
        String applyNo = signService.applySign(solutions.getName(),url,company.getName(),company.getCode(),company.getEmail(),null,company.getSignId(),notifyUrl);
        if(StringUtils.isBlank(applyNo) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        String link = signService.signLink(applyNo,company.getName(),company.getCode());
        if(StringUtils.isBlank(link) ){
            throw  new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"对不起,获取在线签章地址失败,请稍后重试!");
        }
        CompanySolution update= new CompanySolution();
        update.setId(companySolution.getId());
        update.setEditor(user.getId());
        update.setEditDate(new Date());
        update.setApplyNo(applyNo);
        update.setSignStatus(Constants.ZERO);
//        update.setSignUserId(user.getId());
//        update.setSignDate(new Date());
        companySolutionJoinMapper.updateById(update);
        return  link;
    }
 
 
 
}