From 403915beb25beccaffecce835cd4a61732dbc611 Mon Sep 17 00:00:00 2001 From: zhanghl <253316343@qq.com> Date: 星期五, 18 四月 2025 14:08:36 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderProcessMapper.java | 17 ++++ aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderJobMapper.xml | 6 + aps-modules/aps-job/src/main/java/com/aps/job/service/IApsWorkOrderProcessService.java | 5 + aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderJobMapper.java | 10 ++ aps-modules/aps-job/src/main/java/com/aps/job/service/impl/ApsWorkOrderProcessServiceImpl.java | 115 ++++++++++++++++++++++++---- aps-modules/aps-job/src/main/java/com/aps/job/task/RyTask.java | 15 +++ aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderProcessMapper.xml | 57 ++++++++++++++ aps-modules/aps-job/src/main/java/com/aps/job/domain/ApsWorkOrderJob.java | 9 +- 8 files changed, 208 insertions(+), 26 deletions(-) diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/domain/ApsWorkOrderJob.java b/aps-modules/aps-job/src/main/java/com/aps/job/domain/ApsWorkOrderJob.java index bbd6c87..e4d09d2 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/domain/ApsWorkOrderJob.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/domain/ApsWorkOrderJob.java @@ -1,12 +1,12 @@ package com.aps.job.domain; -import java.math.BigDecimal; - +import com.aps.common.core.annotation.Excel; +import com.aps.common.core.web.domain.BaseEntity; import com.fasterxml.jackson.annotation.JsonProperty; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -import com.aps.common.core.annotation.Excel; -import com.aps.common.core.web.domain.BaseEntity; + +import java.math.BigDecimal; /** * 宸ュ崟鍚屾瀵硅薄 aps_work_order_job @@ -439,6 +439,7 @@ .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) + .append("processStatus", getProcessStatus()) .toString(); } } diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderJobMapper.java b/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderJobMapper.java index 067ad2d..af9b270 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderJobMapper.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderJobMapper.java @@ -1,8 +1,9 @@ package com.aps.job.mapper; -import java.util.List; import com.aps.job.domain.ApsWorkOrderJob; import org.apache.ibatis.annotations.Mapper; + +import java.util.List; /** * 宸ュ崟鍚屾Mapper鎺ュ彛 @@ -64,4 +65,11 @@ int batchInsertApsWorkOrderJob(List<ApsWorkOrderJob> jobs); int deleteWorkOrderJobByOrderIds(List<String> orderIds); + /** + * 鏇存柊宸ュ崟宸ュ簭鍚屾鐘舵�� + * @param docNo + * @return + */ + public int updateApsWorkOrderJobPrccessStatus(String docNo); + } diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderProcessMapper.java b/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderProcessMapper.java index d1d04e8..96b6407 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderProcessMapper.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/mapper/ApsWorkOrderProcessMapper.java @@ -2,6 +2,7 @@ import com.aps.job.domain.ApsWorkOrderProcess; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.List; import java.util.Map; @@ -66,7 +67,21 @@ /** * 鏍规嵁宸ュ崟鍙峰拰宸ュ崟宸ュ簭鍙锋煡璇㈠伐鍗曞伐搴� * @param map - * @return + * @return 宸ュ簭id */ public Long existsByDocNoOpNumOpId(Map map); + + /** + * 鎵归噺鎻掑叆宸ュ崟宸ュ簭 + * @param list + * @return 鏇存柊鏁伴噺 + */ + int updateApsWorkOrderProcessBatch(@Param("list") List<ApsWorkOrderProcess> list); + + /** + * 鎵归噺鎻掑叆宸ュ崟宸ュ簭 + * @param list + * @return 鎻掑叆鏁伴噺 + */ + int insertApsWorkOrderProcessBatch(@Param("list") List<ApsWorkOrderProcess> list); } diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/service/IApsWorkOrderProcessService.java b/aps-modules/aps-job/src/main/java/com/aps/job/service/IApsWorkOrderProcessService.java index 17047aa..80d43f6 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/service/IApsWorkOrderProcessService.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/service/IApsWorkOrderProcessService.java @@ -66,4 +66,9 @@ * @return */ public void getWorkOrderProcessFromU9(List<String> docNos) throws Exception; + + /** + * 鍚屾宸ュ崟宸ュ簭鏁版嵁 + */ + public void syncWorkOrderProcessData(); } diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/service/impl/ApsWorkOrderProcessServiceImpl.java b/aps-modules/aps-job/src/main/java/com/aps/job/service/impl/ApsWorkOrderProcessServiceImpl.java index ac9fb54..e815c21 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/service/impl/ApsWorkOrderProcessServiceImpl.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/service/impl/ApsWorkOrderProcessServiceImpl.java @@ -2,13 +2,19 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.aps.common.core.utils.DateUtils; import com.aps.common.core.utils.StringUtils; +import com.aps.job.domain.ApsWorkOrderJob; +import com.aps.job.domain.ApsWorkOrderJobLog; import com.aps.job.domain.ApsWorkOrderProcess; +import com.aps.job.mapper.ApsWorkOrderJobMapper; import com.aps.job.mapper.ApsWorkOrderProcessMapper; +import com.aps.job.service.IApsWorkOrderJobLogService; import com.aps.job.service.IApsWorkOrderProcessService; -import jakarta.annotation.Resource; +import com.github.pagehelper.PageHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -17,6 +23,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,11 +42,17 @@ private final Logger logger = LoggerFactory.getLogger(ApsWorkOrderProcessServiceImpl.class); - @Resource + @Autowired private RestTemplate restTemplate; - @Resource + @Autowired private ApsWorkOrderProcessMapper apsWorkOrderProcessMapper; + + @Autowired + private ApsWorkOrderJobMapper apsWorkOrderJobMapper; + + @Autowired + private IApsWorkOrderJobLogService apsWorkOrderJobLogService; /** * 鏌ヨ宸ュ崟宸ュ簭 @@ -121,19 +134,33 @@ // 璁剧疆璇锋眰浣� JSONObject requestBody = new JSONObject(); requestBody.put("DocList", docNos); + requestBody.put("PageIndex", 1); + requestBody.put("PageSize", 1000); // 鍒涘缓HttpEntity瀵硅薄 HttpEntity<String> request = new HttpEntity<>(requestBody.toJSONString(), headers); // 鍙戦�丳OST璇锋眰 ResponseEntity<String> response = restTemplate.postForEntity(u9WorkOrderProcessUrl, request, String.class); + String responseBody = response.getBody(); + JSONObject responseBodyJson = JSONObject.parseObject(responseBody); + ApsWorkOrderJobLog apsWorkOrderJobLog = new ApsWorkOrderJobLog(); + apsWorkOrderJobLog.setRequestData(requestBody.toJSONString()); + apsWorkOrderJobLog.setCreateTime(DateUtils.getNowDate()); + apsWorkOrderJobLog.setBizType("work_order_process"); + apsWorkOrderJobLog.setResult("SUCCESS"); + apsWorkOrderJobLogService.insertApsWorkOrderJobLog(apsWorkOrderJobLog); if (response.getStatusCode().is2xxSuccessful()) { - String responseBody = response.getBody(); - if(StringUtils.isEmpty(responseBody)){ - JSONObject responseBodyJson = JSONObject.parseObject(responseBody); - if(!"200".equals(responseBodyJson.getString("status"))){ + if(!StringUtils.isEmpty(responseBody)){ + if("200".equals(responseBodyJson.getString("status"))){ JSONArray jsonArray = responseBodyJson.getJSONArray("data"); - if (jsonArray != null) { - jsonArray.forEach(jsonObject -> { - JSONObject process = (JSONObject) jsonObject; + if (!jsonArray.isEmpty()) { + List<ApsWorkOrderProcess> addList = new ArrayList<>(); + List<ApsWorkOrderProcess> updateList = new ArrayList<>(); + String nowDocNo = null; + for (Object o : jsonArray) { + JSONObject process = (JSONObject) o; + if (nowDocNo == null) { + nowDocNo = process.getString("DocNo"); + } Map<String, Object> params = new HashMap<>(); params.put("docNo", process.getString("DocNo")); params.put("opNum", process.getString("OpNum")); @@ -153,24 +180,76 @@ apsWorkOrderProcess.setOpStatus(process.getString("OpStatus")); apsWorkOrderProcess.setOrg(process.getString("Org")); apsWorkOrderProcess.setOrgCode(process.getString("OrgCode")); - if(existsId!=null){ + if (existsId != null) { apsWorkOrderProcess.setId(existsId); - apsWorkOrderProcessMapper.updateApsWorkOrderProcess(apsWorkOrderProcess); - logger.info("銆怳PDATE銆戣幏鍙栧苟鏇存柊U9宸ュ簭鎴愬姛锛併�愬伐鍗曞彿锛歿}锛屽伐搴忓彿锛歿}銆�", docNos, apsWorkOrderProcess.getOpNum()); - }else{ - apsWorkOrderProcessMapper.insertApsWorkOrderProcess(apsWorkOrderProcess); - logger.info("銆怚NSERT銆戣幏鍙栧苟鎻掑叆U9宸ュ簭鎴愬姛锛併�愬伐鍗曞彿锛歿}, 宸ュ簭鍙凤細{}銆�", docNos, apsWorkOrderProcess.getOpNum()); + updateList.add(apsWorkOrderProcess); + } else { + addList.add(apsWorkOrderProcess); } - }); + if(!nowDocNo.equals(process.getString("DocNo"))){ + //鏇存柊宸ュ崟鍚屾宸ュ簭鐘舵�� + apsWorkOrderJobMapper.updateApsWorkOrderJobPrccessStatus(nowDocNo); + nowDocNo = process.getString("DocNo"); + } + } + if(!updateList.isEmpty()){ + apsWorkOrderProcessMapper.updateApsWorkOrderProcessBatch(updateList); + apsWorkOrderJobLog.setResult("ok update "+updateList.size()); + apsWorkOrderJobLogService.updateApsWorkOrderJobLog(apsWorkOrderJobLog); + logger.info("銆怳PDATE銆戣幏鍙栧苟鏇存柊U9宸ュ簭鎴愬姛锛併�愬伐鍗曞彿锛歿}銆�", docNos); + } + if(!addList.isEmpty()){ + apsWorkOrderProcessMapper.insertApsWorkOrderProcessBatch(addList); + apsWorkOrderJobLog.setResult("ok insert "+updateList.size()); + apsWorkOrderJobLogService.updateApsWorkOrderJobLog(apsWorkOrderJobLog); + logger.info("銆怚NSERT銆戣幏鍙栧苟鎻掑叆U9宸ュ簭鎴愬姛锛併�愬伐鍗曞彿锛歿}銆�", docNos); + } } }else{ + apsWorkOrderJobLog.setResponseData(response.getBody()); + apsWorkOrderJobLog.setResult("fail"); + apsWorkOrderJobLogService.updateApsWorkOrderJobLog(apsWorkOrderJobLog); logger.error("銆怑RROR銆戞煡璇9宸ュ簭澶辫触锛併�愬伐鍗曞彿锛歿}, 閿欒鐮侊細{}锛岄敊璇俊鎭細{}銆�", docNos, responseBodyJson.getString("status"), responseBodyJson.getString("message")); } }else{ logger.warn("銆怶ARNING銆戞湭鏌ヨ鍒癠9宸ュ簭锛併�愬伐鍗曞彿锛歿}銆�", docNos); } } else { - throw new Exception("銆怑RROR銆戣幏鍙朥9宸ュ簭澶辫触锛併�愬伐鍗曞彿锛�"+ docNos +"銆�"); + apsWorkOrderJobLog.setResponseData(response.getBody()); + apsWorkOrderJobLog.setResult("fail"); + apsWorkOrderJobLogService.updateApsWorkOrderJobLog(apsWorkOrderJobLog); + throw new Exception("銆怑RROR銆戞煡璇9宸ュ簭澶辫触锛併�愬伐鍗曞彿锛歿"+ docNos +"}, 閿欒鐮侊細{"+ responseBodyJson.getString("status") +"}锛岄敊璇俊鎭細{"+ responseBodyJson.getString("message") +"}銆�"); + } + } + + @Override + public void syncWorkOrderProcessData() { + try{ + //鍒嗛〉鏌ヨ宸ュ崟 + ApsWorkOrderJob apsWorkOrderJob = new ApsWorkOrderJob(); + apsWorkOrderJob.setProcessStatus("0"); + List<ApsWorkOrderJob> list = apsWorkOrderJobMapper.selectApsWorkOrderJobList(apsWorkOrderJob); + int pageSize = 100; + int allPage = list.size()/pageSize; +// int allPage = 1; + for (int i = 1; i <= allPage; i++) { + long startTime = System.currentTimeMillis(); + PageHelper.startPage(i, pageSize); + List<ApsWorkOrderJob> pageList = apsWorkOrderJobMapper.selectApsWorkOrderJobList(apsWorkOrderJob); + if(!pageList.isEmpty()){ + List<String> docNos = new ArrayList<>(); + for (ApsWorkOrderJob apsWorkOrderJob1 : pageList){ + docNos.add(apsWorkOrderJob1.getDocNo()); + } + getWorkOrderProcessFromU9(docNos); + } + long endTime = System.currentTimeMillis(); // 璁板綍缁撴潫鏃堕棿 + long duration = endTime - startTime; // 璁$畻杩愯鏃堕棿 + System.out.println("杩愯鏃堕棿锛�"+ duration +"姣"); + } + }catch (Exception e){ + e.printStackTrace(); + logger.error(e.getMessage()); } } } diff --git a/aps-modules/aps-job/src/main/java/com/aps/job/task/RyTask.java b/aps-modules/aps-job/src/main/java/com/aps/job/task/RyTask.java index 6cf995b..857c706 100644 --- a/aps-modules/aps-job/src/main/java/com/aps/job/task/RyTask.java +++ b/aps-modules/aps-job/src/main/java/com/aps/job/task/RyTask.java @@ -1,7 +1,9 @@ package com.aps.job.task; -import org.springframework.stereotype.Component; import com.aps.common.core.utils.StringUtils; +import com.aps.job.service.IApsWorkOrderProcessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * 瀹氭椂浠诲姟璋冨害娴嬭瘯 @@ -11,6 +13,9 @@ @Component("ryTask") public class RyTask { + + @Autowired + private IApsWorkOrderProcessService iApsWorkOrderProcessService; public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i) { System.out.println(StringUtils.format("鎵ц澶氬弬鏂规硶锛� 瀛楃涓茬被鍨媨}锛屽竷灏旂被鍨媨}锛岄暱鏁村瀷{}锛屾诞鐐瑰瀷{}锛屾暣褰}", s, b, l, d, i)); @@ -25,4 +30,12 @@ { System.out.println("鎵ц鏃犲弬鏂规硶"); } + + /** + * 鍚屾宸ュ崟宸ュ簭鏁版嵁 + */ + public void syncWorkOrderProcessData() + { + iApsWorkOrderProcessService.syncWorkOrderProcessData(); + } } diff --git a/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderJobMapper.xml b/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderJobMapper.xml index 229d57a..b8a6848 100644 --- a/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderJobMapper.xml +++ b/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderJobMapper.xml @@ -35,6 +35,7 @@ <result property="createTime" column="create_time" /> <result property="updateBy" column="update_by" /> <result property="updateTime" column="update_time" /> + <result property="processStatus" column="process_status" /> </resultMap> @@ -281,4 +282,9 @@ #{id} </foreach> </delete> + + <update id="updateApsWorkOrderJobPrccessStatus" parameterType="String"> + update aps_work_order_job set process_status='1' where doc_no = #{docNo} + </update> + </mapper> \ No newline at end of file diff --git a/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderProcessMapper.xml b/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderProcessMapper.xml index 366a651..981eb19 100644 --- a/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderProcessMapper.xml +++ b/aps-modules/aps-job/src/main/resources/mapper/job/ApsWorkOrderProcessMapper.xml @@ -40,7 +40,7 @@ <if test="scrapQty != null "> and scrap_qty = #{scrapQty}</if> <if test="opStatus != null and opStatus != ''"> and op_status = #{opStatus}</if> <if test="org != null and org != ''"> and org = #{org}</if> - <if test="org_code != null and opStatus != ''"> and op_status = #{opStatus}</if> + <if test="org_code != null and org_code != ''"> and org_code = #{orgCode}</if> </where> </select> @@ -123,4 +123,59 @@ and op_id = #{opId} </select> + <update id="updateApsWorkOrderProcessBatch"> + <foreach collection="list" item="item" separator=";"> + UPDATE aps_work_order_process + SET item_code = #{item.itemCode}, + doc_no = #{item.docNo}, + op_num = #{item.opNum}, + op_id = #{item.opId}, + process_name = #{item.processName}, + standard_time = #{item.standardTime}, + plan_start_date = #{item.palnStartDate}, + plan_complete_date = #{item.planCompleteDate}, + process_qty = #{item.processQty}, + scrap_qty = #{item.scrapQty}, + op_status = #{item.opStatus}, + org = #{item.org}, + org_code = #{item.orgCode} + WHERE id = #{item.id} + </foreach> + </update> + + <insert id="insertApsWorkOrderProcessBatch"> + INSERT INTO aps_work_order_process ( + item_code, + doc_no, + op_num, + op_id, + process_name, + standard_time, + plan_start_date, + plan_complete_date, + process_qty, + scrap_qty, + op_status, + org, + org_code + ) VALUES + <foreach collection="list" item="item" separator=","> + ( + #{item.itemCode}, + #{item.docNo}, + #{item.opNum}, + #{item.opId}, + #{item.processName}, + #{item.standardTime}, + #{item.palnStartDate}, + #{item.planCompleteDate}, + #{item.processQty}, + #{item.scrapQty}, + #{item.opStatus}, + #{item.org}, + #{item.orgCode} + ) + </foreach> + </insert> + </mapper> \ No newline at end of file -- Gitblit v1.9.3