mes-basic/src/main/java/com/chinaztt/mes/basic/controller/PartController.java
@@ -25,6 +25,7 @@ import com.chinaztt.mes.basic.excel.PartData; import com.chinaztt.mes.basic.excel.PartUploadListener; import com.chinaztt.mes.basic.service.PartService; import com.chinaztt.mes.common.util.JsonUtil; import com.chinaztt.mes.common.wrapper.QueryWrapperUtil; import com.chinaztt.ztt.admin.api.entity.SysDictItem; import com.chinaztt.ztt.admin.api.feign.RemoteDictService; @@ -42,7 +43,6 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.Date; import java.util.List; @@ -74,6 +74,9 @@ @GetMapping("/page") @PreAuthorize("@pms.hasPermission('basic_part_view')") public R getPartPage(Page page, Part part, Long bomId) { //System.out.println(bomId); //System.out.println(part); System.out.println(JsonUtil.jsonToString(page)); return R.ok(partService.getPartPage(page, QueryWrapperUtil.gen(part), bomId)); } /** @@ -91,11 +94,19 @@ partService.syncPart(); return R.ok(); } //@InitBinder //protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception { // //System.out.println(request.getParameter("date")); // DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // CustomDateEditor editor = new CustomDateEditor(df, true);//true表示å 许为空ï¼falseåä¹ // binder.registerCustomEditor(Date.class, editor); //} @ApiOperation(value = "忥Ifs", notes = "忥Ifs") @PostMapping("/syncNewIfs") //@XxlJob("syncPart") public R syncNewIfs(Date date) { System.out.println(date); public R syncNewIfs(String date) { String key = "syncPart_lock"+ SecurityUtils.getUser().getId(); if (redisTemplate.hasKey(key)) { throw new RuntimeException("æåæ¥ä»»å¡æ£å¨å¤ç"); mes-basic/src/main/java/com/chinaztt/mes/basic/service/PartService.java
@@ -26,7 +26,6 @@ import com.chinaztt.mes.basic.excel.PartData; import com.chinaztt.ztt.common.core.util.R; import java.util.Date; import java.util.List; /** @@ -131,5 +130,5 @@ void syncPart(); Long syncNewIfs(Date date); Long syncNewIfs(String date); } mes-basic/src/main/java/com/chinaztt/mes/basic/service/impl/PartServiceImpl.java
@@ -17,7 +17,6 @@ package com.chinaztt.mes.basic.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; @@ -33,6 +32,7 @@ import com.chinaztt.mes.basic.service.PartService; import com.chinaztt.mes.basic.util.DictUtils; import com.chinaztt.mes.basic.util.PartUtils; import com.chinaztt.mes.basic.util.TransactionUtils; import com.chinaztt.mes.common.util.JsonUtil; import com.chinaztt.ztt.common.core.util.R; import com.chinaztt.ztt.common.security.util.SecurityUtils; @@ -54,11 +54,15 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import java.io.IOException; import java.math.BigDecimal; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.*; /** @@ -77,7 +81,9 @@ private DiscoveryClient discoveryClient; private Environment environment; private RedisTemplate redisTemplate; private TransactionUtils transactionUtils; ; @Override public void importPartExcel(List<PartData> list) { @@ -369,9 +375,10 @@ } @Transactional(rollbackFor = Exception.class) @Override public Long syncNewIfs(Date date) { @Transactional(rollbackFor = Exception.class) public Long syncNewIfs(String date) { TransactionStatus transaction = transactionUtils.begin(TransactionDefinition.ISOLATION_READ_COMMITTED); Map<String, String> dicmattype = dictUtils.getDicKey("material_type"); Map<String, String> dicunit = dictUtils.getDicKey("unit"); String key = "syncPart_lock" + SecurityUtils.getUser().getId(); @@ -379,16 +386,26 @@ throw new RuntimeException("æåæ¥ä»»å¡æ£å¨å¤ç"); } redisTemplate.opsForValue().set(key, 1, 1000 * 3600); Map<String, Object>map=new HashMap<>(); map.put("MODIFY_DATE", DateUtil.format(date,"yyyy-MM-dd")); List<Part>partList=new ArrayList<Part>(); Connection conn =null; PreparedStatement pstmt =null; try { String url =""; //å¤ææ¥ææå¦ if (Objects.isNull(date)){ url = "http://192.168.20.47:8008/PurchService.ashx?contract=KJZS&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr={}"; }else { Map<String, Object>map=new HashMap<>(); map.put("MODIFY_DATE", date); url = "http://192.168.20.47:8008/PurchService.ashx?contract=KJZS&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr="+new ObjectMapper().writeValueAsString(map); } log.info("å¼å§æ§è¡åæ¥==========ã"); String url = "http://192.168.20.47:8008/PurchService.ashx?contract=ZTKJ&contractKey=4ttDeLKNsZuhstjtROMcRE1USNFXKdFYE7lQ2p1m5Bo=&procedureName=QUERY_INVENTORY_PART_INFO_STD&userId=7632&inAttr="+new ObjectMapper().writeValueAsString(map); String body = HttpRequest.get(url).execute().body(); log.info("æ§è¡åæ¥ç»æ===========ã"); Map<String, Object> mapResult = JsonUtil.jsonToPojo(body, Map.class); List<Map<String, Object>> data = JsonUtil.jsonToPojo(JsonUtil.jsonToString(mapResult.get("INVENTORY_PART_INFO")), List.class); System.out.println(data.size()); //data.forEach(System.out::println); List<String>no=new ArrayList<String>(); data.forEach(l->{ Part part = new Part(); @@ -418,8 +435,8 @@ List<Part> selectList = baseMapper.selectList(queryWrapper); //System.out.println(baseMapper.selectList(queryWrapper)); partList.removeIf(mainObj -> selectList.stream().anyMatch(subObj -> subObj.getPartNo().equals(mainObj.getPartNo()))); //System.out.println(partList); partList.forEach(l -> { System.out.println("è¿æ»¤é¿åº¦=============================ã"+partList.size()); partList.forEach(l->{ baseMapper.insert(l); }); } @@ -427,6 +444,7 @@ e.printStackTrace(); throw new RuntimeException(e.getMessage()); } finally { //JDBCUtil.close(pstmt,conn); redisTemplate.delete(key); } return (long) partList.size(); mes-basic/src/main/java/com/chinaztt/mes/basic/util/JDBCUtil.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,48 @@ package com.chinaztt.mes.basic.util; import java.sql.*; /** * @Author å¼ å®¾ * @Date 2023/10/26 */ public class JDBCUtil { private static String url; private static String user; private static String password; private static String driver; static { try { url = "jdbc:postgresql://127.0.0.1:5432/postgres"; user = "postgres"; password = "root2022"; driver = "org.postgresql.Driver"; } catch (Exception e) { e.getMessage(); } } public static Connection getConn() throws Exception { Connection connection = DriverManager.getConnection(url, user, password); return connection; } public static void close(PreparedStatement preparedStatement, Connection connection) { try { if (preparedStatement != null) { preparedStatement.close(); } if (connection != null) { connection.close(); } } catch (SQLException e) { throw new RuntimeException(); } } } mes-basic/src/main/java/com/chinaztt/mes/basic/util/TransactionUtils.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,44 @@ package com.chinaztt.mes.basic.util; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; import javax.annotation.Resource; /** * @Author å¼ å®¾ * @Date 2023/10/26 */ @Component public class TransactionUtils { @Resource private DataSourceTransactionManager transactionManager; //å¼å¯äºå¡,ä¼ å ¥éç¦»çº§å« public TransactionStatus begin(int isolationLevel) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); // äºç©é离级å«ï¼å¼å¯æ°äºå¡ TransactionDefinition.ISOLATION_READ_COMMITTED def.setIsolationLevel(isolationLevel); // äºå¡ä¼ æè¡ä¸º def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); //é»è®¤äºå¡ TransactionStatus transaction = transactionManager.getTransaction(def); //å°æ¿å°çäºå¡è¿åè¿å»ï¼æè½æäº¤ã return transaction; } //æäº¤äºå¡ public void commit(TransactionStatus transaction) { //æäº¤äºå¡ transactionManager.commit(transaction); } //åæ»äºå¡ public void rollback(TransactionStatus transaction) { transactionManager.rollback(transaction); } } mes-common/src/main/java/com/chinaztt/mes/common/config/TransactionConfig.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,11 @@ package com.chinaztt.mes.common.config; import org.springframework.context.annotation.Configuration; /** * @Author å¼ å®¾ * @Date 2023/10/26 */ @Configuration public class TransactionConfig { } mes-technology/src/main/java/com/chinaztt/mes/technology/controller/DocumentController.java
@@ -37,7 +37,6 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -258,7 +257,7 @@ * @return */ @PostMapping("/uploadJgt") public R uploadJgt(@RequestParam("file") List<MultipartFile> file, @RequestParam("documentId") Long documentId) { public R uploadJgt(@RequestParam("file") MultipartFile file, @RequestParam("documentId") Long documentId) { return documentService.uploadJgt(file, documentId); } @@ -301,9 +300,9 @@ * @param fileName * @param response */ @Inner(false) @GetMapping("/file/{fileName}") public void file(@PathVariable String fileName, HttpServletResponse response) { @Inner(value = false) @GetMapping("/file") public void file(@RequestParam("fileName") String fileName, HttpServletResponse response) { documentService.getFile(fileName, response); } mes-technology/src/main/java/com/chinaztt/mes/technology/feign/MesFileApi.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,20 @@ package com.chinaztt.mes.technology.feign; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.multipart.MultipartFile; import java.util.List; /** * @Author å¼ å®¾ * @Date 2023/10/27 */ @FeignClient(value = "mes-file",path = "/mes-file") public interface MesFileApi { @PostMapping(value = "/uploadFile",consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = {MediaType.APPLICATION_JSON_VALUE}) String uploadFile(MultipartFile file); } mes-technology/src/main/java/com/chinaztt/mes/technology/service/DocumentService.java
@@ -23,7 +23,6 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.chinaztt.mes.quality.dto.TestStandardDTO; import com.chinaztt.mes.quality.entity.TestStandard; import com.chinaztt.mes.technology.dto.DocTestStandardDTO; import com.chinaztt.mes.technology.dto.DocumentDTO; import com.chinaztt.mes.technology.dto.DocumentMaterialCostDTO; import com.chinaztt.mes.technology.dto.JoinDocumentTestStandardDTO; @@ -34,8 +33,6 @@ import com.chinaztt.mes.technology.excel.DocumentTestStandardData; import com.chinaztt.mes.technology.state.document.constant.DocumentStates; import com.chinaztt.ztt.common.core.util.R; import com.sun.org.apache.xpath.internal.operations.Bool; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; @@ -134,7 +131,7 @@ * @param documentId * @return */ R uploadJgt(List<MultipartFile> file, Long documentId); R uploadJgt(MultipartFile file, Long documentId); /** * ä¸ä¼ æµç¨å¾æä»¶ mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/DocumentServiceImpl.java
@@ -17,6 +17,7 @@ package com.chinaztt.mes.technology.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.IoUtil; import cn.hutool.core.util.BooleanUtil; @@ -53,6 +54,7 @@ import com.chinaztt.mes.technology.entity.*; import com.chinaztt.mes.technology.excel.DocumentTestStandardData; import com.chinaztt.mes.technology.excel.MaterialCostData; import com.chinaztt.mes.technology.feign.MesFileApi; import com.chinaztt.mes.technology.mapper.*; import com.chinaztt.mes.technology.service.DocumentJgtService; import com.chinaztt.mes.technology.service.DocumentService; @@ -72,13 +74,13 @@ import lombok.extern.slf4j.Slf4j; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; import java.io.*; import java.math.BigDecimal; import java.net.URLEncoder; import java.time.LocalDateTime; @@ -127,6 +129,13 @@ private DocumentJgtMapper documentJgtMapper; private DocumentJgtService documentJgtService; private DocumentSamplingRuleMapper documentSamplingRuleMapper; @Autowired private MesFileApi mesFileApi; private static final String locationImg="D:/file/img"; private static final String file_img_url = "http://127.0.0.1:6066/Image/img"; /** * @Author: Hans @@ -600,23 +609,61 @@ @SneakyThrows @Override public R uploadJgt(List<MultipartFile> file, Long documentId) { List<DocumentJgt> list = new ArrayList<>(); for (MultipartFile multipartFile:file) { String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(multipartFile.getOriginalFilename()); minioTemplate.putObject(OSS_BUCKET, fileName, multipartFile.getInputStream()); DocumentJgt jgt = new DocumentJgt(); jgt.setFileName(fileName); jgt.setDocumentId(documentId); list.add(jgt); } //å·¥èºä¸»è¡¨æ´æ°æ¶é´ï¼æ´æ°äºº Document document = new Document(); document.setId(documentId); baseMapper.updateById(doUpdateRealUser(document)); documentJgtService.saveBatch(list); List<String> fileNameList = list.stream().map(a -> a.getFileName()).collect(Collectors.toList()); return R.ok(org.apache.commons.lang3.StringUtils.join(fileNameList,",")); public R uploadJgt(MultipartFile file, Long documentId) { String requestUrl=""; String fileName = IdUtil.simpleUUID() + StrUtil.DOT + FileUtil.extName(file.getOriginalFilename()); //minioTemplate.putObject(OSS_BUCKET, fileName, multipartFile.getInputStream()); //å建æä»¶å¤¹ String timeForder= DateUtil.format(DateUtil.date(),"yyyy/MM/dd"); String forder=locationImg+"/"+OSS_BUCKET+"/"+timeForder; File filePath = new File(forder); if(!filePath.exists()){ filePath.mkdirs(); } //åå¹¶æä»¶ RandomAccessFile raFile = null; BufferedInputStream inputStream=null; try{ File dirFile = new File(forder, fileName); //以读åçæ¹å¼æå¼ç®æ æä»¶ raFile = new RandomAccessFile(dirFile, "rw"); raFile.seek(raFile.length()); inputStream = new BufferedInputStream(file.getInputStream()); byte[] buf = new byte[1024]; int length = 0; while ((length = inputStream.read(buf)) != -1) { raFile.write(buf, 0, length); } requestUrl=OSS_BUCKET+"/"+timeForder+"/"+fileName; }catch(Exception e){ e.printStackTrace(); }finally{ try { if (inputStream != null) { inputStream.close(); } if (raFile != null) { raFile.close(); } }catch(Exception ignored){ } } String url = requestUrl; QueryWrapper<DocumentJgt>queryWrapper=new QueryWrapper<>(); queryWrapper.lambda().eq(DocumentJgt::getDocumentId,documentId); DocumentJgt documentJgt = documentJgtMapper.selectOne(queryWrapper); if(Objects.nonNull(documentJgt)){ UpdateWrapper<DocumentJgt>updateWrapper=new UpdateWrapper<>(); updateWrapper.lambda().eq(DocumentJgt::getDocumentId,documentId).set(DocumentJgt::getFileName,locationImg+"/"+url); documentJgtMapper.update(null,updateWrapper); }else { DocumentJgt jgt=new DocumentJgt(); jgt.setDocumentId(documentId); jgt.setFileName(locationImg+"/"+url); documentJgtMapper.insert(jgt); } return R.ok(locationImg+"/"+url); } @SneakyThrows @@ -668,7 +715,7 @@ @Override public void getFile(String fileName, HttpServletResponse response) { try (InputStream inputStream = minioTemplate.getObject(OSS_BUCKET, fileName)) { try (InputStream inputStream = new FileInputStream(fileName)) { response.setContentType("application/octet-stream; charset=UTF-8"); IoUtil.copy(inputStream, response.getOutputStream()); } catch (Exception e) { @@ -792,11 +839,15 @@ if (CollectionUtil.isEmpty(routings)) { throw new RuntimeException("ä¿å失败ï¼é¶ä»¶ï¼" + document.getPartNo() + "æ å·¥èºè·¯çº¿"); } Routing routing = routings.get(0); joinDocumentBomRouting.setRoutingId(routing.getId()); joinDocumentBomRouting.setBomId(routing.getBomId()); joinDocumentBomRoutingMapper.insertAndGetId(joinDocumentBomRouting); // æ·»å æ£æµæ å Routing routing = routings.get(0); joinDocumentBomRouting.setRoutingId(routing.getId()); joinDocumentBomRouting.setBomId(routing.getBomId()); Routing routing1 = routingMapper.selectById(joinDocumentBomRouting.getRoutingId()); if(Objects.equals(routing1.getState(),RoutingStateStringValues.DRAFT)){ throw new RuntimeException("å·¥èºè·¯çº¿ç¶ææªéè¿ï¼"); } joinDocumentBomRoutingMapper.insertAndGetId(joinDocumentBomRouting); // æ·»å æ£æµæ å addDocTestStandard(joinDocumentBomRouting); // 设置åèç¹æ°æ® addBomRoutingPartByBomId(joinDocumentBomRouting.getId(), routing.getBomId(), mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/RoutingServiceImpl.java
@@ -46,6 +46,7 @@ import com.chinaztt.mes.technology.excel.RoutingExcelData; import com.chinaztt.mes.technology.mapper.*; import com.chinaztt.mes.technology.service.RoutingService; import com.chinaztt.mes.technology.state.bom.constant.BomStateStringValues; import com.chinaztt.mes.technology.state.routing.RoutingStateMachineConfig; import com.chinaztt.mes.technology.state.routing.constant.RoutingEvents; import com.chinaztt.mes.technology.state.routing.constant.RoutingStateStringValues; @@ -168,6 +169,10 @@ if (noCount > 0) { throw new RuntimeException("ç¼å·éå¤"); } Bom bom = bomMapper.selectById(routingDTO.getBomId()); if(Objects.equals(BomStateStringValues.DRAFT,bom.getState())){ throw new RuntimeException("BOMç¶ææªéè¿ï¼"); } //主表ä¸ãé¶ä»¶å·ãããå·¥èºçæ¬ãããæ¿ä»£ãå¼çç»åé¡»å¯ä¸ã noCount = baseMapper.selectCount(Wrappers.<Routing>lambdaQuery().eq(Routing::getPartId, routingDTO.getPartId()) .eq(Routing::getBomTypeDb, routingDTO.getBomTypeDb()) mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/StructureServiceImpl.java
@@ -386,9 +386,9 @@ structure.setIfsSync(false); resetMaster(structure); baseMapper.updateById(structure); // 对æ¥ifs List<StructureDTO> structureDTOS = structureMapper.getStructureDtoByIds(Arrays.asList(structure.getId())); structureIfsSyncByDto(structureDTOS); //// 对æ¥ifs //List<StructureDTO> structureDTOS = structureMapper.getStructureDtoByIds(Arrays.asList(structure.getId())); //structureIfsSyncByDto(structureDTOS); return R.ok(); } mes-web/src/main/java/com/chinaztt/mes/App.java
@@ -16,7 +16,7 @@ @EnableZttSwagger2 @SpringCloudApplication @EnableDiscoveryClient @EnableZttFeignClients(basePackages = {"com.chinaztt.ztt", "com.chinaztt.ifs", "com.chinaztt.inspect"}) @EnableZttFeignClients(basePackages = {"com.chinaztt.**"}) @EnableZttResourceServer @EnableZttXxlJob public class App { mes-web/src/main/resources/bootstrap.yml
@@ -38,7 +38,6 @@ log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #erpBase: http://localhost:7071/zbgj ## 忥åå #erpUrl: ${erpBase}/syncList