diff --git a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/NuzarCustomerApplication.java b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/NuzarCustomerApplication.java index eab6eb3..358ac36 100644 --- a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/NuzarCustomerApplication.java +++ b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/NuzarCustomerApplication.java @@ -6,6 +6,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.scheduling.annotation.EnableAsync; /** * @Author limng @@ -15,6 +16,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients; @EnableCreateCacheAnnotation //开启Feign支持 @EnableFeignClients +@EnableAsync public class NuzarCustomerApplication implements CommandLineRunner { /** diff --git a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/handler/ExportInHandler.java b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/handler/ExportInHandler.java index cb220d7..34441d5 100644 --- a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/handler/ExportInHandler.java +++ b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/handler/ExportInHandler.java @@ -24,7 +24,6 @@ import com.haitonggauto.rtosc.common.dto.Result; import com.haitonggauto.rtosc.common.enums.ErrorType; import com.haitonggauto.rtosc.common.handler.BaseHandler; import com.haitonggauto.rtosc.common.utils.*; -import com.haitonggauto.rtosc.config.SyncConfig; import com.haitonggauto.rtosc.dto.*; import com.haitonggauto.rtosc.excel.*; import com.haitonggauto.rtosc.query.CargoQuery; @@ -35,10 +34,7 @@ import com.haitonggauto.rtosc.handler.excel.ReadExcelListener; import com.haitonggauto.rtosc.handler.mapper.PoMapper; import com.haitonggauto.rtosc.repository.enums.AuditEnum; import com.haitonggauto.rtosc.repository.query.PrintQuery; -import com.haitonggauto.rtosc.repository.service.CustomerExportInCargoService; -import com.haitonggauto.rtosc.repository.service.CustomerExportInService; -import com.haitonggauto.rtosc.repository.service.CustomerExportInTimesService; -import com.haitonggauto.rtosc.repository.service.CustomerExportLoadService; +import com.haitonggauto.rtosc.repository.service.*; import com.haitonggauto.rtosc.service.CustomerService; import com.nuzar.common.security5.common.util.SecurityUtils; import com.nuzar.rtops.log.dto.LogRecordDTO; @@ -46,6 +42,7 @@ import com.nuzar.rtops.log.service.EsLogApprovalUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; import org.apache.commons.io.IOUtils; @@ -107,9 +104,6 @@ public class ExportInHandler implements BaseHandler { @Resource private NuzarPubApi pubApi; - @Resource - private SyncConfig syncConfig; - @ApiOperation("船名航次模糊匹配") @PostMapping("/shipVoyage") public Result> getExportInShipNameList( @@ -1223,7 +1217,7 @@ public class ExportInHandler implements BaseHandler { List list = customerExportInService.lambdaQuery().in(CustomerExportIn::getId, check.getIds()).list(); if (check.getCheckStatus() == AuditEnum.AUDIT_PASS) { - this.syncAddExportInToOld(list); + customerService.syncAddExportInToOld(list); } // 记录日志 @@ -1281,7 +1275,7 @@ public class ExportInHandler implements BaseHandler { .eq(CustomerExportIn::getVoyageId, check.getVoyageId()).list(); if (check.getCheckStatus() == AuditEnum.AUDIT_PASS) { - this.syncAddExportInToOld(list); + customerService.syncAddExportInToOld(list); } // 记录日志 @@ -1336,7 +1330,7 @@ public class ExportInHandler implements BaseHandler { boolean row = customerExportInService.updateBatchById(exportIns); if (row) { - this.syncDelExportInToOld(check.getIds()); + customerService.syncDelExportInToOld(check.getIds()); return ResultUtil.success("success"); } return ResultUtil.failure(ErrorType.PARAMS_ERROR.id(), "修改失败,ID不存在"); @@ -3519,79 +3513,4 @@ public class ExportInHandler implements BaseHandler { return ResultUtil.success(rst, String.valueOf(page.getTotal())); } - - private void formatData(List ins) { - if (CollectionUtils.isEmpty(ins)) { - return; - } - ins.stream().forEach(item -> { - - }); - } - - private void syncAddExportInToOld(List list) throws Exception { - if (!syncConfig.getSync() || CollectionUtils.isEmpty(list)) { // 没有打开同步或,列表为空真直接返回 - return; - } - for (CustomerExportIn item : list) { - OldExportInAddReq req = PoMapper.instance.exportIn2OldExportInAddReq(item); - req.setVlsNm(item.getShipName()+"/"+item.getShipEnName()); - if (item.getLength() != null) { - req.setLength(req.getLength().setScale(3, RoundingMode.HALF_UP)); - } - if (item.getWidth() != null) { - req.setWidth(item.getWidth().setScale(3, RoundingMode.HALF_UP)); - } - if (item.getHeight() != null) { - req.setHeight(item.getHeight().setScale(3, RoundingMode.HALF_UP)); - } - if (item.getWeight() != null) { - req.setWeight(item.getWeight().setScale(3, RoundingMode.HALF_UP)); - } - if (StringUtils.equals("备件", item.getCartType())) { - req.setCarNum(0); - req.setPartNum(item.getQuantity()); - req.setPartOpMode(item.getOperateType()); - } else { - req.setCarNum(item.getQuantity()); - req.setPartNum(0); - req.setCarOpMode(item.getOperateType()); - } - if (item.getEachWeight() != null) { - req.setMnfWeight(item.getEachWeight().setScale(3, RoundingMode.HALF_UP)); - } - if (item.getEachVolume() != null) { - req.setMnfVolume(item.getEachVolume().setScale(3, RoundingMode.HALF_UP)); - } - - System.err.println(JSONObject.toJSONString(req)); - - String post = OkHttpUtils.post(syncConfig.getUrl() + "/execInPortPlanAdd", OkHttpUtils.buildJsonRequestBody(JSONObject.toJSONString(req)), null); - - JSONObject rst = JSONObject.parseObject(post); - - if (StringUtils.equals("0", rst.getString("success"))) { - throw new RuntimeException(rst.getString("errmsg")); - } - } - - } - - private void syncDelExportInToOld(List list) throws Exception { - if (!syncConfig.getSync() || CollectionUtils.isEmpty(list)) { // 没有打开同步或,列表为空真直接返回 - return; - } - for (Long id : list) { - Map params = new HashMap<>(); - params.put("nsId", String.valueOf(id)); - - String post = OkHttpUtils.post(syncConfig.getUrl() + "/execInPortPlanDel", OkHttpUtils.buildFormRequestBody(params), null); - - JSONObject rst = JSONObject.parseObject(post); - - if (StringUtils.equals("0", rst.getString("success"))) { - throw new RuntimeException(rst.getString("errmsg")); - } - } - } } diff --git a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/CustomerService.java b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/CustomerService.java index 10da963..5dde021 100644 --- a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/CustomerService.java +++ b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/CustomerService.java @@ -173,4 +173,8 @@ public interface CustomerService { * @param jobs */ void updateImportTake(Boolean imp, CustomerImportTake importTake, List cargos, List jobs); + + void syncAddExportInToOld(List list); + + void syncDelExportInToOld(List list); } diff --git a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/impl/CustomerServiceImpl.java b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/impl/CustomerServiceImpl.java index 7ea0c09..0a1a5a3 100644 --- a/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/impl/CustomerServiceImpl.java +++ b/nuzar-customer-controller/src/main/java/com/haitonggauto/rtosc/service/impl/CustomerServiceImpl.java @@ -1,21 +1,32 @@ package com.haitonggauto.rtosc.service.impl; import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.haitonggauto.rtosc.common.context.UserContext; +import com.haitonggauto.rtosc.common.dto.LoginUser; +import com.haitonggauto.rtosc.common.utils.OkHttpUtils; +import com.haitonggauto.rtosc.config.SyncConfig; +import com.haitonggauto.rtosc.dto.OldExportInAddReq; +import com.haitonggauto.rtosc.handler.mapper.PoMapper; import com.haitonggauto.rtosc.repository.entity.*; import com.haitonggauto.rtosc.repository.enums.SequenceTypeEnum; import com.haitonggauto.rtosc.repository.service.*; import com.haitonggauto.rtosc.service.CustomerService; import com.nuzar.cloud.annotation.echo.EchoResult; import com.nuzar.cloud.mapper.base.EchoEntity; +import com.nuzar.common.security5.common.util.SecurityUtils; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; @@ -76,6 +87,12 @@ public class CustomerServiceImpl implements CustomerService { @Resource private CustomerImportTakeJobService importTakeJobService; + @Resource + private CustomerExportInSyncLogService customerExportInSyncLogService; + + @Resource + private SyncConfig syncConfig; + @Override @EchoResult public T wrapperEntity(T entity) { @@ -766,4 +783,104 @@ public class CustomerServiceImpl implements CustomerService { importTakeJobService.saveBatch(insert); } } + + @Override + @Async + public void syncAddExportInToOld(List list) { + if (!syncConfig.getSync() || CollectionUtils.isEmpty(list)) { // 没有打开同步或,列表为空真直接返回 + return; + } + // 异步时,变量会丢失 + LoginUser tmpUser = new LoginUser(); + tmpUser.setUserId(SecurityUtils.getUserId()); + tmpUser.setRoleId(0L); + tmpUser.setAdmin(true); + + UserContext.setUser(tmpUser); + for (CustomerExportIn item : list) { + OldExportInAddReq req = PoMapper.instance.exportIn2OldExportInAddReq(item); + req.setVlsNm(item.getShipName()+"/"+item.getShipEnName()); + if (item.getLength() != null) { + req.setLength(req.getLength().setScale(3, RoundingMode.HALF_UP)); + } + if (item.getWidth() != null) { + req.setWidth(item.getWidth().setScale(3, RoundingMode.HALF_UP)); + } + if (item.getHeight() != null) { + req.setHeight(item.getHeight().setScale(3, RoundingMode.HALF_UP)); + } + if (item.getWeight() != null) { + req.setWeight(item.getWeight().setScale(3, RoundingMode.HALF_UP)); + } + if (StringUtils.equals("备件", item.getCartType())) { + req.setCarNum(0); + req.setPartNum(item.getQuantity()); + req.setPartOpMode(item.getOperateType()); + } else { + req.setCarNum(item.getQuantity()); + req.setPartNum(0); + req.setCarOpMode(item.getOperateType()); + } + if (item.getEachWeight() != null) { + req.setMnfWeight(item.getEachWeight().setScale(3, RoundingMode.HALF_UP)); + } + if (item.getEachVolume() != null) { + req.setMnfVolume(item.getEachVolume().setScale(3, RoundingMode.HALF_UP)); + } + + try { + + String post = OkHttpUtils.post(syncConfig.getUrl() + "/execInPortPlanAdd", OkHttpUtils.buildJsonRequestBody(JSONObject.toJSONString(req)), null); + + JSONObject rst = JSONObject.parseObject(post); + + System.err.println(rst.toJSONString()); + + if (StringUtils.equals("0", rst.getString("success"))) { + throw new RuntimeException("请求参数:" + JSONObject.toJSONString(req) + ", 错误信息:" + rst.getString("errmsg")); + } + } catch (Exception e) { + CustomerExportInSyncLog log = new CustomerExportInSyncLog(); + log.setBatchNo(StringUtils.joinWith(",", list.stream().map(p -> p.getBatchNo()).collect(Collectors.toList()))); + log.setRequestStr(JSONObject.toJSONString(req)); + log.setResponseStr(e.getMessage()); + customerExportInSyncLogService.save(log); + } + } + } + + @Override + @Async + public void syncDelExportInToOld(List list) { + if (!syncConfig.getSync() || CollectionUtils.isEmpty(list)) { // 没有打开同步或,列表为空真直接返回 + return; + } + // 异步时,变量会丢失 + LoginUser tmpUser = new LoginUser(); + tmpUser.setUserId(SecurityUtils.getUserId()); + tmpUser.setRoleId(0L); + tmpUser.setAdmin(true); + + UserContext.setUser(tmpUser); + for (Long id : list) { + Map params = new HashMap<>(); + params.put("nsId", String.valueOf(id)); + + try { + String post = OkHttpUtils.post(syncConfig.getUrl() + "/execInPortPlanDel", OkHttpUtils.buildFormRequestBody(params), null); + + JSONObject rst = JSONObject.parseObject(post); + + if (StringUtils.equals("0", rst.getString("success"))) { + throw new RuntimeException(rst.getString("errmsg")); + } + } catch (Exception e) { + CustomerExportInSyncLog log = new CustomerExportInSyncLog(); + log.setBatchNo(""); + log.setRequestStr(JSONObject.toJSONString(params)); + log.setResponseStr(e.getMessage()); + customerExportInSyncLogService.save(log); + } + } + } } diff --git a/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/entity/CustomerExportInSyncLog.java b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/entity/CustomerExportInSyncLog.java new file mode 100644 index 0000000..823265f --- /dev/null +++ b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/entity/CustomerExportInSyncLog.java @@ -0,0 +1,38 @@ +package com.haitonggauto.rtosc.repository.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.haitonggauto.rtosc.common.db.entity.BaseEntity; +import java.io.Serializable; +import lombok.Data; + +/** + * 出口进场基本表 + * @TableName customer_export_in_sync_log + */ +@TableName(value ="customer_export_in_sync_log") +@Data +public class CustomerExportInSyncLog extends BaseEntity implements Serializable { + /** + * 受理号 + */ + @TableField(value = "batch_no") + private String batchNo; + + /** + * 请求参数 + */ + @TableField(value = "request_str") + private String requestStr; + + /** + * 返回参数 + */ + @TableField(value = "response_str") + private String responseStr; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/mapper/CustomerExportInSyncLogMapper.java b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/mapper/CustomerExportInSyncLogMapper.java new file mode 100644 index 0000000..927a5a4 --- /dev/null +++ b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/mapper/CustomerExportInSyncLogMapper.java @@ -0,0 +1,18 @@ +package com.haitonggauto.rtosc.repository.mapper; + +import com.haitonggauto.rtosc.repository.entity.CustomerExportInSyncLog; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** +* @author dj +* @description 针对表【customer_export_in_sync_log(出口进场基本表)】的数据库操作Mapper +* @createDate 2024-02-02 15:56:08 +* @Entity com.haitonggauto.rtosc.repository.entity.CustomerExportInSyncLog +*/ +public interface CustomerExportInSyncLogMapper extends BaseMapper { + +} + + + + diff --git a/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/CustomerExportInSyncLogService.java b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/CustomerExportInSyncLogService.java new file mode 100644 index 0000000..35a24d8 --- /dev/null +++ b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/CustomerExportInSyncLogService.java @@ -0,0 +1,13 @@ +package com.haitonggauto.rtosc.repository.service; + +import com.haitonggauto.rtosc.repository.entity.CustomerExportInSyncLog; +import com.baomidou.mybatisplus.extension.service.IService; + +/** +* @author dj +* @description 针对表【customer_export_in_sync_log(出口进场基本表)】的数据库操作Service +* @createDate 2024-02-02 15:56:08 +*/ +public interface CustomerExportInSyncLogService extends IService { + +} diff --git a/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/impl/CustomerExportInSyncLogServiceImpl.java b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/impl/CustomerExportInSyncLogServiceImpl.java new file mode 100644 index 0000000..106095f --- /dev/null +++ b/nuzar-customer-repository/src/main/java/com/haitonggauto/rtosc/repository/service/impl/CustomerExportInSyncLogServiceImpl.java @@ -0,0 +1,22 @@ +package com.haitonggauto.rtosc.repository.service.impl; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.haitonggauto.rtosc.repository.entity.CustomerExportInSyncLog; +import com.haitonggauto.rtosc.repository.service.CustomerExportInSyncLogService; +import com.haitonggauto.rtosc.repository.mapper.CustomerExportInSyncLogMapper; +import org.springframework.stereotype.Service; + +/** +* @author dj +* @description 针对表【customer_export_in_sync_log(出口进场基本表)】的数据库操作Service实现 +* @createDate 2024-02-02 15:56:08 +*/ +@Service +public class CustomerExportInSyncLogServiceImpl extends ServiceImpl + implements CustomerExportInSyncLogService{ + +} + + + + diff --git a/nuzar-customer-repository/src/main/resources/mapper/CustomerExportInSyncLogMapper.xml b/nuzar-customer-repository/src/main/resources/mapper/CustomerExportInSyncLogMapper.xml new file mode 100644 index 0000000..76c21aa --- /dev/null +++ b/nuzar-customer-repository/src/main/resources/mapper/CustomerExportInSyncLogMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + id,batch_no,is_del, + create_by,create_date,update_by, + update_date,version,request_str, + response_str + +