luoyb
2021-05-31 3ae6bd194fe1f17b4f5d96cb78b057705e5d0d78
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
package cc.mrbird.febs.server.hr.service.impl;
 
import cc.mrbird.febs.common.core.constant.DicCode;
import cc.mrbird.febs.common.core.constant.ModuleCode;
import cc.mrbird.febs.common.core.entity.constant.FebsConstant;
import cc.mrbird.febs.common.core.entity.system.DicItem;
import cc.mrbird.febs.common.core.exception.FebsException;
import cc.mrbird.febs.common.core.utils.SortUtil;
import cc.mrbird.febs.server.hr.constant.MyConstant;
import cc.mrbird.febs.server.hr.entity.*;
import cc.mrbird.febs.server.hr.entity.EmpLaborTrouble;
import cc.mrbird.febs.server.hr.feign.IRemoteDeptService;
import cc.mrbird.febs.server.hr.mapper.EmpLaborTroubleMapper;
import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService;
import cc.mrbird.febs.server.hr.service.IEmpLaborTroubleService;
import cn.hutool.core.date.DateUtil;
 
import cn.hutool.core.util.StrUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cc.mrbird.febs.common.core.entity.QueryRequest;
import cc.mrbird.febs.common.core.entity.constant.StringConstant;
import cc.mrbird.febs.common.core.entity.system.Dept;
import cc.mrbird.febs.common.core.utils.CastUtil;
import cc.mrbird.febs.common.core.utils.FebsUtil;
import cc.mrbird.febs.common.core.utils.SequenceUtil;
import cc.mrbird.febs.common.redis.service.RedisService;
 
import java.math.BigDecimal;
import java.util.*;
 
