lyh
4 小时以前 86ba6f759117d9437bcaab902efa29e8cf72c815
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
package org.jeecg.modules.eam.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.dto.EamReportProductHazardsDto;
import org.jeecg.modules.eam.entity.EamReportProductHazards;
import org.jeecg.modules.eam.entity.EamReportRepair;
import org.jeecg.modules.eam.mapper.EamReportProductHazardsMapper;
import org.jeecg.modules.eam.request.EamReportProductHazardsQuery;
import org.jeecg.modules.eam.service.IEamReportProductHazardsService;
import org.jeecg.modules.eam.service.IEamReportRepairService;
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.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * @Description: 产品安全隐患确认
 * @Author: jeecg-boot
 * @Date:   2025-07-17
 * @Version: V1.0
 */
@Service("IEamReportProductHazardsService")
public class EamReportProductHazardsServiceImpl extends ServiceImpl<EamReportProductHazardsMapper, EamReportProductHazards> implements IEamReportProductHazardsService {
 
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    @Lazy
    private IEamReportRepairService iEamReportRepairService;
 
    /**
     * 分页列表
     * @param page
     * @param eamReportProductHazardsQuery
     * @return
     */
    @Override
    public IPage<EamReportProductHazardsQuery> pageList(Page<EamReportProductHazardsQuery> page, EamReportProductHazardsQuery eamReportProductHazardsQuery){
        QueryWrapper<EamReportProductHazardsQuery> queryWrapper = new QueryWrapper<>();
        //用户数据权限
        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> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCode);
            } else {
                return page;
            }
        }
        //查询条件过滤
        if (eamReportProductHazardsQuery != null) {
            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getEquipmentId())) {
                queryWrapper.eq("erph.equipment_id", eamReportProductHazardsQuery.getEquipmentId());
            }
            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getEquipmentCode())) {
                queryWrapper.like("e.equipment_code", eamReportProductHazardsQuery.getEquipmentCode());
            }
            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getEquipmentName())) {
                queryWrapper.like("e.equipment_name", eamReportProductHazardsQuery.getEquipmentName());
            }
            //排序
            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getColumn()) && StringUtils.isNotBlank(eamReportProductHazardsQuery.getOrder())) {
                String column = eamReportProductHazardsQuery.getColumn();
                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
                }
                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(eamReportProductHazardsQuery.getOrder())) {
                    queryWrapper.orderByAsc("erph." + oConvertUtils.camelToUnderline(column));
                } else {
                    queryWrapper.orderByDesc("erph." + oConvertUtils.camelToUnderline(column));
                }
            } else {
                queryWrapper.orderByDesc("erph.create_time");
            }
        } else {
            queryWrapper.orderByDesc("erph.create_time");
        }
        return baseMapper.queryPageList(page, queryWrapper);
    }
 
    /**
     * 操作工填报
     * @param eamReportProductHazardsDto
     * @return
     */
    @Override
    public boolean report(EamReportProductHazardsDto eamReportProductHazardsDto){
        EamReportProductHazards eamReportProductHazards=this.getById(eamReportProductHazardsDto.getId());
        if (eamReportProductHazards==null){
            return false;
        }
        BeanUtils.copyProperties(eamReportProductHazardsDto,eamReportProductHazards);
        this.updateById(eamReportProductHazards);
        return true;
    }
 
    /**
     * 操作工提交-发起流程
     * @param id
     * @return
     */
    @Override
    public Result<?> submit(String id){
        return null;
    }
 
    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public boolean cancelled(String id){
        //双控故障报修,作废后故障保修数据同步修改
        EamReportProductHazards eamReportProductHazards=this.getById(id);
        if (eamReportProductHazards==null){
            return false;
        }
        EamReportRepair eamReportRepair=iEamReportRepairService.getById(eamReportProductHazards.getReportId());
        if (eamReportRepair==null) {
            return false;
        }
        UpdateWrapper<EamReportRepair> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",eamReportRepair.getId());
        updateWrapper.set("is_processed","2");
        updateWrapper.set("batch_number",null);
        updateWrapper.set("processing_part",null);
        updateWrapper.set("quantity",null);
        iEamReportRepairService.update(updateWrapper);
        this.removeById(id);
        return true;
    }
}