diff --git a/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java b/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java index cc237bb62..e2aaa6e44 100644 --- a/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java +++ b/src/main/java/com/glxp/api/controller/inout/IoCodeTempController.java @@ -1214,7 +1214,6 @@ public class IoCodeTempController extends BaseController { if (StrUtil.isNotEmpty(codeTempEntity.getBatchNo()) && codeTempEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!批次号超出最大范围"); } - if (StrUtil.isBlank(codeTempEntity.getSerialNo()) && StrUtil.isBlank(codeTempEntity.getBatchNo())) { return ResultVOUtils.error(500, "批次号不能为空!"); } diff --git a/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java b/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java index 2687a3cf9..1494dcf37 100644 --- a/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java +++ b/src/main/java/com/glxp/api/http/sync/SpGetHttpClient.java @@ -22,10 +22,14 @@ import com.glxp.api.req.sync.OrderStatusFilterRequest; import com.glxp.api.req.sync.SyncUpLoadRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.inout.RefreshInoiceResponse; +import com.glxp.api.res.inv.InvPreProductResponse; +import com.glxp.api.res.inv.InvPreinProductResponse; +import com.glxp.api.res.inv.InvProductResponse; import com.glxp.api.res.sync.*; import com.glxp.api.res.system.SyncDataSetResponse; import com.glxp.api.service.sync.SyncDataSetService; import com.glxp.api.util.OkHttpCli; +import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -438,12 +442,58 @@ public class SpGetHttpClient { public BaseResponse postTemplateFile(List fileNameList) { return fileService.upload(fileNameList); + } -// String json = JSONUtil.toJsonStr(fileNameList); -// String result = okHttpCli.doPostJson(getIpUrl() + "/spssync/file/download", json, buildHeader()); -// BaseResponse response = -// JSONObject.parseObject(result, new TypeReference>() { -// }); -// return response; + //下载普通库存 + public BaseResponse> getInvData(Integer page, Integer limit) { + Map paramMap = new HashMap<>(16); + paramMap.put("page", page + ""); + paramMap.put("limit", limit + ""); + String response = okHttpCli.doGet(getIpUrl() + "/syncToSpms" + "/spms/inv/product/vail", paramMap, buildHeader()); + try { + BaseResponse> data = + JSONObject.parseObject(response, new TypeReference>>() { + }); + return data; + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error(500, "下载失败!"); + } } + + //下载寄售库存 + public BaseResponse> getInvPreData(Integer page, Integer limit) { + Map paramMap = new HashMap<>(16); + paramMap.put("page", page + ""); + paramMap.put("limit", limit + ""); + String response = okHttpCli.doGet(getIpUrl() + "/syncToSpms" + "/spms/inv/pre/product/vail", paramMap, buildHeader()); + try { + BaseResponse> data = + JSONObject.parseObject(response, new TypeReference>>() { + }); + return data; + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error(500, "下载失败!"); + } + } + + //下载预验收库存 + public BaseResponse> getInvPreInData(Integer page, Integer limit) { + Map paramMap = new HashMap<>(16); + paramMap.put("page", page + ""); + paramMap.put("limit", limit + ""); + String response = okHttpCli.doGet(getIpUrl() + "/syncToSpms" + "/spms/inv/preIn/product/vail", paramMap, buildHeader()); + try { + BaseResponse> data = + JSONObject.parseObject(response, new TypeReference>>() { + }); + return data; + } catch (Exception e) { + e.printStackTrace(); + return ResultVOUtils.error(500, "下载失败!"); + } + } + + } diff --git a/src/main/java/com/glxp/api/task/VailInvTask.java b/src/main/java/com/glxp/api/task/VailInvTask.java new file mode 100644 index 000000000..058d362e1 --- /dev/null +++ b/src/main/java/com/glxp/api/task/VailInvTask.java @@ -0,0 +1,173 @@ +package com.glxp.api.task; + +import com.glxp.api.common.res.BaseResponse; +import com.glxp.api.dao.schedule.ScheduledDao; +import com.glxp.api.entity.inv.InvPreProductEntity; +import com.glxp.api.entity.inv.InvPreinProductEntity; +import com.glxp.api.entity.inv.InvProductEntity; +import com.glxp.api.entity.system.ScheduledEntity; +import com.glxp.api.http.sync.SpGetHttpClient; +import com.glxp.api.req.system.ScheduledRequest; +import com.glxp.api.res.PageSimpleResponse; +import com.glxp.api.res.inv.InvProductResponse; +import com.glxp.api.service.inv.InvPreProductService; +import com.glxp.api.service.inv.InvPreinProductService; +import com.glxp.api.service.inv.InvProductService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.SchedulingConfigurer; +import org.springframework.scheduling.config.ScheduledTaskRegistrar; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +@Slf4j +@Component +@Transactional(rollbackFor = Exception.class) +public class VailInvTask implements SchedulingConfigurer { + + + @Resource + private ScheduledDao scheduledDao; + @Resource + SpGetHttpClient spGetHttpClient; + + @Override + public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) { + scheduledTaskRegistrar.addTriggerTask(() -> process(), + triggerContext -> { + ScheduledRequest scheduledRequest = new ScheduledRequest(); + scheduledRequest.setCronName("dlThrSysHeartTask"); + ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest); + if (scheduledEntity != null) { + String cron = scheduledEntity.getCron(); + if (cron.isEmpty()) { + log.error("cron is null"); + } + return new CronTrigger(cron).nextExecutionTime(triggerContext); + } else + return null; + + }); + } + + private void process() { + + StringBuffer stringBuffer = new StringBuffer(); + String invStr = downloadInv(); + String invPreStr = downloadPreInv(); + String invPreInStr = downloadPreInInv(); + stringBuffer.append("------------普通库存-----------------------\n"); + stringBuffer.append(invStr); + stringBuffer.append("------------寄售库存-----------------------\n"); + stringBuffer.append(invPreStr); + stringBuffer.append("------------预验收库存-----------------------\n"); + stringBuffer.append(invPreInStr); + + + + } + + @Resource + InvProductService invProductService; + @Resource + InvPreinProductService invPreinProductService; + @Resource + InvPreProductService invPreProductService; + + public String downloadInv() { + int page = 1; + int limit = 100; + StringBuffer buffer = new StringBuffer(); + while (true) { + BaseResponse> baseResponse = spGetHttpClient.getInvData(page, limit); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.forEach(invProductResponse -> { + InvProductEntity invProductEntity = invProductService.selectByUnique(Long.getLong(invProductResponse.getRelIdFk()), invProductResponse.getBatchNo(), invProductResponse.getSupId(), invProductResponse.getDeptCode(), invProductResponse.getInvCode()); + if (invProductEntity.getInCount() != invProductResponse.getInCount() || invProductEntity.getOutCount() != invProductResponse.getOutCount()) { + buffer.append(invProductResponse.getCpmctymc() + "," + + invProductResponse.getNameCode() + "," + + invProductResponse.getBatchNo() + "," + + invProductResponse.getSupName() + "," + + invProductResponse.getDeptName() + "," + + invProductResponse.getInvCode() + "\n"); + } + }); + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return buffer.toString(); + } + } + return buffer.toString(); + } + + public String downloadPreInv() { + int page = 1; + int limit = 100; + StringBuffer buffer = new StringBuffer(); + while (true) { + BaseResponse> baseResponse = spGetHttpClient.getInvData(page, limit); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.forEach(invProductResponse -> { + InvPreProductEntity invProductEntity = invPreProductService.selectByUnique(Long.getLong(invProductResponse.getRelIdFk()), invProductResponse.getBatchNo(), invProductResponse.getSupId(), invProductResponse.getDeptCode(), invProductResponse.getInvCode()); + if (invProductEntity.getInCount() != invProductResponse.getInCount() || invProductEntity.getOutCount() != invProductResponse.getOutCount()) { + buffer.append(invProductResponse.getCpmctymc() + "," + + invProductResponse.getNameCode() + "," + + invProductResponse.getBatchNo() + "," + + invProductResponse.getSupName() + "," + + invProductResponse.getDeptName() + "," + + invProductResponse.getInvCode() + "\n"); + } + }); + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return buffer.toString(); + } + } + return buffer.toString(); + } + + public String downloadPreInInv() { + int page = 1; + int limit = 100; + StringBuffer buffer = new StringBuffer(); + while (true) { + BaseResponse> baseResponse = spGetHttpClient.getInvData(page, limit); + if (baseResponse.getCode() == 20000) { + List list = baseResponse.getData().getList(); + list.forEach(invProductResponse -> { + InvPreinProductEntity invProductEntity = invPreinProductService.selectByUnique(Long.getLong(invProductResponse.getRelIdFk()), invProductResponse.getBatchNo(), invProductResponse.getSupId(), invProductResponse.getDeptCode(), invProductResponse.getInvCode()); + if (invProductEntity.getInCount() != invProductResponse.getInCount() || invProductEntity.getOutCount() != invProductResponse.getOutCount()) { + buffer.append(invProductResponse.getCpmctymc() + "," + + invProductResponse.getNameCode() + "," + + invProductResponse.getBatchNo() + "," + + invProductResponse.getSupName() + "," + + invProductResponse.getDeptName() + "," + + invProductResponse.getInvCode() + "\n"); + } + }); + if (list.size() >= limit) { + page++; + } else { + break; + } + } else { + return buffer.toString(); + } + } + return buffer.toString(); + } + +}