k94314517
2024-04-02 11927cefa1347d192105c9b0bc08d1b91badf18c
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
package com.doumee.service.business.impl;
 
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.NoticesMapper;
import com.doumee.dao.business.join.NoticesJoinMapper;
import com.doumee.dao.business.model.ApplyChagneDetail;
import com.doumee.dao.business.model.Company;
import com.doumee.dao.business.model.InsuranceApply;
import com.doumee.dao.business.model.Notices;
import com.doumee.dao.business.vo.ApplyNoticeVO;
import com.doumee.service.business.NoticesService;
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.xiaoymin.knife4j.core.util.CollectionUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 系统消息信息表Service实现
 * @author 江蹄蹄
 * @date 2024/01/16 10:03
 */
@Service
public class NoticesServiceImpl implements NoticesService {
 
    @Autowired
    private NoticesJoinMapper noticesMapper;
 
    @Override
    public Integer create(Notices notices) {
        noticesMapper.insert(notices);
        return notices.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        noticesMapper.deleteById(id);
    }
 
    @Override
    public void delete(Notices notices) {
        UpdateWrapper<Notices> deleteWrapper = new UpdateWrapper<>(notices);
        noticesMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        noticesMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(Notices notices) {
        noticesMapper.updateById(notices);
    }
 
    @Override
    public void updateByIdInBatch(List<Notices> noticess) {
        if (CollectionUtils.isEmpty(noticess)) {
            return;
        }
        for (Notices notices: noticess) {
            this.updateById(notices);
        }
    }
 
    @Override
    public Notices findById(Integer id) {
        return noticesMapper.selectById(id);
    }
 
    @Override
    public Notices findOne(Notices notices) {
        QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices);
        return noticesMapper.selectOne(wrapper);
    }
 
    @Override
    public List<Notices> findList(Notices notices) {
        QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices);
        return noticesMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<Notices> findPage(PageWrap<Notices> pageWrap) {
        IPage<Notices> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
        MPJLambdaWrapper<Notices> queryWrapper = new MPJLambdaWrapper<>();
        Utils.MP.blankToNull(pageWrap.getModel());
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
 
        //企业人员查看本企业数据
        if(loginUserInfo.getType().equals(Constants.ONE)||loginUserInfo.getType().equals(Constants.TWO)){
            queryWrapper.eq(Notices::getCompanyId, loginUserInfo.getCompanyId());
        }else{
            if(loginUserInfo.getCompanyIdList()!=null && loginUserInfo.getCompanyIdList().size()>0){
                queryWrapper.in(Notices::getCompanyId, loginUserInfo.getCompanyIdList());
            }else{
                queryWrapper.eq(Notices::getCompanyId, -1);
            }
        }
 
        queryWrapper.selectAll(Notices.class);
        queryWrapper.selectAs(Company::getName,Notices::getCompanyName);
        queryWrapper.leftJoin(Company.class,Company::getId,Notices::getCompanyId);
        if (pageWrap.getModel().getIsdeleted() != null) {
            queryWrapper.eq(Notices::getIsdeleted, pageWrap.getModel().getIsdeleted());
        }
        if (pageWrap.getModel().getObjType() != null) {
            queryWrapper.eq(Notices::getObjType, pageWrap.getModel().getObjType());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.eq(Notices::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.eq(Notices::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        if (pageWrap.getModel().getPalt() != null) {
            queryWrapper.eq(Notices::getPalt, pageWrap.getModel().getPalt());
        }
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(Notices::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getReaded() != null) {
            queryWrapper.eq(Notices::getReaded, pageWrap.getModel().getReaded());
        }
        if(pageWrap.getModel().getQueryType()!=null){
            if(pageWrap.getModel().getQueryType().equals(Constants.ZERO)){
                queryWrapper.in(Notices::getObjType,new Integer[]{Constants.NoticeObjectType.INSURANCE_APPLY.getKey(),
                        Constants.NoticeObjectType.APPLY_CHANGE.getKey(),
                        Constants.NoticeObjectType.DISPATCH_UNIT.getKey(),
                        Constants.NoticeObjectType.CHANGE_FACTORY.getKey()});
            } else if(pageWrap.getModel().getQueryType().equals(Constants.ONE)){
                queryWrapper.in(Notices::getObjType,new Integer[]{Constants.NoticeObjectType.TAXES.getKey() });
            } else if(pageWrap.getModel().getQueryType().equals(Constants.TWO)){
                queryWrapper.in(Notices::getObjType,new Integer[]{Constants.NoticeObjectType.SETTLE_CLAIMS.getKey() });
            }
        }
        if(CollectionUtils.isNotEmpty(pageWrap.getSorts())){
            for(PageWrap.SortData sortData: pageWrap.getSorts()) {
                if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
                    queryWrapper.orderByDesc(sortData.getProperty());
                } else {
                    queryWrapper.orderByAsc(sortData.getProperty());
                }
            }
        }else{
            queryWrapper.orderByDesc(Notices::getCreateDate);
        }
 
        PageData<Notices> pageData = PageData.from(noticesMapper.selectJoinPage(page,Notices.class, queryWrapper));
        pageData.getRecords().forEach(i->{
            i.setTypeDetail(
                    Constants.NoticeType.getDetail(i.getType(),i.getObjType())
            );
        });
        return pageData;
    }
 
    @Override
    public long count(Notices notices) {
        QueryWrapper<Notices> wrapper = new QueryWrapper<>(notices);
        return noticesMapper.selectCount(wrapper);
    }
 
 
    /**
     * 查询投保单 提醒数量
     * @param companyId
     * @return
     */
    @Override
    public ApplyNoticeVO getApplyNotice(Integer companyId){
        ApplyNoticeVO applyNoticeVO = new ApplyNoticeVO();
        applyNoticeVO.setWaitSignNum(Constants.ZERO);
        applyNoticeVO.setRenewalNum(Constants.ZERO);
        List<Notices> noticesList = noticesMapper.selectList(new QueryWrapper<Notices>()
                .lambda()
                .select(Notices::getType)
                .eq(Notices::getPalt,Constants.ONE)
                .eq(Notices::getCompanyId,companyId)
                .eq(Notices::getObjType,Constants.NoticeObjectType.INSURANCE_APPLY.getKey())
                .eq(Notices::getStatus,Constants.ZERO)
                .in(Notices::getType,Constants.NoticeType.SIX.getStatus(),Constants.NoticeType.ONE.getStatus())
        );
        if(CollectionUtils.isNotEmpty(noticesList)){
            applyNoticeVO.setRenewalNum(noticesList.stream().filter(m->m.getType().equals(Constants.NoticeType.SIX.getStatus())).collect(Collectors.toList()).size());
            applyNoticeVO.setWaitSignNum(noticesList.size() - applyNoticeVO.getRenewalNum());
        }
        return applyNoticeVO ;
    }
 
    /**
     * 关闭提醒
     * @param companyId
     * @param type
     */
    @Override
    public void closeApplyNotice(Integer companyId,Integer type){
        noticesMapper.update(null,new UpdateWrapper<Notices>()
                .lambda()
                .set(Notices::getStatus,Constants.ONE)
                .eq(Notices::getPalt,Constants.ONE)
                .eq(Notices::getCompanyId,companyId)
                .eq(Notices::getStatus,Constants.ZERO)
                .eq(Notices::getObjType,Constants.NoticeObjectType.INSURANCE_APPLY.getKey())
                .eq(Notices::getType,type)
        );
    }
 
}