From c58b3e345dcc7c83f776e3da9bd0db7ef7b32caf Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@63.com> Date: 星期三, 24 十一月 2021 09:04:56 +0800 Subject: [PATCH] # --- /dev/null | 20 ------ src/main/java/zy/cloud/wms/common/service/task/DiffValScheduler.java | 106 +++++++++++++++++++++++++++++++++++ src/main/java/zy/cloud/wms/common/model/MatnrDto0.java | 15 +++++ 3 files changed, 120 insertions(+), 21 deletions(-) diff --git a/src/main/java/diffVal.sql b/src/main/java/diffVal.sql deleted file mode 100644 index 9c33de3..0000000 --- a/src/main/java/diffVal.sql +++ /dev/null @@ -1,20 +0,0 @@ --- save diffVal record --- mysql -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal/diffVal.html', 'diffVal绠$悊', null , '2', null , '1'); - -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#view', '鏌ヨ', '', '3', '0', '1'); -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#btn-add', '鏂板', '', '3', '1', '1'); -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#btn-edit', '缂栬緫', '', '3', '2', '1'); -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#btn-delete', '鍒犻櫎', '', '3', '3', '1'); -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#btn-export', '瀵煎嚭', '', '3', '4', '1'); -insert into `sys_resource` ( `code`, `name`, `resource_id`, `level`, `sort`, `status`) values ( 'diffVal#btn-into', '瀵煎叆', '', '3', '5', '1'); - --- sqlserver -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal/diffVal.html', N'diffVal绠$悊', null, '2', null, '1'); - -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#view', N'鏌ヨ', '', '3', '0', '1'); -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#btn-add', N'鏂板', '', '3', '1', '1'); -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#btn-edit', N'缂栬緫', '', '3', '2', '1'); -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#btn-delete', N'鍒犻櫎', '', '3', '3', '1'); -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#btn-export', N'瀵煎嚭', '', '3', '4', '1'); -insert [dbo].[sys_resource] ( [code], [name], [resource_id], [level], [sort], [status]) values ( N'diffVal#btn-into', N'瀵煎叆', '', '3', '5', '1'); diff --git a/src/main/java/zy/cloud/wms/common/model/MatnrDto0.java b/src/main/java/zy/cloud/wms/common/model/MatnrDto0.java new file mode 100644 index 0000000..0f24317 --- /dev/null +++ b/src/main/java/zy/cloud/wms/common/model/MatnrDto0.java @@ -0,0 +1,15 @@ +package zy.cloud.wms.common.model; + +import lombok.Data; + +/** + * Created by vincent on 2021/3/31 + */ +@Data +public class MatnrDto0 { + + private String PUserCode; + + private Double Qty; + +} diff --git a/src/main/java/zy/cloud/wms/common/service/task/DiffValScheduler.java b/src/main/java/zy/cloud/wms/common/service/task/DiffValScheduler.java index 839fafe..78a6df5 100644 --- a/src/main/java/zy/cloud/wms/common/service/task/DiffValScheduler.java +++ b/src/main/java/zy/cloud/wms/common/service/task/DiffValScheduler.java @@ -1,12 +1,26 @@ package zy.cloud.wms.common.service.task; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.core.common.Arith; +import com.core.common.Cools; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RestController; +import zy.cloud.wms.common.model.MatnrDto; +import zy.cloud.wms.common.model.MatnrDto0; +import zy.cloud.wms.common.service.erp.ErpScheduler; +import zy.cloud.wms.common.service.erp.Result; +import zy.cloud.wms.common.service.erp.entity.GetBasisResult; +import zy.cloud.wms.manager.entity.DiffVal; import zy.cloud.wms.manager.service.DiffValService; +import zy.cloud.wms.manager.utils.HttpHandler; + +import java.util.*; /** * Created by vincent on 2021/11/23 @@ -17,10 +31,100 @@ @Autowired private DiffValService diffValService; + @Autowired + private JdbcTemplate jdbcTemplate; @Transactional - @Scheduled(cron = "0/10 * * * * ? ") + @Scheduled(cron = "0 */10 * * * ?") public void run() { + List<MatnrDto0> erpQtyList = null; + Date now = new Date(); + try { + Map<String, Object> param = new HashMap<>(); + param.put("PUserCode", "N"); + param.put("KUserCode", "N"); + String response = new HttpHandler.Builder() + .setUri("http://123.60.34.127:6220/api") + .setPath(ErpScheduler.GET_STOCK) + .setJson(JSON.toJSONString(param)) + .build() + .doPost(); + if (!Cools.isEmpty(response)) { + log.info(response); + Result result = JSON.parseObject(response, Result.class); + if (result.getCode() != 1) { + return; + } + erpQtyList = JSON.parseArray(result.getData(), MatnrDto0.class); + } + } catch (Exception e) { + e.printStackTrace(); + } + if (Cools.isEmpty(erpQtyList)) { + log.error("鑾峰彇EPR搴撳瓨澶辫触"); + return; + } + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select sum(a.anfme) as count, a.matnr from (\n" + + "\tselect\n" + + "\tsum(anfme) as anfme,\n" + + "\tmatnr\n" + + "\tfrom asr_loc_detl\n" + + "\tgroup by matnr\n" + + "\tunion all\n" + + "\tselect\n" + + "\tsum(anfme) as anfme,\n" + + "\tmatnr\n" + + "\tfrom man_loc_detl\n" + + "\tgroup by matnr\n" + + ") as a\n" + + "where 1=1\n" + + "group by a.matnr"); + List<MatnrDto> stockQtyList = new ArrayList<>(); + for (Map<String, Object> map : maps) { + stockQtyList.add(Cools.conver(map, MatnrDto.class)); + } + + for (MatnrDto item : stockQtyList) { + DiffVal diffVal = diffValService.selectById(item.getMatnr()); + if (diffVal == null) { + diffVal = new DiffVal( + item.getMatnr(), // 鐗╂枡缂栧彿[闈炵┖] + item.getCount(), // WMS搴撳瓨 + 0.0D, // ERP搴撳瓨 + item.getCount(), // 宸紓鍊� + now, // 鏇存柊鏃堕棿 + null // 澶囨敞 + ); + diffValService.insert(diffVal); + } else { + diffVal.setStockQty(item.getCount()); + double erpQty = diffVal.getErpQty(); + diffVal.setVal(Arith.subtract(2, diffVal.getStockQty(), erpQty)); + diffVal.setUpdateTime(now); + diffValService.updateById(diffVal); + } + } + + for (MatnrDto0 item : erpQtyList) { + DiffVal diffVal = diffValService.selectById(item.getPUserCode()); + if (diffVal == null) { + diffVal = new DiffVal( + item.getPUserCode(), // 鐗╂枡缂栧彿[闈炵┖] + 0.0D, // WMS搴撳瓨 + item.getQty(), // ERP搴撳瓨 + -item.getQty(), // 宸紓鍊� + now, // 鏇存柊鏃堕棿 + null // 澶囨敞 + ); + diffValService.insert(diffVal); + } else { + diffVal.setErpQty(item.getQty()); + double stockQty = diffVal.getStockQty(); + diffVal.setVal(Arith.subtract(2, stockQty, diffVal.getErpQty())); + diffVal.setUpdateTime(now); + diffValService.updateById(diffVal); + } + } } -- Gitblit v1.9.1