lyh
2025-02-14 f2f8241dd52ef12ec109f6f4f0f13042055338ac
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
package org.jeecg.modules.dnc.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.dnc.entity.DeviceInfo;
import org.jeecg.modules.dnc.entity.DncPassLog;
import org.jeecg.modules.dnc.entity.DocInfo;
import org.jeecg.modules.dnc.entity.DocRelative;
import org.jeecg.modules.dnc.exception.ExceptionCast;
import org.jeecg.modules.dnc.ext.NcTxtFilePathInfo;
import org.jeecg.modules.dnc.mapper.DocInfoMapper;
import org.jeecg.modules.dnc.mapper.DocRelativeMapper;
import org.jeecg.modules.dnc.response.CommonCode;
 
import org.jeecg.modules.dnc.service.*;
import org.jeecg.modules.dnc.utils.ValidateUtil;
import org.jeecg.modules.dnc.utils.date.DateUtil;
 
import org.jeecg.modules.dnc.utils.file.FileUtilS;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.mdc.entity.MdcEquipment;
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
@Service
public class DocRelativeServiceImpl extends ServiceImpl<DocRelativeMapper, DocRelative> implements IDocRelativeService {
 
    @Autowired
    private DocInfoMapper docInfoMapper;
    @Autowired
    private IDeviceInfoService deviceInfoService;
    @Autowired
    private IDeviceGroupService deviceGroupService;
    @Value("${securedoc.localFilePath}")
    private String localFilePath;
    @Autowired
    private IDncPassLogService dncPassLogService;
    @Autowired
    private IMdcEquipmentService iMdcEquipmentService;
    @Autowired
    private IMdcProductionService iMdcProductionService;
 
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteByDocAttr(Integer attrType, String attrId) {
        LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType).eq(DocRelative::getAttributionId, attrId);
        return super.remove(lambdaQueryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteByDocId(String id) {
        LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(DocRelative::getDocId, id);
        return super.remove(lambdaQueryWrapper);
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteDocByAttr(String docId, Integer attrType,  String attrId) {
        List<DocRelative> docRelatives = super.lambdaQuery().eq(DocRelative::getDocId, docId).
                        eq(DocRelative::getAttributionType, attrType).
                        eq(DocRelative::getAttributionId, attrId).list();
        boolean docRel = false;
        DocRelative docRelative = new DocRelative();
        if (docRelatives != null && !docRelatives.isEmpty()) {
            String classificationId = "1259647678577995778";
            docRelative = docRelatives.get(0);
            if (classificationId.equals(docRelative.getClassificationId())) {
                docRel = true;
            }
        }
        LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(DocRelative::getDocId, docId);
        lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType);
        lambdaQueryWrapper.eq(DocRelative::getAttributionId, attrId);
        boolean b = super.remove(lambdaQueryWrapper);
 
        if (b && docRel) {
            DocInfo info = docInfoMapper.selectById(docId);
            //todo 修改为mdc设备
            MdcEquipment mdcEquipment=iMdcEquipmentService.getById(attrId);
            List<String> strings =  iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
            if (strings != null && !strings.isEmpty()) {
                String path = StringUtils.join(strings.toArray(), "/");
                boolean deleteFile = FileUtilS.deleteFilePathZip(path + "/"+ mdcEquipment.getEquipmentId(),
                        info.getDocName(), info.getDocSuffix());
                if (!deleteFile) {
                    return false;
                }
                DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY));
                Integer fileTxt = 0, fileNc =0;
                if (dncPassLog !=null) {
                    fileTxt = dncPassLog.getSequenceNumber() + 1;
                    fileNc = fileTxt + 1;
                } else {
                    fileTxt =  1;
                    fileNc = fileTxt + 1;
                }
                String sequence = String.format("%06d",fileTxt);
                DncPassLog passInfoNc = new DncPassLog();
                passInfoNc.setSequenceNumber(fileNc);
                passInfoNc.setSequenceOrder(sequence);
                passInfoNc.setDayTime(DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY));
                passInfoNc.setPassType("02");
                passInfoNc.setPassName(info.getDocName()+"."+info.getDocSuffix());
                passInfoNc.setCreateTime(DateUtil.getNow());
                dncPassLogService.save(passInfoNc);
                //处理文件名称  文件路径
 
                NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
                ncTxt.setEquipmentId(mdcEquipment.getEquipmentId());
                ncTxt.setFilePath(path + "/"+ mdcEquipment.getEquipmentId() + "/" );
                ncTxt.setFileTxtName("02A"+DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY)+sequence);
                ncTxt.setOrigFileName(info.getDocName());
                ncTxt.setOrigFileSuffix(info.getDocSuffix());
                ncTxt.setFileAddOrDelete(2);
                String loFilePath = localFilePath + "\\" + ncTxt.getFileTxtName() + ".nc";
                try {
                   /* ObjectMapper mapper = new ObjectMapper();
                    String json = mapper.writeValueAsString(ncTxt);*/
                    String allList = new String();
                    allList=(ncTxt.getFileTxtName()+"\n");
                    allList+=(ncTxt.getFileNcName()+"\n");
                    allList+=(ncTxt.getOrigFileName()+"\n");
                    allList+=(ncTxt.getOrigFileSuffix()+"\n");
                    allList+=(ncTxt.getFilePath()+"\n");
                    allList+=(ncTxt.getEquipmentId()+"\n");
                    allList+=(ncTxt.getFileAddOrDelete().toString());
                    FileUtilS.fileWriterSql(loFilePath,allList);
                }catch (Exception e) {
                    return true;
                }
            }
        }
        return b;
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteCopyDocByAttrNext(String docId, Integer attrType, String attrId) {
        LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(DocRelative::getDocId, docId);
        lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType);
        lambdaQueryWrapper.eq(DocRelative::getAttributionId, attrId);
        boolean b = super.remove(lambdaQueryWrapper);
        return b;
    }
 
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public List<MdcEquipment> findDeviceByDocId(String docId) {
        if(!ValidateUtil.validateString(docId))
            ExceptionCast.cast(CommonCode.INVALID_PARAM);
        return super.getBaseMapper().findDeviceByDocId(docId);
    }
}