¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.modules.dnc.constant.DocAttributionTypeEnum; |
| | | import org.jeecg.modules.dnc.entity.*; |
| | | import org.jeecg.modules.dnc.mapper.GuideCardBatchMapper; |
| | | import org.jeecg.modules.dnc.service.*; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Description: ncæä»¶å¯¹åºæ°æ§ç¨åºå 工确认表 |
| | | * @Author: jeecg-boot |
| | | * @Date: 2025-05-27 |
| | | * @Version: V1.0 |
| | | */ |
| | | @Service |
| | | public class GuideCardBatchServiceImpl extends ServiceImpl<GuideCardBatchMapper, GuideCardBatch> implements IGuideCardBatchService { |
| | | |
| | | @Autowired |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Autowired |
| | | private IDocInfoService docInfoService; |
| | | |
| | | @Autowired |
| | | private IPartsInfoService partsInfoService; |
| | | |
| | | @Autowired |
| | | private IProcessStreamService processStreamService; |
| | | |
| | | @Autowired |
| | | private IWorkStepService workStepService; |
| | | |
| | | @Autowired |
| | | private IDeviceTypeService deviceTypeService; |
| | | |
| | | /** |
| | | * çææµæ°´å· |
| | | * @param code |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String getSerialNumber(String code) { |
| | | // äºä»¶ç¼å·æ ¼å¼ï¼å¹´ä»½åä¸¤ä½ + åä½ç¼ç + æä½å·¥è´¦å· + æµæ°´å·ï¼4ä½ï¼ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | |
| | | // è·åå½å年份åä¸¤ä½ |
| | | String yearSuffix = DateUtils.formatDate(new Date(), "yy"); |
| | | |
| | | // æ¥è¯¢å½å¹´ææè®°å½ |
| | | QueryWrapper<GuideCardBatch> wrapper = new QueryWrapper<>(); |
| | | wrapper.apply("YEAR(create_time) = YEAR(GETDATE())"); |
| | | wrapper.isNotNull("serial_number"); |
| | | wrapper.orderByDesc("SUBSTRING(serial_number, LEN(serial_number)-3, 4)"); |
| | | |
| | | List<GuideCardBatch> list = this.list(wrapper); |
| | | |
| | | // çææµæ°´å·é»è¾ |
| | | String serialSuffix; |
| | | if (!list.isEmpty()) { |
| | | // æåææ°æµæ°´å·çååä½ |
| | | String lastSerial = list.get(0).getSerialNumber(); |
| | | String lastSuffix = lastSerial.substring(lastSerial.length() - 4); |
| | | |
| | | // æµæ°´å·èªå¢ï¼å¤ç9999溢åºï¼ |
| | | int nextNum = Integer.parseInt(lastSuffix) + 1; |
| | | serialSuffix = String.format("%04d", nextNum > 9999 ? 1 : nextNum); // è¶
è¿9999åé置为0001 |
| | | } else { |
| | | serialSuffix = "0001"; // å½å¹´æ è®°å½ååå§å |
| | | } |
| | | |
| | | // æ¼æ¥å®æ´ç¼å· |
| | | return yearSuffix+"-"+ code+"-"+ user.getUsername()+"-"+ serialSuffix; |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥NCæä»¶é»è®¤äº§çncæä»¶å¯¹åºæ°æ§ç¨åºå 工确认表 |
| | | * @param docId |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean importGuideCardBatch(String docId,String attributionId,Integer attributionType){ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | DocInfo docInfo=docInfoService.getById(docId); |
| | | if (docInfo==null){ |
| | | return false; |
| | | } |
| | | PartsInfo partsInfo=new PartsInfo(); |
| | | ProcessStream processStream; |
| | | WorkStep workStep; |
| | | DeviceType deviceType; |
| | | GuideCardBatch guideCardBatch=new GuideCardBatch(); |
| | | if (DocAttributionTypeEnum.PROCESS.getCode().equals(attributionType)){ |
| | | //å·¥åºè®¾å¤ç±» |
| | | deviceType=deviceTypeService.getById(attributionId); |
| | | if (deviceType==null){ |
| | | return false; |
| | | } |
| | | processStream=processStreamService.getById(deviceType.getAttributionId()); |
| | | if (processStream==null){ |
| | | return false; |
| | | } |
| | | guideCardBatch.setProcessWorkCode(processStream.getProcessCode()); |
| | | partsInfo=partsInfoService.getById(processStream.getPartsId()); |
| | | }else if (DocAttributionTypeEnum.WORKSITE.getCode().equals(attributionType)){ |
| | | //å·¥æ¥è®¾å¤ç±» |
| | | deviceType=deviceTypeService.getById(attributionId); |
| | | if (deviceType==null){ |
| | | return false; |
| | | } |
| | | workStep=workStepService.getById(deviceType.getAttributionId()); |
| | | if (workStep==null){ |
| | | return false; |
| | | } |
| | | guideCardBatch.setProcessWorkCode(workStep.getStepCode()); |
| | | partsInfo=partsInfoService.getById(workStep.getPartsId()); |
| | | } |
| | | guideCardBatch.setDocId(docId); |
| | | guideCardBatch.setSerialNumber(getSerialNumber("C140")); |
| | | guideCardBatch.setUnit(sysDictService.queryDictTextByKey("unit_code", "C140")); |
| | | guideCardBatch.setDocName(docInfo.getDocName()); |
| | | if (partsInfo!=null){ |
| | | guideCardBatch.setPartsCode(partsInfo.getPartsCode()); |
| | | guideCardBatch.setPartsName(partsInfo.getPartsName()); |
| | | guideCardBatch.setMaterielDesp(partsInfo.getMaterielDesp()); |
| | | } |
| | | guideCardBatch.setFlowStatus("0"); |
| | | guideCardBatch.setCompiler(user.getUsername()); |
| | | guideCardBatch.setCreateTime(new Date()); |
| | | return this.save(guideCardBatch); |
| | | } |
| | | } |