无关风月
2 天以前 eaef137e2a787d55f5d31b39ec3a104675368579
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
package com.ruoyi.system.service.impl;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.constants.AssetDeptConstant;
import com.ruoyi.system.dto.asset.AdHandleCompleteDTO;
import com.ruoyi.system.dto.asset.AdUpdateMaterialDTO;
import com.ruoyi.system.mapper.OaApprovalApplicationAdMapper;
import com.ruoyi.system.model.OaApprovalApplicationAd;
import com.ruoyi.system.query.ApprovalApplicationAdQuery;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.OaApprovalApplicationAdService;
import com.ruoyi.system.vo.ApprovalApplicationAdVO;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
 
/**
 * <p>
 * 审批申请记录广告制作申请明细表 服务实现类
 * </p>
 *
 * @author WuGuanFengYue
 * @since 2025-09-15
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class OaApprovalApplicationAdServiceImpl extends ServiceImpl<OaApprovalApplicationAdMapper, OaApprovalApplicationAd> implements OaApprovalApplicationAdService {
    private final ISysUserService sysUserService;
    @Override
    public IPage<ApprovalApplicationAdVO> getPageList(ApprovalApplicationAdQuery query) {
        // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据
        Long userId = SecurityUtils.getUserId();
        boolean isAdmin = SecurityUtils.isAdmin(userId);
 
        if (!isAdmin) {
            try {
                // 获取当前用户的部门名称
                String deptName = sysUserService.selectUserById(userId).getDeptName();
 
                // 非超级管理员且非资产管理部,设置部门权限
                if (!AssetDeptConstant.ASSET_DEPARTMENT_NAME.equals(deptName)) {
                    query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                }
            } catch (Exception e) {
                // 如果获取部门信息失败,默认设置部门权限
                try {
                    query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId()));
                } catch (Exception ex) {
                    // ignore parse, leave null if cannot parse
                }
            }
        }
        return baseMapper.getPageList(new Page<>(query.getPageNum(), query.getPageSize()), query);
    }
 
    @Override
    public boolean handleComplete(AdHandleCompleteDTO dto) {
        // 查询记录是否存在
        OaApprovalApplicationAd entity = getById(dto.getId());
        if (entity == null) {
            return false;
        }
 
        // 更新字段
        entity.setOrderTaker(dto.getOrderTaker());
        entity.setFileUrl(dto.getFileUrl());
        entity.setStatus(dto.getStatus());
        entity.setHandleTime(LocalDateTime.now());
        return updateById(entity);
    }
 
    @Override
    public boolean updateMaterial(AdUpdateMaterialDTO dto) {
        // 查询记录是否存在
        OaApprovalApplicationAd entity = getById(dto.getId());
        if (entity == null) {
            return false;
        }
 
        // 只更新广告图
        entity.setFileUrl(dto.getFileUrl());
 
        return updateById(entity);
    }
 
    /**
     * 检查用户是否有数据权限处理该记录
     *
     * @param entity 实体对象
     * @return 是否有权限
     */
    private boolean hasDataPermission(OaApprovalApplicationAd entity) {
        Long userId = SecurityUtils.getUserId();
        boolean isAdmin = SecurityUtils.isAdmin(userId);
 
        // 超级管理员有所有权限
        if (isAdmin) {
            return true;
        }
 
        try {
            // 获取当前用户的部门名称
            String deptName = sysUserService.selectUserById(userId).getDeptName();
 
            // 资产管理部有所有权限
            if (AssetDeptConstant.ASSET_DEPARTMENT_NAME.equals(deptName)) {
                return true;
            }
        } catch (Exception e) {
            // 如果获取部门信息失败,默认无权限
            return false;
        }
 
        return false;
    }
}