Alan
2021-02-17 41f5434217c77cb0fd87b08008876f7a5be5af55
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
package cc.mrbird.febs.server.hr.service.impl;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Optional;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
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.constant.DicCode;
import cc.mrbird.febs.common.core.constant.ModuleCode;
import cc.mrbird.febs.common.core.entity.QueryRequest;
import cc.mrbird.febs.common.core.entity.system.Dept;
import cc.mrbird.febs.common.core.entity.system.DicItem;
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 cc.mrbird.febs.server.hr.entity.EmpBaseInfo;
import cc.mrbird.febs.server.hr.feign.IRemoteDeptService;
import cc.mrbird.febs.server.hr.mapper.EmpBaseInfoMapper;
import cc.mrbird.febs.server.hr.service.IEmpBaseInfoService;
import lombok.RequiredArgsConstructor;
 
/**
 * name:EmpBaseinfo
 * package:cc.mrbird.febs.server.hr.controller
 * description:员工基本信息服务接口实现
 *
 * @author luoyibo
 * @date 2021-01-30 08:04:50
 * @since JDK1.8
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
class EmpBaseInfoServiceImpl extends ServiceImpl<EmpBaseInfoMapper, EmpBaseInfo> implements IEmpBaseInfoService {
    private final RedisService redisService;
    private final IRemoteDeptService remoteDeptService;
    private final EmpBaseInfoMapper empBaseInfoMapper;
    private final String operatorId = Optional.ofNullable(FebsUtil.getCurrentUser())
            .map(u -> u.getUserId().toString())
            .orElse("1");
 
    @Override
    public IPage<EmpBaseInfo> findEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
        LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EmpBaseInfo::getDelFlag, empBaseInfo.getDelFlag());
        if (StringUtils.isNotBlank(empBaseInfo.getEmpNumb())) {
            queryWrapper.eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpName())) {
            queryWrapper.eq(EmpBaseInfo::getEmpName, empBaseInfo.getEmpName());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getCertificateNumb())) {
            queryWrapper.eq(EmpBaseInfo::getCertificateNumb, empBaseInfo.getCertificateNumb());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDeptName())) {
            queryWrapper.eq(EmpBaseInfo::getDeptName, empBaseInfo.getDeptName());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEntryDateStr())) {
            queryWrapper.between(EmpBaseInfo::getEntryDate, empBaseInfo.getEntryDateStr().split(",")[0],  empBaseInfo.getEntryDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getDimissionDateStr())) {
            queryWrapper.between(EmpBaseInfo::getDimissionDate, empBaseInfo.getDimissionDateStr().split(",")[0],  empBaseInfo.getDimissionDateStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getSex())) {
            queryWrapper.eq(EmpBaseInfo::getSex, empBaseInfo.getSex());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEducation())) {
            queryWrapper.eq(EmpBaseInfo::getEducation, empBaseInfo.getEducation());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getPolitics())) {
            queryWrapper.eq(EmpBaseInfo::getPolitics, empBaseInfo.getPolitics());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getAgeStr())) {
            queryWrapper.between(EmpBaseInfo::getAge, empBaseInfo.getAgeStr().split(",")[0],  empBaseInfo.getAgeStr().split(",")[1]);
        }
        if (StringUtils.isNotBlank(empBaseInfo.getArchivesStatus())) {
            queryWrapper.eq(EmpBaseInfo::getArchivesStatus, empBaseInfo.getArchivesStatus());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getInsuranceType())) {
            queryWrapper.eq(EmpBaseInfo::getInsuranceType, empBaseInfo.getInsuranceType());
        }
        if (StringUtils.isNotBlank(empBaseInfo.getEmpStatus())) {
            queryWrapper.eq(EmpBaseInfo::getEmpStatus, empBaseInfo.getEmpStatus());
        }
        Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        IPage<EmpBaseInfo> iPage = this.page(page, queryWrapper);
        //设置部门
        List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
        list.forEach(p -> {
            p.setSexName("1".equals(p.getSex()) ? "男" : "女");
            p.setEmpTypeName("1".equals(p.getEmpType()) ? "正式工" : "临时工");
            p.setInsuranceTypeName("1".equals(p.getInsuranceType()) ? "(深户)五险一档" : "(非深户)五险一档");
            p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交");
            // 设置民族
            p.setNationName(dicItems.stream()
                    .filter(k -> DicCode.NATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("汉族"));
            // 设置政治面貌
            p.setPoliticsName(dicItems.stream()
                    .filter(k -> DicCode.PLITICAL.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getPolitics()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("群众"));
            // 设置婚姻状况
            p.setMarriageName(dicItems.stream()
                    .filter(k -> DicCode.MARRIAGE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getMarriage()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未婚"));
            // 设置学历
            p.setEducationName(dicItems.stream()
                    .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEducation()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("无学历"));
            // 设置籍贯
            p.setNativePlaceName(dicItems.stream()
                    .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getNativePlace()))
                    .findFirst()
                    .map(DicItem::getDicItemName)
                    .orElse("未知"));
        });
        iPage.setRecords(list);
        return iPage;
    }
 
    @Override
    public List<EmpBaseInfo> findEmpBaseInfos(EmpBaseInfo empBaseInfo) {
        LambdaQueryWrapper<EmpBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(EmpBaseInfo::getDelFlag, empBaseInfo.getDelFlag());
        return this.baseMapper.selectList(queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
        empBaseInfo.setCreator(operatorId);
        empBaseInfo.setModifier(operatorId);
        this.save(empBaseInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        EmpBaseInfo dbData = this.getById(empBaseInfo.getEmpId());
        empBaseInfo.setCreateTime(dbData.getCreateTime());
        empBaseInfo.setCreator(dbData.getCreator());
        empBaseInfo.setDelFlag(dbData.getDelFlag());
        empBaseInfo.setModifyTime(new Date());
        empBaseInfo.setModifier(operatorId);
        this.saveOrUpdate(empBaseInfo);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteEmpBaseInfo(EmpBaseInfo empBaseInfo) {
        LambdaQueryWrapper<EmpBaseInfo> 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 logicDelEmpBaseInfo(String ids) {
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        empBaseInfoMapper.logicDeleteByIds(list, operatorId);
    }
 
    /**
     * 设置员工部门名称
     * <p>
     * date 2021-02-02 21:43
     *
     * @param empBaseInfoList 人员信息列表
     * @return java.util.List<cc.mrbird.febs.server.hr.entity.EmpBaseInfo>
     * @author: luoyibo
     */
    private List<EmpBaseInfo> setDeptName(List<EmpBaseInfo> empBaseInfoList) {
        List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
        for (EmpBaseInfo empBaseInfo : empBaseInfoList) {
            // 设置部门
            empBaseInfo.setDeptName(depts.stream()
                    .filter(k -> k.getDeptId().equals(empBaseInfo.getDeptId()))
                    .findFirst()
                    .map(Dept::getDeptName)
                    .orElse(""));
        }
        return empBaseInfoList;
    }
 
    @Override
    public boolean verifyEmpNumb(EmpBaseInfo empBaseInfo) {
        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EmpBaseInfo::getEmpNumb, empBaseInfo.getEmpNumb());
        EmpBaseInfo tempEmpBaseInfo = this.getOne(queryWrapper);
        if (tempEmpBaseInfo == null) {
            return false;
        }
        return !empBaseInfo.getEmpId().equals(tempEmpBaseInfo.getEmpId());
    }
 
    @Override
    public boolean momentToNormal(String ids) {
        String[] str = ids.split(",");
        List<String> list = new ArrayList<>(Arrays.asList(str));
        return empBaseInfoMapper.momentToNormal(list, operatorId) > 0;
    }
}