zss
2025-01-13 8d85246f061e3da623c7b9eb4e323ee724b4de0b
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
package com.yuanchu.mom.utils;
 
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.deepoove.poi.data.PictureRenderData;
import com.deepoove.poi.data.Pictures;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.UserMapper;
import com.yuanchu.mom.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
/**
 * Author: yuan
 * Date: 2024-12-17 星期二 10:35:50
 * Description: User工具类
 */
@Component
public class UserUtils {
    private static UserMapper userMapper;
 
    private static String imgUrl;
 
    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        UserUtils.userMapper = userMapper;
    }
 
    @Autowired
    public void setImgUrl(@Value("${file.path}") String imgUrl) {
        UserUtils.imgUrl = imgUrl;
    }
 
    /**
     * 通过人员id获取用户签名地址
     * @param userId 人员id
     * @return 用户签名地址
     */
    public static String getUserSignatureUrl(Integer userId) {
        String userSignatureUrl = null;
        if (userId != null) {
            userSignatureUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
                            .eq(User::getId, userId))
                    .getSignatureUrl();
            if (StringUtils.isBlank(userSignatureUrl)) {
                throw new ErrorException("找不到该人员签名");
            }
            return imgUrl + "\\" + userSignatureUrl;
        } else {
            return null;
        }
    }
 
    /**
     * 通过人员id获取渲染Word用户签名对象
     * @param userId 人员id
     * @return 用户签名对象 or null
     */
    public static PictureRenderData getFinalUserSignatureUrl(Integer userId) {
        String userSignatureUrl = null;
        if (userId != null) {
            userSignatureUrl = userMapper.selectById(userId)
                    .getSignatureUrl();
            if (StringUtils.isBlank(userSignatureUrl)) {
                throw new ErrorException("找不到该人员签名");
            }
        }
        return StringUtils.isNotBlank(userSignatureUrl) ? Pictures.ofLocal(imgUrl + "/" + userSignatureUrl).create() : null;
    }
 
 
    /**
     * 通过名字获取渲染Word用户签名对象
     * @param userName 人员名字
     * @return 用户签名对象 or null
     */
    public static PictureRenderData getFinalUserSignatureUrl(String userName) {
        String userSignatureUrl = null;
        if (userName != null) {
            userSignatureUrl = userMapper.selectOne(Wrappers.<User>lambdaQuery()
                            .eq(User::getName, userName))
                    .getSignatureUrl();
            if (StringUtils.isBlank(userSignatureUrl)) {
                throw new ErrorException("找不到该人员签名");
            }
        }
        return StringUtils.isNotBlank(userSignatureUrl) ? Pictures.ofLocal(imgUrl + "/" + userSignatureUrl).create() : null;
    }
}