/**
 * name:EmpLabortrouble
 * package:cc.mrbird.febs.server.hr.controller
 * description:员工劳资案件服务接口实现
 *
 * @author luoyibo
 * @date 2021-01-31 11:26:36
 * @since JDK1.8
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
class EmpLaborTroubleServiceImpl extends ServiceImpl<EmpLaborTroubleMapper, EmpLaborTrouble> implements IEmpLaborTroubleService {
 
    private final RedisService redisService;
    private final EmpLaborTroubleMapper empLabortroubleMapper;
    private final IEmpBaseInfoService empBaseInfoService;
    private final IRemoteDeptService remoteDeptService;
    private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser())
            .map(u -> u.getUserId().toString())
            .orElse("1");
 
    @Override
    public IPage<EmpLaborTrouble> findEmpLabortroubles(QueryRequest request, EmpLaborTrouble empLabortrouble) {
        QueryWrapper<EmpLaborTrouble> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.DelFlag", empLabortrouble.getDelFlag());
        if (StringUtils.isNotBlank(empLabortrouble.getEmpNumb())) {
            queryWrapper.like("a.EmpNumb", empLabortrouble.getEmpNumb());
        }
        if (StringUtils.isNotBlank(empLabortrouble.getEmpName())) {
            queryWrapper.like("a.EmpName", empLabortrouble.getEmpName());
        }
        if (StringUtils.isNotBlank(empLabortrouble.getCertificateNumb())) {
            queryWrapper.like("a.CertificateNumb", empLabortrouble.getCertificateNumb());
        }
        if (StringUtils.isNotBlank(empLabortrouble.getDeptName())) {
            queryWrapper.like("b.allDeptName", empLabortrouble.getDeptName());
        }
        if (StringUtils.isNotBlank(empLabortrouble.getArbitrationDateStr())) {
            queryWrapper.between("a.ArbitrationDate", empLabortrouble.getArbitrationDateStr().split(",")[0],
                    empLabortrouble.getArbitrationDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empLabortrouble.getSettleDateStr())) {
            queryWrapper.between("a.SettleDate", empLabortrouble.getSettleDateStr().split(",")[0],
                    empLabortrouble.getSettleDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empLabortrouble.getArbitrationType())) {
            queryWrapper.eq("a.ArbitrationType", empLabortrouble.getArbitrationType());
        }
        if (empLabortrouble.getArbitrationStatus() != null && empLabortrouble.getArbitrationStatus() != 0) {
            queryWrapper.eq("a.ArbitrationStatus", empLabortrouble.getArbitrationStatus());
        }
        if (StringUtils.isNotBlank(empLabortrouble.getEmpStatus())) {
            queryWrapper.in("b.EmpStatus", empLabortrouble.getEmpStatus().split(","));
        }
        if (StringUtils.isNotBlank(empLabortrouble.getArbitrationReason())) {
            queryWrapper.like("a.ArbitrationReason", empLabortrouble.getArbitrationReason());
        }
        queryWrapper.in("c.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
        Page<EmpLaborTrouble> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "arbitrationDate", FebsConstant.ORDER_ASC, true);
        IPage<EmpLaborTrouble> iPage = empLabortroubleMapper.selectPageVo(page, queryWrapper);
        iPage.setRecords(this.convertDicItemName(iPage.getRecords()));
        return iPage;
    }
 
    @Override
    public List<EmpLaborTrouble> findEmpLabortroubles(EmpLaborTrouble empLabortrouble) {
        LambdaQueryWrapper<EmpLaborTrouble> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EmpLaborTrouble::getDelFlag, empLabortrouble.getDelFlag());
        return this.convertDicItemName(this.baseMapper.selectList(queryWrapper));
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createEmpLabortrouble(EmpLaborTrouble empLabortrouble) throws FebsException {
        LambdaQueryWrapper<EmpLaborTrouble> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EmpLaborTrouble::getEmpId, empLabortrouble.getEmpId());
        lambdaQueryWrapper.eq(EmpLaborTrouble::getArbitrationDate, empLabortrouble.getArbitrationDate());
        lambdaQueryWrapper.ne(EmpLaborTrouble::getDelFlag, 1);
        if (this.count(lambdaQueryWrapper) > 0) {
            throw new FebsException(MyConstant.MESSAGE);
        }
        empLabortrouble.setArbitrationId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
        empLabortrouble.setCreator(operatorId);
        empLabortrouble.setModifier(operatorId);
        this.save(empLabortrouble);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateEmpLabortrouble(EmpLaborTrouble empLabortrouble) throws FebsException {
        LambdaQueryWrapper<EmpLaborTrouble> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EmpLaborTrouble::getEmpId, empLabortrouble.getEmpId());
        lambdaQueryWrapper.eq(EmpLaborTrouble::getArbitrationDate, empLabortrouble.getArbitrationDate());
        lambdaQueryWrapper.ne(EmpLaborTrouble::getDelFlag, 1);
        lambdaQueryWrapper.ne(EmpLaborTrouble::getArbitrationId, empLabortrouble.getArbitrationId());
        if (this.count(lambdaQueryWrapper) > 0) {
            throw new FebsException(MyConstant.MESSAGE);
        }
        EmpLaborTrouble dbData = this.getById(empLabortrouble.getArbitrationId());
        empLabortrouble.setCreateTime(dbData.getCreateTime());
        empLabortrouble.setCreator(dbData.getCreator());
        empLabortrouble.setDelFlag(dbData.getDelFlag());
        empLabortrouble.setModifyTime(new Date());
        empLabortrouble.setModifier(operatorId);
        this.saveOrUpdate(empLabortrouble);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteEmpLabortrouble(EmpLaborTrouble empLabortrouble) {
        LambdaQueryWrapper<EmpLaborTrouble> wrapper = new LambdaQueryWrapper<>();
// TODO 设置删除条件
        this.remove(wrapper);
    }
 
    /**
     * 根据Id批量逻辑删除记录
     * <p>
     * date 2021-01-28 10:48
     *
     * @param ids 待删除Id
     * @return void
     * @author: luoyibo
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void logicDelEmpLabortrouble(String ids) {
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        empLabortroubleMapper.logicDeleteByIds(list, operatorId);
    }
 
    @Override
    public boolean momentToNormal(String ids) {
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        return empLabortroubleMapper.momentToNormal(list, operatorId) > 0;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importEmpLaborTrouble(List<List<Object>> listObject, List<String> returnList, List<DicItem> dicItems) {
        for (List<Object> list : listObject) {
            if (list.size() == 0 || StrUtil.isBlank(list.get(0).toString())) {
                continue;
            }
            EmpLaborTrouble empLabortrouble = new EmpLaborTrouble();
            empLabortrouble.setArbitrationId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
            empLabortrouble.setEmpNumb(list.get(0).toString());
            List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
            if (null == depts) {
                depts = remoteDeptService.setDeptRedis();
            }
            Dept dept = depts.stream().filter(d -> d.getDeptName().equals(list.get(1).toString())).findFirst().orElse(null);
            if (null == dept) {
                returnList.add(StrUtil.format("导入员工劳资案件异常: 出现位置第{}行, 原因:{}部门不存在", listObject.indexOf(list) + 1, list.get(1).toString()));
                continue;
            }
            EmpBaseInfo empBaseInfo = empBaseInfoService.getEmpBaseInfoByEmpNumb(list.get(0).toString());
            if (null == empBaseInfo) {
                returnList.add(StrUtil.format("导入员工劳资案件异常: 出现位置第{}行, 原因:{}员工编号不存在", listObject.indexOf(list) + 1, list.get(0).toString()));
                continue;
            }
            empLabortrouble.setDelFlag(0);
            empLabortrouble.setEmpId(empBaseInfo.getEmpId());
            empLabortrouble.setDeptName(list.get(1).toString());
            empLabortrouble.setDeptId(dept.getDeptId());
            empLabortrouble.setJobName(list.get(2).toString());
            empLabortrouble.setEmpName(list.get(3).toString());
            empLabortrouble.setCertificateNumb(list.get(4).toString());
 
            //仲裁类型
            DicItem dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "zctype") && StrUtil.equals(j.getDicItemName(), list.get(6).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empLabortrouble.setArbitrationType(dicItem.getDicItemCode());
            }
 
 
            empLabortrouble.setArbitrationReason(list.get(7).toString());
            empLabortrouble.setReporter(list.get(8).toString());
            empLabortrouble.setRemark(list.get(9).toString());
            if (StringUtils.isNotBlank(list.get(10).toString())) {
                empLabortrouble.setArbitrationPay(new BigDecimal(list.get(10).toString()));
            }
            if (StringUtils.isNotBlank(list.get(11).toString())) {
                empLabortrouble.setArbitrationStatus("未结案".equals(list.get(11).toString()) ? 0 : 1);
            }
            try {
                if (StringUtils.isNotBlank(list.get(5).toString())) {
                    empLabortrouble.setArbitrationDate(DateUtil.parse(list.get(5).toString()));
                }
 
                if (StringUtils.isNotBlank(list.get(12).toString())) {
                    empLabortrouble.setSettleDate(DateUtil.parse(list.get(12).toString()));
                }
            } catch (Exception e) {
                returnList.add(StrUtil.format("导入员工劳资案件异常: 出现位置第{}行, 原因:{}时间格式错误", listObject.indexOf(list) + 1, list.get(0).toString()));
                continue;
            }
 
            empLabortrouble.setEmpStatus(empBaseInfo.getEmpStatus());
            this.save(empLabortrouble);
        }
    }
 
    private List<EmpLaborTrouble> convertDicItemName(List<EmpLaborTrouble> list) {
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        list.forEach(p -> {
            //仲裁类型
            p.setArbitrationTypeName(dicItems.stream()
                    .filter(k -> DicCode.ZCTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getArbitrationType()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse(""));
        });
 
        return list;
    }
}