xieb
2025-01-09 8a591448377eff009b0b57d430f63f3f3db42e4c
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
/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.assessment.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springblade.common.cache.SysCache;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.modules.assessment.entity.AssessmentConfigEntity;
import org.springblade.modules.assessment.excel.AssessmentConfigExcel;
import org.springblade.modules.assessment.mapper.AssessmentConfigMapper;
import org.springblade.modules.assessment.service.IAssessmentConfigService;
import org.springblade.modules.assessment.vo.AssessmentConfigVO;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
import java.util.Objects;
 
/**
 * 考核权重配置表 服务实现类
 *
 * @author Aix
 * @since 2024-02-21
 */
@Service
@AllArgsConstructor
public class AssessmentConfigServiceImpl extends BaseServiceImpl<AssessmentConfigMapper, AssessmentConfigEntity> implements IAssessmentConfigService {
 
    private final IUserService userService;
 
    @Override
    public IPage<AssessmentConfigVO> selectAssessmentConfigPage(IPage<AssessmentConfigVO> page, AssessmentConfigVO assessmentConfig) {
        return page.setRecords(baseMapper.selectAssessmentConfigPage(page, assessmentConfig));
    }
 
 
    @Override
    public List<AssessmentConfigExcel> exportAssessmentConfig(Wrapper<AssessmentConfigEntity> queryWrapper) {
        List<AssessmentConfigExcel> assessmentConfigList = baseMapper.exportAssessmentConfig(queryWrapper);
        //assessmentConfigList.forEach(assessmentConfig -> {
        //    assessmentConfig.setTypeName(DictCache.getValue(DictEnum.YES_NO, AssessmentConfig.getType()));
        //});
        return assessmentConfigList;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importData(List<AssessmentConfigExcel> data, Boolean isCovered) {
        data.forEach(configExcel -> {
            System.out.println("username:" + configExcel.getUserName());
            System.out.println("username:" + configExcel.getAssessorUserName());
            if (configExcel.getUserName() != null && configExcel.getDeptName() != null) {
                AssessmentConfigEntity po = Objects.requireNonNull(BeanUtil.copy(configExcel, AssessmentConfigEntity.class));
                // 被考核人信息
                QueryWrapper qw = new QueryWrapper();
                qw.eq("name", po.getUserName().trim());
                qw.eq("dept_id", Func.toStrWithEmpty(SysCache.getDeptIds("000000", po.getDeptName().trim()), StringPool.EMPTY));
                User user = userService.getOne(qw);
                if (null == user) {
                    throw new RuntimeException("用户:" + po.getUserName() + ",离职或者不存在员工信息中,请核对数据");
                }
                po.setUserId(user.getId());
                po.setDeptId(Func.toLong(user.getDeptId()));
                po.setDeptName(po.getDeptName());
                po.setPostName(SysCache.getPostName(Func.toLong(user.getPostId())));
 
                //考核人信息
                QueryWrapper beQw = new QueryWrapper();
                beQw.eq("name", po.getAssessorUserName().trim());
                beQw.eq("dept_id", Func.toStrWithEmpty(SysCache.getDeptIds("000000", po.getAssessorDeptName().trim()), StringPool.EMPTY));
                User beUser = userService.getOne(beQw);
                if (null == beUser) {
                    throw new RuntimeException("用户:" + po.getAssessorUserName() + ",不存在员工信息中,请核对数据");
                }
                po.setAssessorUserId(beUser.getId());
                po.setAssessorDeptId(Func.toLong(beUser.getDeptId()));
                po.setAssessorDeptName(po.getAssessorDeptName());
                po.setAssessorPostName(SysCache.getPostName(Func.toLong(beUser.getPostId())));
 
                // 覆盖数据
                if (isCovered) {
                    QueryWrapper configQw = new QueryWrapper();
                    configQw.eq("user_id", po.getUserId());
                    configQw.eq("assessor_user_id", po.getAssessorUserId());
                    AssessmentConfigEntity assessmentConfig = getOne(configQw);
                    if (assessmentConfig != null && assessmentConfig.getId() != null) {
                        po.setId(assessmentConfig.getId());
                    }
                }
 
                saveOrUpdate(po);
            }
 
 
 
 
        });
    }
}