lyh
2 天以前 9a9697c55fa66821cf74165ac2ae820182dae94d
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
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.EamReportAccidentsRegisterDto;
import org.jeecg.modules.eam.entity.EamReportAccidentsRegister;
import org.jeecg.modules.eam.entity.EamReportProductHazards;
import org.jeecg.modules.eam.entity.EamReportRepair;
import org.jeecg.modules.eam.mapper.EamReportAccidentsRegisterMapper;
import org.jeecg.modules.eam.request.EamReportAccidentsRegisterQuery;
import org.jeecg.modules.eam.service.IEamReportAccidentsRegisterService;
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
public class EamReportAccidentsRegisterServiceImpl extends ServiceImpl<EamReportAccidentsRegisterMapper, EamReportAccidentsRegister> implements IEamReportAccidentsRegisterService {
 
    @Autowired
    private IBaseFactoryUserService baseFactoryUserService;
    @Autowired
    private IBaseFactoryService baseFactoryService;
    @Autowired
    @Lazy
    private IEamReportRepairService iEamReportRepairService;
    /**
     * 分页列表
     * @param page
     * @param eamReportAccidentsRegisterQuery
     * @return
     */
    @Override
    public IPage<EamReportAccidentsRegisterQuery> pageList(Page<EamReportAccidentsRegisterQuery> page, EamReportAccidentsRegisterQuery eamReportAccidentsRegisterQuery){
        QueryWrapper<EamReportAccidentsRegisterQuery> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wmo.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> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                queryWrapper.in("e.factory_org_code", factoryCode);
            } else {
                return page;
            }
        }
        //查询条件过滤
        if (eamReportAccidentsRegisterQuery != null) {
            if (StringUtils.isNotBlank(eamReportAccidentsRegisterQuery.getEquipmentId())) {
                queryWrapper.eq("aar.equipment_id", eamReportAccidentsRegisterQuery.getEquipmentId());
            }
            if (StringUtils.isNotBlank(eamReportAccidentsRegisterQuery.getEquipmentCode())) {
                queryWrapper.like("e.equipment_code", eamReportAccidentsRegisterQuery.getEquipmentCode());
            }
            if (StringUtils.isNotBlank(eamReportAccidentsRegisterQuery.getEquipmentName())) {
                queryWrapper.like("e.equipment_name", eamReportAccidentsRegisterQuery.getEquipmentName());
            }
            //排序
            if (StringUtils.isNotBlank(eamReportAccidentsRegisterQuery.getColumn()) && StringUtils.isNotBlank(eamReportAccidentsRegisterQuery.getOrder())) {
                String column = eamReportAccidentsRegisterQuery.getColumn();
                if (column.endsWith(CommonConstant.DICT_TEXT_SUFFIX)) {
                    column = column.substring(0, column.lastIndexOf(CommonConstant.DICT_TEXT_SUFFIX));
                }
                if (DataBaseConstant.SQL_ASC.equalsIgnoreCase(eamReportAccidentsRegisterQuery.getOrder())) {
                    queryWrapper.orderByAsc("wmo." + oConvertUtils.camelToUnderline(column));
                } else {
                    queryWrapper.orderByDesc("wmo." + oConvertUtils.camelToUnderline(column));
                }
            } else {
                queryWrapper.orderByDesc("wmo.create_time");
            }
        } else {
            queryWrapper.orderByDesc("wmo.create_time");
        }
        return baseMapper.queryPageList(page, queryWrapper);
    }
 
    /**
     * 填报数据
     * @param eamReportAccidentsRegisterDto
     * @return
     */
    @Override
    public boolean report(EamReportAccidentsRegisterDto eamReportAccidentsRegisterDto){
        EamReportAccidentsRegister eamReportAccidentsRegister=this.getById(eamReportAccidentsRegisterDto.getId());
        if (eamReportAccidentsRegister==null){
            return false;
        }
        BeanUtils.copyProperties(eamReportAccidentsRegisterDto,eamReportAccidentsRegister);
        this.updateById(eamReportAccidentsRegister);
        return true;
    }
 
    /**
     * 操作工提交-发起流程
     * @param id
     * @return
     */
    @Override
    public Result<?> submit(String id){
        return null;
    }
 
    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public boolean cancelled(String id){
        //双控故障报修,作废后故障保修数据同步修改
        EamReportAccidentsRegister eamReportAccidentsRegister=this.getById(id);
        if (eamReportAccidentsRegister==null){
            return false;
        }
        EamReportRepair eamReportRepair=iEamReportRepairService.getById(eamReportAccidentsRegister.getReportId());
        if (eamReportRepair==null) {
            return false;
        }
        UpdateWrapper<EamReportRepair> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",eamReportRepair.getId());
        updateWrapper.set("is_accidents_register","2");
        updateWrapper.set("scrap_part_number",null);
        updateWrapper.set("scrap_part_quantity",null);
        updateWrapper.set("scrap_part_value",null);
        iEamReportRepairService.update(updateWrapper);
        this.removeById(id);
        return true;
    }
}