chenrui
2025-03-14 9687fd99fdf6208dbf747ea45c440f192a9af815
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
package com.ruoyi.personnel.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.deepoove.poi.data.Pictures;
import com.ruoyi.common.constant.MenuJumpPathConstants;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.utils.DateImageUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.WxCpUtils;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.personnel.dto.PersonPersonnelCapacityDto;
import com.ruoyi.personnel.dto.PersonPersonnelCapacityExportDto;
import com.ruoyi.personnel.pojo.PersonPersonnelCapacity;
import com.ruoyi.personnel.mapper.PersonPersonnelCapacityMapper;
import com.ruoyi.personnel.service.PersonPersonnelCapacityService;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.InformationNotificationService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.HashMap;
 
/**
 * <p>
 * 人员能力 服务实现类
 * </p>
 *
 * @author 芯导软件(江苏)有限公司
 * @since 2024-10-10 11:26:18
 */
@Service
public class PersonPersonnelCapacityServiceImpl extends ServiceImpl<PersonPersonnelCapacityMapper, PersonPersonnelCapacity> implements PersonPersonnelCapacityService {
 
    @Resource
    private UserMapper userMapper;
    @Resource
    private InformationNotificationService informationNotificationService;
 
    @Resource
    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
 
    @Value("${file.path}")
    private String imgUrl;
 
    @Override
    public IPage<PersonPersonnelCapacityDto> personPersonnelCapacityPage(Page page, Integer departLimsId, Integer userId, String userName) {
        return baseMapper.personPersonnelCapacityPage(page, departLimsId, userId, userName);
    }
 
    /**
     * 导出人员能力
     * @param id
     * @param response
     */
    @Override
    public void exportPersonnelCapacity(Integer id, HttpServletResponse response) {
        PersonPersonnelCapacityExportDto capacityExportDto = baseMapper.selectExportPersonnelCapacity(id);
 
        // 确认人
        String confirmUrl = null;
        if (capacityExportDto.getConfirmOperatingPersonnelId() != null) {
            confirmUrl = userMapper.selectById(capacityExportDto.getConfirmOperatingPersonnelId()).getSignatureUrl();
            if (StringUtils.isBlank(confirmUrl)) {
                throw new ErrorException("缺少确认人签名");
            }
        }
 
        // 获取路径
        InputStream inputStream = this.getClass().getResourceAsStream("/static/personnel-capacity.docx");
        ConfigureBuilder builder = Configure.builder();
        builder.useSpringEL(true);
        String finalConfirmUrl = confirmUrl;
        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
                new HashMap<String, Object>() {{
                    put("capacity", capacityExportDto);
                    put("confirmUrl", StringUtils.isNotBlank(finalConfirmUrl) ? Pictures.ofLocal(imgUrl + "/" + finalConfirmUrl).create() : null);
                    put("confirmDateUrl", capacityExportDto.getConfirmDate() != null ?
                            Pictures.ofStream(DateImageUtil.createDateImage(capacityExportDto.getConfirmDate())).create() : null);
                }});
 
        try {
            response.setContentType("application/msword");
            String fileName = URLEncoder.encode(
                    "人员能力", "UTF-8");
            response.setHeader("Content-disposition",
                    "attachment;filename=" + fileName + ".docx");
            OutputStream os = response.getOutputStream();
            template.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("导出失败");
        }
    }
 
    /**
     * 提交确认人员能力
     * @param personPersonnelCapacity
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void submitConfirmPersonnelCapability(PersonPersonnelCapacity personPersonnelCapacity) {
        if (personPersonnelCapacity.getConfirmOperatingPersonnelId() == null) {
            throw new ErrorException("缺少确认人");
        }
        User formUser = userMapper.selectById(personPersonnelCapacity.getUserId());
 
        Integer userId = SecurityUtils.getUserId().intValue();
        User user = userMapper.selectById(userId);
        // 消息发送
        InformationNotification info = new InformationNotification();
        // 发送人
        info.setCreateUser(user.getName());
        info.setMessageType("6");
        info.setTheme("CNAS人员能力确认通知");
        info.setContent(formUser.getName() + "的人员能力待确认");
        info.setSenderId(userId);
        // 接收人
        info.setConsigneeId(personPersonnelCapacity.getConfirmOperatingPersonnelId());
        info.setJumpPath(MenuJumpPathConstants.PERSONNEL);
        informationNotificationService.addInformationNotification(info);
        this.saveOrUpdate(personPersonnelCapacity);
 
        // 发送企业微信通知
        threadPoolTaskExecutor.execute(() -> {
            // 查询接收人
            User personnel = userMapper.selectById(personPersonnelCapacity.getConfirmOperatingPersonnelId());
 
            String message = "";
            message += "CNAS人员能力确认通知";
            message += "\n请去资源管理-人员-人员能力填写";
            message += "\n" + formUser.getName() + "的人员能力待确认";
            //发送企业微信消息通知
            try {
                WxCpUtils.inform(personnel.getAccount(), message, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
 
    }
 
}