李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
/*
 *    Copyright (c) 2018-2025, ztt All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: ztt
 */
package com.chinaztt.mes.quality.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.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaztt.mes.quality.dto.PartsDTO;
import com.chinaztt.mes.quality.entity.*;
import com.chinaztt.mes.quality.mapper.*;
import com.chinaztt.mes.quality.service.PartsService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
import java.util.List;
 
/**
 * 零件检测
 *
 * @author liuth
 * @date 2020-10-14 10:54:02
 */
@Service
@AllArgsConstructor
public class PartsServiceImpl extends ServiceImpl<PartsMapper, Parts> implements PartsService {
    private RequirementsMapper requirementsMapper;
    private ItemsMapper itemsMapper;
    private TemplateMapper templateMapper;
    private TaskMapper taskMapper;
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean fullDelete(Long id) {
        requirementsMapper.delete(Wrappers.<Requirements>lambdaQuery().eq(Requirements::getPartId,id));
        baseMapper.delete(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId,id));
 
        return true;
    }
 
    @Override
    public PartsDTO getFullById(Long id) {
        PartsDTO partsDTO = new PartsDTO();
        //当不为空时获取零件检测信息
        if (id != 0L) {
            // 1.获取检测零件基本信息
            partsDTO = baseMapper.selectDtoById(id);
 
           //获取对应的检测模板信息
            List<Template> templateList=templateMapper.selectList(Wrappers.<Template>lambdaQuery().eq(Template::getId, partsDTO.getTemplateId()));
            if (CollectionUtil.isNotEmpty(templateList)) {
                partsDTO.setTemplates(templateList);
            }
 
        }return partsDTO;
    }
 
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean fullSave(PartsDTO partsDTO) {
        try {
            baseMapper.insert(partsDTO);
            if (CollectionUtil.isNotEmpty(partsDTO.getRequirements())) {
                partsDTO.getRequirements().forEach(a -> {
                    a.setPartId(partsDTO.getPartId());
                    requirementsMapper.insert(a);
                });
            }
        } catch (Exception e) {
            log.error("创建检测要求失败", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return false;
        }
        return true;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean fullUpdate(PartsDTO partsDTO)
    {
        try {
            //更新主表
            baseMapper.delete(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId, partsDTO.getPartId()));
            baseMapper.insert(partsDTO);
            //删除原有检测要求信息
            requirementsMapper.delete(Wrappers.<Requirements>lambdaQuery().eq(Requirements::getPartId, partsDTO.getPartId()));
            //更新检验要求关系表
            if (CollectionUtil.isNotEmpty(partsDTO.getRequirements())) {
                partsDTO.getRequirements().forEach(r -> {
                    if (r.getId() == null || r.getId() == 0) {
                        r.setPartId(partsDTO.getPartId());
                        requirementsMapper.insert(r);
                    } else {
                        requirementsMapper.updateById(r);
                    }
 
                });
            }
        } catch (Exception e) {
            log.error("更新零件检测失败" , e);
            throw new RuntimeException("更新检测要求失败");
        }
        return true;
    }
 
    @Override
    public IPage<List<Parts>> getPartsPage(Page page, QueryWrapper<Parts> ew) {
        return baseMapper.getPartsPage(page,ew);
    }
 
    @Override
    public List<Items> selectItemsRequirementsByPartId(Long id) {
        return itemsMapper.selectItemsRequirementsByPartId(id);
    }
 
    @Override
    public Boolean getPartsJoinTemplateById(Long id) {
        if (id != 0L) {
            List<Parts> partsList=baseMapper.selectList(Wrappers.<Parts>lambdaQuery().eq(Parts::getPartId,id));
            if(partsList.size()>0){
                return false;
            }
        }
        return true;
    }
 
 
}