New file |
| | |
| | | package zy.cloud.wms.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.plugins.Page; |
| | | import com.core.annotations.ManagerAuth; |
| | | import com.core.common.Cools; |
| | | import com.core.common.R; |
| | | import com.core.common.SnowflakeIdWorker; |
| | | import com.core.exception.CoolException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import zy.cloud.wms.common.model.BillDto; |
| | | import zy.cloud.wms.common.service.erp.ErpService; |
| | | import zy.cloud.wms.common.web.BaseController; |
| | | import zy.cloud.wms.manager.entity.LocSum; |
| | | import zy.cloud.wms.manager.entity.Pakout; |
| | | import zy.cloud.wms.manager.entity.WrkLocSync; |
| | | import zy.cloud.wms.manager.service.LocSyncService; |
| | | import zy.cloud.wms.manager.service.PakoutService; |
| | | import zy.cloud.wms.manager.service.WrkLocSyncService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @Slf4j |
| | | public class LocSyncController extends BaseController { |
| | | @Autowired |
| | | private LocSyncService locSyncService; |
| | | @Autowired |
| | | private WrkLocSyncService wrkLocSyncService; |
| | | @Autowired |
| | | private ErpService erpService; |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | | |
| | | @RequestMapping(value = "/locSync/queryLocSum") |
| | | @ManagerAuth(memo = "获取总库存清单") |
| | | public R queryLocSum() { |
| | | return R.ok(locSyncService.queryLocSum()); |
| | | } |
| | | |
| | | @RequestMapping(value = "/locSync/syncLocWrkCount") |
| | | @ManagerAuth(memo = "获取库存同步上传清单数量") |
| | | public R getSyncLocWrkCount() { |
| | | return R.ok(wrkLocSyncService.getSyncLocWrkCount()); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/locSync/insertWrklocSync") |
| | | @ManagerAuth(memo = "同步上传清单数据插入") |
| | | public R insertWrklocSync(@RequestBody JSONObject param) { |
| | | List<WrkLocSync> list = JSONObject.parseArray(param.getJSONArray("list").toJSONString(), WrkLocSync.class); |
| | | // 插入创建人员和创建时间 |
| | | if (list.size() > 0) { |
| | | for (WrkLocSync elist : list) { |
| | | elist.setCreateBy(getUserId()); |
| | | elist.setCreateTime(new Date()); |
| | | } |
| | | } |
| | | Integer result = 0; |
| | | result = wrkLocSyncService.insertWrkLocSync(list); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/locSync/updateWrklocSync") |
| | | @ManagerAuth(memo = "清空同步上传清单数据,并插入") |
| | | public R updateWrklocSync(@RequestBody JSONObject param) { |
| | | // 清空同步上传清单数据 |
| | | if (!wrkLocSyncService.clearWrkLocSync()) { |
| | | throw new CoolException("同步上传清单数据清空失败,请联系管理员"); |
| | | } |
| | | ; |
| | | List<WrkLocSync> list = JSONObject.parseArray(param.getJSONArray("list").toJSONString(), WrkLocSync.class); |
| | | // 插入创建人员和创建时间 |
| | | if (list.size() > 0) { |
| | | for (WrkLocSync elist : list) { |
| | | elist.setCreateBy(getUserId()); |
| | | elist.setCreateTime(new Date()); |
| | | } |
| | | } |
| | | Integer result = 0; |
| | | result = wrkLocSyncService.insertWrkLocSync(list); |
| | | return R.ok(result); |
| | | } |
| | | |
| | | /* 同步上传erp[uploadBill] 单据上传 */ |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | public void execute() { |
| | | List<String> orderList = new ArrayList<>(); |
| | | orderList.add("state"); |
| | | orderList.add("create_time"); |
| | | List<WrkLocSync> syncList = wrkLocSyncService.selectList(new EntityWrapper<WrkLocSync>().orderDesc(orderList)); |
| | | // 同步上传清单处理,取第一条 |
| | | if (!Cools.isEmpty(syncList)) { |
| | | WrkLocSync executeData = syncList.get(0); |
| | | // 订单号 |
| | | String docNum = String.valueOf(snowflakeIdWorker.nextId()); |
| | | // 订单类型 34采购单 |
| | | Integer docId = 34; |
| | | List<BillDto> dtos = new ArrayList<BillDto>(); |
| | | BillDto res = new BillDto(); |
| | | res.setMatnr(executeData.getMatnr()); |
| | | res.setQty(executeData.getQty()); |
| | | dtos.add(res); |
| | | if (erpService.uploadBill(dtos, docId, docNum)) { |
| | | // 成功后删除任务 |
| | | if (!wrkLocSyncService.delete(new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) { |
| | | log.info("库存同步删除任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date()); |
| | | } |
| | | } else { |
| | | // 失败后将任务状态state更新为N |
| | | executeData.setState("X"); |
| | | executeData.setUpdateBy(getUserId()); |
| | | executeData.setCreateTime(new Date()); |
| | | if(!wrkLocSyncService.update(executeData, new EntityWrapper<WrkLocSync>().eq("matnr", executeData.getMatnr()))) { |
| | | log.info("库存同步更新任务失败,任务matnr=" + executeData.getMatnr() + "时间=" + new Date()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | @TableName("asr_sumloc_view") |
| | | @Data |
| | | public class LocSum implements Serializable { |
| | | private String matnr; |
| | | |
| | | private String maktx; |
| | | |
| | | private Double anfme; |
| | | |
| | | private String altme; |
| | | |
| | | private String memo; |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotations.TableField; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import lombok.Data; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | @TableName("asr_wrk_loc_sync") |
| | | @Data |
| | | public class WrkLocSync implements Serializable { |
| | | private String matnr; |
| | | |
| | | private Double qty; |
| | | |
| | | private String state; |
| | | |
| | | @TableField("create_time") |
| | | private Date createTime; |
| | | |
| | | @TableField("create_by") |
| | | private Long createBy; |
| | | |
| | | @TableField("update_time") |
| | | private Date updateTime; |
| | | |
| | | @TableField("update_by") |
| | | private Long updateBy; |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | import zy.cloud.wms.manager.entity.LocSum; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface LocSyncMapper extends BaseMapper<LocSum> { |
| | | List<LocSum> queryLocSum(); |
| | | |
| | | Integer getSyncLocWrkCount(); |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.BaseMapper; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.springframework.stereotype.Repository; |
| | | import zy.cloud.wms.manager.entity.WrkLocSync; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Mapper |
| | | @Repository |
| | | public interface WrkLocSyncMapper extends BaseMapper<WrkLocSync> { |
| | | Integer getSyncLocWrkCount(); |
| | | |
| | | Integer insertWrkLocSync(List<WrkLocSync> list); |
| | | |
| | | Boolean clearWrkLocSync(); |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.service; |
| | | |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | import zy.cloud.wms.manager.entity.LocSum; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface LocSyncService extends IService<LocSum> { |
| | | List<LocSum> queryLocSum(); |
| | | |
| | | Integer getSyncLocWrkCount(); |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.service; |
| | | |
| | | import com.baomidou.mybatisplus.service.IService; |
| | | import zy.cloud.wms.manager.entity.WrkLocSync; |
| | | import java.util.List; |
| | | |
| | | public interface WrkLocSyncService extends IService<WrkLocSync> { |
| | | Integer getSyncLocWrkCount(); |
| | | |
| | | Integer insertWrkLocSync(List<WrkLocSync> list); |
| | | |
| | | Boolean clearWrkLocSync(); |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import zy.cloud.wms.manager.mapper.LocSyncMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import zy.cloud.wms.manager.entity.LocSum; |
| | | import zy.cloud.wms.manager.service.LocSyncService; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service("locSyncService") |
| | | public class LocSyncServiceImpl extends ServiceImpl<LocSyncMapper, LocSum> implements LocSyncService{ |
| | | |
| | | @Override |
| | | public List<LocSum> queryLocSum() { |
| | | return this.baseMapper.queryLocSum(); |
| | | } |
| | | |
| | | @Override |
| | | public Integer getSyncLocWrkCount() { |
| | | return this.baseMapper.getSyncLocWrkCount(); |
| | | } |
| | | } |
New file |
| | |
| | | package zy.cloud.wms.manager.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | import zy.cloud.wms.manager.entity.WrkLocSync; |
| | | import zy.cloud.wms.manager.mapper.WrkLocSyncMapper; |
| | | import zy.cloud.wms.manager.service.WrkLocSyncService; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service("wrkLocSyncService") |
| | | public class WrkLocSyncServiceImpl extends ServiceImpl<WrkLocSyncMapper, WrkLocSync> implements WrkLocSyncService { |
| | | @Override |
| | | public Integer getSyncLocWrkCount() { |
| | | return this.baseMapper.getSyncLocWrkCount(); |
| | | } |
| | | |
| | | @Override |
| | | public Integer insertWrkLocSync(List<WrkLocSync> list) { |
| | | return this.baseMapper.insertWrkLocSync(list); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean clearWrkLocSync() { |
| | | return this.baseMapper.clearWrkLocSync(); |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="zy.cloud.wms.manager.mapper.LocSyncMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="zy.cloud.wms.manager.entity.LocSum"> |
| | | <result column="matnr" property="matnr" /> |
| | | <result column="maktx" property="maktx" /> |
| | | <result column="anfme" property="anfme" /> |
| | | <result column="altme" property="altme" /> |
| | | <result column="memo" property="memo" /> |
| | | </resultMap> |
| | | |
| | | <select id="queryLocSum" resultMap="BaseResultMap"> |
| | | select matnr,maktx,sum(anfme) as anfme,altme, memo from asr_sumloc_view group by matnr,maktx,altme,memo |
| | | </select> |
| | | |
| | | <select id="getSyncLocWrkCount" resultType="integer"> |
| | | select count(*) from asr_wrk_loc_sync; |
| | | </select> |
| | | |
| | | |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="zy.cloud.wms.manager.mapper.WrkLocSyncMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="zy.cloud.wms.manager.entity.WrkLocSync"> |
| | | <result column="matnr" property="matnr" /> |
| | | <result column="qty" property="qty" /> |
| | | <result column="state" property="state" /> |
| | | <result column="create_by" property="createBy" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_by" property="updateBy" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | </resultMap> |
| | | |
| | | <select id="getSyncLocWrkCount" resultType="integer"> |
| | | select count(*) from asr_wrk_loc_sync; |
| | | </select> |
| | | |
| | | <insert id="insertWrkLocSync"> |
| | | BEGIN |
| | | <foreach collection="list" item="item" index="index"> |
| | | INSERT INTO asr_wrk_loc_sync (matnr, qty, state, create_time, create_by, update_time, update_by) |
| | | VALUES (#{item.matnr,jdbcType=VARCHAR}, #{item.qty,jdbcType=DECIMAL}, 'N', |
| | | #{item.createTime,jdbcType=TIMESTAMP},#{item.createBy,jdbcType=DECIMAL}, |
| | | #{item.updateTime,jdbcType=TIMESTAMP}, #{item.updateBy,jdbcType=DECIMAL}) |
| | | </foreach> |
| | | END; |
| | | </insert> |
| | | |
| | | <delete id="clearWrkLocSync"> |
| | | DELETE FROM asr_wrk_loc_sync |
| | | </delete> |
| | | </mapper> |
New file |
| | |
| | | var syncTableData = []; |
| | | |
| | | layui.use(['table', 'laydate', 'form'], function () { |
| | | var table = layui.table; |
| | | var $ = layui.jquery; |
| | | var layer = layui.layer; |
| | | var layDate = layui.laydate; |
| | | var form = layui.form; |
| | | |
| | | |
| | | // 数据渲染 |
| | | tableIns = table.render({ |
| | | elem: '#locSum', |
| | | headers: {token: localStorage.getItem('token')}, |
| | | url: baseUrl + '/locSync/queryLocSum', |
| | | page: true, |
| | | // limit: 16, |
| | | // limits: [16, 30, 50, 100, 200, 500], |
| | | even: true, |
| | | toolbar: '#toolbar', |
| | | cellMinWidth: 50, |
| | | cols: [[ |
| | | {field: 'matnr', align: 'center', title: '物料编码', width: 200} |
| | | , {field: 'maktx', align: 'center', title: '物料名称'} |
| | | , {field: 'anfme', align: 'center', title: '总数量[平仓+立库]', width: 180} |
| | | , {field: 'altme', align: 'center', title: '单位', width: 80} |
| | | , {field: 'memo', align: 'center', title: '备注'} |
| | | ]], |
| | | request: { |
| | | pageName: 'curr', |
| | | pageSize: 'limit' |
| | | }, |
| | | parseData: function (res) { |
| | | return { |
| | | 'code': res.code, |
| | | 'msg': res.msg, |
| | | 'count': res.data.total, |
| | | 'data': res.data |
| | | } |
| | | }, |
| | | response: { |
| | | statusCode: 200 |
| | | }, |
| | | done: function (res, curr, count) { |
| | | if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } |
| | | pageCurr = curr; |
| | | limit(); |
| | | syncTableData = res.data; |
| | | } |
| | | }); |
| | | |
| | | // 监听头工具栏事件 |
| | | table.on('toolbar(locSum)', function (obj) { |
| | | switch (obj.event) { |
| | | case 'btnSync': |
| | | $.ajax({ |
| | | url: baseUrl + "/locSync/syncLocWrkCount", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: {}, |
| | | method: 'POST', |
| | | traditional: true, |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | var msg = ''; |
| | | if (res.data == 0) { |
| | | msg = '确定要同步库存数据吗?' |
| | | } else { |
| | | msg = '同步任务正在进行,确定要中止并重新同步吗?' |
| | | } |
| | | layer.confirm(msg, { |
| | | shadeClose: true |
| | | , btn: ['确定'] |
| | | }, function () { |
| | | var paramList = []; |
| | | syncTableData.map(function (e) { |
| | | paramList.push({ |
| | | matnr: e.matnr, |
| | | qty: e.anfme, |
| | | }); |
| | | }); |
| | | var param = { |
| | | 'list': paramList, |
| | | }; |
| | | if (res.data > 0) { |
| | | // 清空同步上传清单数据,再进行插入数据 |
| | | $.ajax({ |
| | | url: baseUrl + "/locSync/updateWrklocSync", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify(param), |
| | | dataType: 'json', |
| | | contentType: 'application/json;charset=UTF-8', |
| | | method: 'POST', |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | layer.msg("库存同步中!"); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }); |
| | | } else { |
| | | // 调用同步上传清单数据插入接口 |
| | | $.ajax({ |
| | | url: baseUrl + "/locSync/insertWrklocSync", |
| | | headers: {'token': localStorage.getItem('token')}, |
| | | data: JSON.stringify(param), |
| | | dataType: 'json', |
| | | contentType: 'application/json;charset=UTF-8', |
| | | method: 'POST', |
| | | success: function (res) { |
| | | if (res.code === 200) { |
| | | layer.msg("库存同步中!"); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | layer.closeAll(); |
| | | } |
| | | ); |
| | | } else if (res.code === 403) { |
| | | top.location.href = baseUrl + "/"; |
| | | } else { |
| | | layer.msg(res.msg) |
| | | } |
| | | } |
| | | }); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | }); |
| | | }); |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html lang="en"> |
| | | <head> |
| | | <meta charset="UTF-8"> |
| | | <title></title> |
| | | <meta name="renderer" content="webkit"> |
| | | <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> |
| | | <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/cool.css" media="all"> |
| | | <link rel="stylesheet" href="../../static/css/common.css" media="all"> |
| | | <style> |
| | | |
| | | </style> |
| | | </head> |
| | | <body> |
| | | |
| | | <div class="layui-fluid"> |
| | | <!-- 表格 --> |
| | | <div class="layui-form"> |
| | | <table class="layui-hide" id="locSum" lay-filter="locSum"></table> |
| | | </div> |
| | | </div> |
| | | |
| | | <script type="text/html" id="toolbar"> |
| | | <div class="layui-btn-container"> |
| | | <button class="layui-btn " id="btn-sync" lay-event="btnSync" style="margin-left: 10px">同步库存</button> |
| | | </div> |
| | | </script> |
| | | <script type="text/javascript" src="../../static/js/jquery/jquery-3.3.1.min.js"></script> |
| | | <script type="text/javascript" src="../../static/layui/layui.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/common.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/cool.js" charset="utf-8"></script> |
| | | <script type="text/javascript" src="../../static/js/locSync/locSync.js" charset="utf-8"></script> |
| | | </body> |
| | | </html> |
New file |
| | |
| | | // 新建视图 asr_sumloc_view |
| | | select matnr,maktx,anfme, altme, memo from asr_loc_detl |
| | | union all |
| | | select matnr,maktx,anfme, unit as altme, memo from man_loc_detl |
| | | |
| | | // 新增表结构 |
| | | SET ANSI_NULLS ON |
| | | GO |
| | | |
| | | SET QUOTED_IDENTIFIER ON |
| | | GO |
| | | |
| | | SET ANSI_PADDING ON |
| | | GO |
| | | |
| | | CREATE TABLE [dbo].[asr_wrk_loc_sync]( |
| | | [matnr] [varchar](255) NOT NULL, |
| | | [qty] [decimal](24, 9) NOT NULL, |
| | | [state] [varchar](10) NULL, |
| | | [create_time] [datetime] NULL, |
| | | [create_by] [bigint] NULL, |
| | | [update_time] [datetime] NULL, |
| | | [update_by] [bigint] NULL |
| | | ) ON [PRIMARY] |
| | | |
| | | GO |
| | | |
| | | SET ANSI_PADDING OFF |
| | | GO |
| | | |
| | | EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'物料编码' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'asr_wrk_loc_sync', @level2type=N'COLUMN',@level2name=N'matnr' |
| | | GO |
| | | |
| | | EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'数量' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'asr_wrk_loc_sync', @level2type=N'COLUMN',@level2name=N'qty' |
| | | GO |
| | | |
| | | EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'状态(N未上传,X上传失败)' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'asr_wrk_loc_sync', @level2type=N'COLUMN',@level2name=N'state' |
| | | GO |