zhangherong
2025-07-10 c15c980814508369fcbb2dbfcfb53fe95688e005
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
package org.jeecg.modules.eam.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
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.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.constant.BusinessCodeConst;
import org.jeecg.modules.eam.constant.EamTechnicalStatusEvaluationOrderEnum;
import org.jeecg.modules.eam.constant.HfTemplateCategoryEnum;
import org.jeecg.modules.eam.constant.OrderCreationMethodEnum;
import org.jeecg.modules.eam.entity.EamBaseHFCode;
import org.jeecg.modules.eam.entity.EamEquipment;
import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationOrder;
import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard;
import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationOrderMapper;
import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderQuery;
import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationOrderRequest;
import org.jeecg.modules.eam.service.*;
import org.jeecg.modules.system.entity.BaseFactory;
import org.jeecg.modules.system.entity.BaseFactoryUser;
import org.jeecg.modules.system.service.IBaseFactoryService;
import org.jeecg.modules.system.service.IBaseFactoryUserService;
import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * @Description: 技术状态鉴定工单
 * @Author: jeecg-boot
 * @Date: 2025-07-09
 * @Version: V1.0
 */
@Service
public class EamTechnicalStatusEvaluationOrderServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationOrderMapper, EamTechnicalStatusEvaluationOrder> implements IEamTechnicalStatusEvaluationOrderService {
 
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    private IEamTechnicalStatusEvaluationOrderDetailService orderDetailService;
    @Autowired
    private IEamEquipmentService equipmentService;
    @Autowired
    private ISysBusinessCodeRuleService businessCodeRuleService;
    @Autowired
    private IEamTechnicalStatusEvaluationStandardService standardService;
    @Autowired
    private IEamBaseHFCodeService hfCodeService;
 
    @Override
    public IPage<EamTechnicalStatusEvaluationOrder> queryPageList(Page<EamTechnicalStatusEvaluationOrder> page, EamTechnicalStatusEvaluationOrderQuery query) {
        QueryWrapper<EamTechnicalStatusEvaluationOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ems.del_flag", CommonConstant.DEL_FLAG_0);
        //用户数据权限
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null) {
            return page;
        }
        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
            //选择了设备,根据设备id过滤设备
            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
            queryWrapper.in("e.equipment_code", equipArr);
        } else {
            //没有选择设备,根据中心过滤设备
            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                    list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
            if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCodeList);
            } else {
                return page;
            }
        }
        if (query != null) {
            //编码 模糊查询
            if (StringUtils.isNotBlank(query.getOrderNum())) {
                queryWrapper.like("ems.order_num", query.getOrderNum());
            }
            //设备
            if (StringUtils.isNotBlank(query.getEquipmentId())) {
                queryWrapper.eq("ems.equipment_id", query.getEquipmentId());
            }
 
            //保养分类
            if (StringUtils.isNotBlank(query.getEvaluationStatus())) {
                queryWrapper.eq("ems.evaluation_status", query.getEvaluationStatus());
            }
            if (query.getDateBegin() != null && query.getDateEnd() != null) {
                queryWrapper.between("ems.evaluation_date", query.getDateBegin(), query.getDateEnd());
            }
            //排序
            if (StringUtils.isNotBlank(query.getColumn()) && StringUtils.isNotBlank(query.getOrder())) {
                String column = query.getColumn();
                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
                }
                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(query.getOrder())) {
                    queryWrapper.orderByAsc("ems." + oConvertUtils.camelToUnderline(column));
                } else {
                    queryWrapper.orderByDesc("ems." + oConvertUtils.camelToUnderline(column));
                }
            } else {
                queryWrapper.orderByDesc("ems.create_time");
            }
        } else {
            queryWrapper.orderByDesc("ems.create_time");
        }
        queryWrapper.orderByDesc("ems.create_time");
        return this.getBaseMapper().queryPageList(page, queryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addTechnicalStatusEvaluationOrder(EamTechnicalStatusEvaluationOrderRequest request) {
        EamEquipment equipment = equipmentService.getById(request.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
        EamTechnicalStatusEvaluationStandard standard = standardService.getById(request.getStandardId());
        if(standard == null) {
            throw new JeecgBootException("技术状态鉴定规范不存在,添加失败!");
        }
        EamTechnicalStatusEvaluationOrder order = new EamTechnicalStatusEvaluationOrder();
        order.setOrderNum(request.getOrderNum());
        order.setEquipmentId(request.getEquipmentId());
        order.setStandardId(request.getStandardId());
        order.setEvaluationDate(request.getEvaluationDate());
        order.setRemark(request.getRemark());
        String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_ORDER_CODE_RULE);
        request.setOrderNum(codeSeq);
        request.setCreationMethod(OrderCreationMethodEnum.MANUAL.name());
        //状态初始化
        order.setEvaluationStatus(EamTechnicalStatusEvaluationOrderEnum.WAIT_EVALUATION.name());
        order.setCreationMethod(request.getCreationMethod());
        //删除标记
        order.setDelFlag(CommonConstant.DEL_FLAG_0);
        //技术状态鉴定表
        EamBaseHFCode eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION.name());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("未配置技术状态鉴定表的HF编码,添加失败!");
        }
        order.setHfCodeA(eamBaseHFCode.getHfCode());
        //技术状态鉴定安全装置检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_SAFETY_CHECK.name());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("未配置安全装置检查表的HF编码,添加失败!");
        }
        order.setHfCodeB(eamBaseHFCode.getHfCode());
        //技术状态鉴定其他检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_OTHER_CHECK.name());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("未配置其他检查表的HF编码,添加失败!");
        }
        order.setHfCodeD(eamBaseHFCode.getHfCode());
        //技术状态鉴定设备精度检查表
        eamBaseHFCode = hfCodeService.selectByCategory(HfTemplateCategoryEnum.TECHNICAL_STATUS_EVALUATION_PRECISION_CHECK.name());
        if(eamBaseHFCode == null) {
            throw new JeecgBootException("未配置设备精度检查表的HF编码,添加失败!");
        }
        order.setHfCodeC(eamBaseHFCode.getHfCode());
        this.getBaseMapper().insert(order);
        //处理明细数据
        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
            request.getTableDetailList().forEach(tableDetail -> {
                tableDetail.setId(null);
                tableDetail.setOrderId(order.getId());
            });
            orderDetailService.saveBatch(request.getTableDetailList());
        }
        return true;
    }
}