zss
6 天以前 2bbd50fb56275986e2a8658c373686d56804b99b
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package com.ruoyi.inspect.service.impl;
 
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.PushOADto;
import com.ruoyi.inspect.dto.UnqualifiedHandlerDto;
import com.ruoyi.inspect.mapper.InsOrderMapper;
import com.ruoyi.inspect.mapper.InsUnqualifiedHandlerMapper;
import com.ruoyi.inspect.pojo.CommonOa;
import com.ruoyi.inspect.pojo.InsOrder;
import com.ruoyi.inspect.pojo.InsUnqualifiedHandler;
import com.ruoyi.inspect.pojo.InsUnqualifiedHandlerFile;
import com.ruoyi.inspect.service.CommonOaService;
import com.ruoyi.inspect.service.InsUnqualifiedHandlerFileService;
import com.ruoyi.inspect.service.InsUnqualifiedHandlerService;
import com.ruoyi.inspect.vo.UnqualifiedHandlerVO;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author 27233
 * @description 针对表【ins_unqualified_handler(不合格处理表)】的数据库操作Service实现
 * @createDate 2024-07-31 13:38:14
 */
@Service
@Slf4j
public class InsUnqualifiedHandlerServiceImpl extends ServiceImpl<InsUnqualifiedHandlerMapper, InsUnqualifiedHandler>
        implements InsUnqualifiedHandlerService {
 
    @Resource
    private CommonOaService commonOaService;
 
    @Resource
    private InsUnqualifiedHandlerFileService insUnqualifiedHandlerFileService;
    @Resource
    private InsOrderMapper insOrderMapper;
 
 
    @Override
    public IPage<UnqualifiedHandlerVO> pageList(Page page, UnqualifiedHandlerDto unqualifiedHandlerDto) {
        return baseMapper.selectPageList(page, QueryWrappers.queryWrappers(unqualifiedHandlerDto));
    }
 
    @Override
    public Result pushOA(PushOADto pushOADto) {
        return Result.success();
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void unqualifiedHandlerOACallback(Long oaWorkId, String checkResult, JSONArray objects) {
        // 没有这个就结束
        Long count1 = baseMapper.selectCount(Wrappers.<InsUnqualifiedHandler>lambdaQuery()
                .eq(InsUnqualifiedHandler::getRequestId, Integer.valueOf(String.valueOf(oaWorkId))));
        if (count1 == 0) {
            return;
        }
 
        //oa状态:3通过 4驳回
        Integer oaState = "1".equals(checkResult) ? 3 : 4;
        baseMapper.update(null, new LambdaUpdateWrapper<InsUnqualifiedHandler>()
                .set(InsUnqualifiedHandler::getOaState, oaState)
                .ge(InsUnqualifiedHandler::getRequestId, Integer.valueOf(String.valueOf(oaWorkId))));
        //保存oa审批流程记录
        List<CommonOa> commonOaList = new ArrayList<>();
        objects.forEach(l -> {
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(l));
            CommonOa oa = new CommonOa();
            oa.setApprover(jsonObject.getString("operatorName"));
            oa.setWorkflowId(oaWorkId);
            oa.setOperation(jsonObject.getString("operateType"));
            oa.setApprovalDate(jsonObject.getString("operateDate"));
            oa.setApprovalOpinion(jsonObject.getString("remark"));
            oa.setNodeName(jsonObject.getString("nodeName"));
            oa.setApprovalTime(jsonObject.getString("operateTime"));
 
            //查询判断之前是否添加过
            long count = commonOaService.count(Wrappers.<CommonOa>lambdaQuery()
                    .eq(CommonOa::getApprover, oa.getApprover())
                    .eq(CommonOa::getWorkflowId, oa.getWorkflowId())
                    .eq(CommonOa::getOperation, oa.getOperation())
                    .eq(CommonOa::getApprovalDate, oa.getApprovalDate())
                    .eq(CommonOa::getApprovalOpinion, oa.getApprovalOpinion())
                    .eq(CommonOa::getNodeName, oa.getNodeName())
                    .eq(CommonOa::getApprovalTime, oa.getApprovalTime())
            );
            // 没有重复添加
            if (count == 0) {
                commonOaList.add(oa);
            }
        });
        commonOaService.saveBatch(commonOaList);
 
    }
 
    /**
     * 查看oa流程
     * @param id
     * @return
     */
    @Override
    public List<CommonOa> getOaFlow(Integer id) {
        return baseMapper.getOaFlow(id);
    }
 
    /**
     * 新增不合格处理
     * @param unqualifiedHandlerDto
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addUnqualifiedHandler(UnqualifiedHandlerDto unqualifiedHandlerDto) {
        if (unqualifiedHandlerDto.getInventoryQuantityId() == null) {
            throw new ErrorException("缺少原材料id");
        }
        long count = this.count(Wrappers.<InsUnqualifiedHandler>lambdaQuery()
                .eq(InsUnqualifiedHandler::getInsOrderId, unqualifiedHandlerDto.getInsOrderId()));
        if (count > 0) {
            throw new ErrorException("当前检验单已提交过不合格");
        }
        // 原材料编号切割
        InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery()
                .eq(InsOrder::getId, unqualifiedHandlerDto.getInsOrderId())
                .select(InsOrder::getEntrustCode));
        unqualifiedHandlerDto.setNo(order.getEntrustCode());
 
        this.save(unqualifiedHandlerDto);
        if (CollectionUtils.isNotEmpty(unqualifiedHandlerDto.getUnqualifiedHandlerFiles())) {
            for (InsUnqualifiedHandlerFile unqualifiedHandlerFile : unqualifiedHandlerDto.getUnqualifiedHandlerFiles()) {
                unqualifiedHandlerFile.setUnqualifiedId(unqualifiedHandlerDto.getId());
            }
            insUnqualifiedHandlerFileService.updateBatchById(unqualifiedHandlerDto.getUnqualifiedHandlerFiles());
        }
 
        return true;
    }
 
    /**
     * 编辑不合格处理
     * @param unqualifiedHandlerDto
     * @return
     */
    @Override
    public boolean updateUnqualifiedHandler(UnqualifiedHandlerDto unqualifiedHandlerDto) {
        // 删除附件, 重新添加
        insUnqualifiedHandlerFileService.remove(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery()
                .eq(InsUnqualifiedHandlerFile::getUnqualifiedId, unqualifiedHandlerDto.getId()));
        if (CollectionUtils.isNotEmpty(unqualifiedHandlerDto.getUnqualifiedHandlerFiles())) {
            for (InsUnqualifiedHandlerFile unqualifiedHandlerFile : unqualifiedHandlerDto.getUnqualifiedHandlerFiles()) {
                unqualifiedHandlerFile.setUnqualifiedId(unqualifiedHandlerDto.getId());
            }
            insUnqualifiedHandlerFileService.updateBatchById(unqualifiedHandlerDto.getUnqualifiedHandlerFiles());
        }
 
        return this.updateById(unqualifiedHandlerDto);
    }
 
    /**
     * 查看不合格处理界面
     * @param id
     * @return
     */
    @Override
    public UnqualifiedHandlerDto getUnqualifiedHandler(Integer id) {
        InsUnqualifiedHandler insUnqualifiedHandler = this.getById(id);
        UnqualifiedHandlerDto unqualifiedHandlerDto = new UnqualifiedHandlerDto();
        BeanUtil.copyProperties(insUnqualifiedHandler, unqualifiedHandlerDto);
        // 查看附件
        List<InsUnqualifiedHandlerFile> list = insUnqualifiedHandlerFileService.list(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery()
                .eq(InsUnqualifiedHandlerFile::getUnqualifiedId, unqualifiedHandlerDto.getId()));
        unqualifiedHandlerDto.setUnqualifiedHandlerFiles(list);
        return unqualifiedHandlerDto;
    }
 
    /**
     * 删除不合格
     * @param id
     * @return
     */
    @Override
    public boolean deleteUnqualifiedHandler(Integer id) {
        insUnqualifiedHandlerFileService.remove(Wrappers.<InsUnqualifiedHandlerFile>lambdaQuery()
                .eq(InsUnqualifiedHandlerFile::getUnqualifiedId, id));
        this.removeById(id);
        return true;
    }
}