zhouzh 3 лет назад
Родитель
Сommit
cb82bbfc38

+ 28 - 25
src/main/java/com/steerinfo/dil/controller/WmspInventoryCloseController.java

@@ -11,12 +11,17 @@ import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.*;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author luobang
@@ -43,35 +48,33 @@ public class WmspInventoryCloseController extends BaseRESTfulController {
                                                Integer apiId,
                                                Integer pageNum,
                                                Integer pageSize,
-                                               String  con){
-            if(con != null){
-                if(!"undefined".equals(con)){
-                    String index = "get_wms_InventoryClose";
-                    return success(esFeign.getConResult(mapValue,index,apiId,pageNum,pageSize,con));
-                }
-            }
-            List<Map<String,Object>>inventoryCloseList = null;
-            if(mapValue.size() == 0){
-                //将查询结果存入索引中
-                inventoryCloseList = wmspInventoryCloseServiceImpl.getWmspInventoryClose(mapValue);
-                Map<String, Object> inventoryCloseMap = new HashMap<>();
-                //添加索引
-                inventoryCloseMap.put("index","get_wms_InventoryClose");
-                //添加ID
-                inventoryCloseMap.put("indexId","inventoryCloseId");
-                inventoryCloseList.add(inventoryCloseMap);
-                //新建索引
-                esFeign.insertIndex(inventoryCloseList);
-                //删除
-                inventoryCloseList.remove(inventoryCloseList.size() -1);
-            }
-            if(inventoryCloseList == null) {
-                inventoryCloseList = wmspInventoryCloseServiceImpl.getWmspInventoryClose(mapValue);
+                                               Integer warehouseId,
+                                               String  value){
+            if(mapValue == null){
+                mapValue = new HashMap<>();
             }
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+            String sd = sdf.format(new Date(Long.parseLong(value))); // 时间戳转换日期
+            mapValue.put("warehouseId",warehouseId);
+            mapValue.put("value",sd);
+            List<Map<String,Object>>inventoryCloseList = wmspInventoryCloseServiceImpl.getWmspInventoryClose(mapValue);
             /*分页*/
             PageHelper.startPage(pageNum, pageSize);
             List<Map<String,Object>> columnList = wmspInventoryCloseServiceImpl.getWmspInventoryClose(mapValue);
             PageListAdd pageList = columnDataUtil.tableColumnData(apiId,inventoryCloseList,columnList);
             return success(pageList);
     }
+
+    //库存结转(在每个月的25号11点45时结算一个月的数据)
+    @PostMapping("/addInventoryClose")
+    @Scheduled(cron =  "3 45 23 25 * ? ")
+    @ApiOperation(value = "库存结转")
+    public RESTfulResult addInventoryClose(){
+            int result = 0;
+            int count = wmspInventoryCloseServiceImpl.getClose();
+            if(count == 0) {
+                result = wmspInventoryCloseServiceImpl.addInventoryClose();
+            }
+            return success(result);
+    }
 }

+ 13 - 0
src/main/java/com/steerinfo/dil/mapper/WmspInventoryCloseMapper.java

@@ -3,6 +3,7 @@ package com.steerinfo.dil.mapper;
 import com.steerinfo.dil.model.WmspInventoryClose;
 import com.steerinfo.framework.mapper.IBaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
 
 import java.math.BigDecimal;
 import java.util.List;
@@ -12,4 +13,16 @@ import java.util.Map;
 public interface WmspInventoryCloseMapper extends IBaseMapper<WmspInventoryClose, BigDecimal> {
     List<Map<String, Object>> selectWmspInventoryClose(Map<String, Object> mapValue);
 
+    List<Map<String, Object>> selectSendReceive(BigDecimal warehouseId);
+
+    @Select("select seq_WMSP_INVENTORY_CLOSE.nextval from dual")
+    BigDecimal addInventoryCloseId();
+
+    BigDecimal selectCloseThismonthInbound(BigDecimal warehouseId, BigDecimal materialId);
+
+    BigDecimal selectCloseThismonthOutbound(BigDecimal warehouseId, BigDecimal materialId);
+
+    BigDecimal selectCloseLastmonthInventory(BigDecimal warehouseId, BigDecimal materialId);
+
+    int getClose();
 }

+ 12 - 12
src/main/java/com/steerinfo/dil/model/WmspInventoryClose.java

@@ -37,25 +37,25 @@ public class WmspInventoryClose implements IBasePO<BigDecimal> {
      * 上个月库存(上一个结转周期(每个月25号)留存的库存)(CLOSE_LASTMONTH_INVENTORY,DECIMAL,0)
      */
     @ApiModelProperty(value="上个月库存(上一个结转周期(每个月25号)留存的库存)",required=false)
-    private Short closeLastmonthInventory;
+    private BigDecimal closeLastmonthInventory;
 
     /**
      * 本月入库(生产入库+退货入库+盘盈 = 本月入库)(CLOSE_THISMONTH_INBOUND,DECIMAL,0)
      */
     @ApiModelProperty(value="本月入库(生产入库+退货入库+盘盈 = 本月入库)",required=false)
-    private Short closeThismonthInbound;
+    private BigDecimal closeThismonthInbound;
 
     /**
      * 本月出库(出库+盘亏=本月出库)(CLOSE_THISMONTH_OUTBOUND,DECIMAL,0)
      */
     @ApiModelProperty(value="本月出库(出库+盘亏=本月出库)",required=false)
-    private Short closeThismonthOutbound;
+    private BigDecimal closeThismonthOutbound;
 
     /**
      * 本月库存(上月库存 + 本月入库 — 本月出库 = 本月库存)(CLOSE_THISMONTH_INVENTORY,DECIMAL,0)
      */
     @ApiModelProperty(value="本月库存(上月库存 + 本月入库 — 本月出库 = 本月库存)",required=false)
-    private Short closeThismonthInventory;
+    private BigDecimal closeThismonthInventory;
 
     /**
      * 记录创建人(INSERT_USERNAME,VARCHAR,20)
@@ -137,35 +137,35 @@ public class WmspInventoryClose implements IBasePO<BigDecimal> {
         this.warehouseId = warehouseId;
     }
 
-    public Short getCloseLastmonthInventory() {
+    public BigDecimal getCloseLastmonthInventory() {
         return closeLastmonthInventory;
     }
 
-    public void setCloseLastmonthInventory(Short closeLastmonthInventory) {
+    public void setCloseLastmonthInventory(BigDecimal closeLastmonthInventory) {
         this.closeLastmonthInventory = closeLastmonthInventory;
     }
 
-    public Short getCloseThismonthInbound() {
+    public BigDecimal getCloseThismonthInbound() {
         return closeThismonthInbound;
     }
 
-    public void setCloseThismonthInbound(Short closeThismonthInbound) {
+    public void setCloseThismonthInbound(BigDecimal closeThismonthInbound) {
         this.closeThismonthInbound = closeThismonthInbound;
     }
 
-    public Short getCloseThismonthOutbound() {
+    public BigDecimal getCloseThismonthOutbound() {
         return closeThismonthOutbound;
     }
 
-    public void setCloseThismonthOutbound(Short closeThismonthOutbound) {
+    public void setCloseThismonthOutbound(BigDecimal closeThismonthOutbound) {
         this.closeThismonthOutbound = closeThismonthOutbound;
     }
 
-    public Short getCloseThismonthInventory() {
+    public BigDecimal getCloseThismonthInventory() {
         return closeThismonthInventory;
     }
 
-    public void setCloseThismonthInventory(Short closeThismonthInventory) {
+    public void setCloseThismonthInventory(BigDecimal closeThismonthInventory) {
         this.closeThismonthInventory = closeThismonthInventory;
     }
 

+ 5 - 5
src/main/java/com/steerinfo/dil/service/IWmspInventoryCloseService.java

@@ -16,9 +16,9 @@ public interface IWmspInventoryCloseService {
      */
     public List<Map<String, Object>> getWmspInventoryClose(Map<String, Object> mapValue);
 
-    /**
-     * 主键ID
-     * @return
-     */
-    int count();
+
+
+    int addInventoryClose();
+
+    int getClose();
 }

+ 71 - 2
src/main/java/com/steerinfo/dil/service/impl/WmspInventoryCloseServiceImpl.java

@@ -1,10 +1,15 @@
 package com.steerinfo.dil.service.impl;
 
+import com.steerinfo.dil.mapper.RmsWarehouseMapper;
 import com.steerinfo.dil.mapper.WmspInventoryCloseMapper;
+import com.steerinfo.dil.model.WmspInventoryClose;
 import com.steerinfo.dil.service.IWmspInventoryCloseService;
+import com.steerinfo.dil.util.DataChange;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -18,6 +23,9 @@ public class WmspInventoryCloseServiceImpl implements IWmspInventoryCloseService
     @Autowired
     WmspInventoryCloseMapper wmspInventoryCloseMapper;
 
+    @Autowired
+    RmsWarehouseMapper rmsWarehouseMapper;
+
     @Override
     public List<Map<String, Object>> getWmspInventoryClose(Map<String, Object> mapValue) {
         List<Map<String, Object>> maps = wmspInventoryCloseMapper.selectWmspInventoryClose(mapValue);
@@ -26,7 +34,68 @@ public class WmspInventoryCloseServiceImpl implements IWmspInventoryCloseService
     }
 
     @Override
-    public int count() {
-        return 0;
+    public int addInventoryClose() {
+        int i = 0;
+        //高线库,一棒库,二棒库,配送库
+        List<Map<String, Object>> mapList = rmsWarehouseMapper.getWarehouseName();
+        //遍历四个仓库
+        for(Map<String,Object> map:mapList) {
+            BigDecimal warehouseId = DataChange.dataToBigDecimal(map.get("id"));
+            //先获取收发存中的物资
+            List<Map<String,Object>> materialList = wmspInventoryCloseMapper.selectSendReceive(warehouseId);
+            for(Map<String,Object> map1:materialList){
+                WmspInventoryClose wmspInventoryClose = new WmspInventoryClose();
+                //主键自增
+                BigDecimal inventoryCloseId = wmspInventoryCloseMapper.addInventoryCloseId();
+                wmspInventoryClose.setCloseId(inventoryCloseId);
+                //增加仓库id
+                wmspInventoryClose.setWarehouseId(warehouseId);
+                //增加物资id
+                BigDecimal materialId = DataChange.dataToBigDecimal(map1.get("materialId"));
+                wmspInventoryClose.setMaterialId(materialId);
+                //获取一个仓库中的一种物资一个月之内的入库数据
+                BigDecimal closeThismonthInbound = wmspInventoryCloseMapper.selectCloseThismonthInbound(warehouseId,materialId);
+                if(closeThismonthInbound == null){
+                    wmspInventoryClose.setCloseThismonthInbound(new BigDecimal(0));
+                }else {
+                    wmspInventoryClose.setCloseThismonthInbound(closeThismonthInbound);
+                }
+                BigDecimal closeThismonthInbound1 = wmspInventoryClose.getCloseThismonthInbound();
+                //获取一个仓库的一种物资一个月之内的出库数据
+                BigDecimal closeThismonthOutbound = wmspInventoryCloseMapper.selectCloseThismonthOutbound(warehouseId,materialId);
+                if(closeThismonthOutbound == null){
+                    wmspInventoryClose.setCloseThismonthOutbound(new BigDecimal(0));
+                }else {
+                    wmspInventoryClose.setCloseThismonthOutbound(closeThismonthOutbound);
+                }
+                BigDecimal closeThismonthOutbound1 = wmspInventoryClose.getCloseThismonthOutbound();
+                //获取上一个月的一种物资的库存数据
+                BigDecimal closeLastmonthInventory = wmspInventoryCloseMapper.selectCloseLastmonthInventory(warehouseId,materialId);
+                if(closeLastmonthInventory==null){
+                    wmspInventoryClose.setCloseLastmonthInventory(new BigDecimal(0));
+                }else {
+                    wmspInventoryClose.setCloseLastmonthInventory(closeLastmonthInventory);
+                }
+                //获取一个仓库的一种物资一个月之内的总库存数据
+                BigDecimal closeLastmonthInventory1 = wmspInventoryClose.getCloseLastmonthInventory();
+                    BigDecimal closeThismonthInventory =
+                            new BigDecimal(closeThismonthInbound1.intValue() - closeThismonthOutbound1.intValue() + closeLastmonthInventory1.intValue());
+
+                    wmspInventoryClose.setCloseThismonthInventory(closeThismonthInventory);
+
+                wmspInventoryClose.setInsertTime(new Date());
+                wmspInventoryClose.setInsertUsername("admin");
+                wmspInventoryClose.setDeleted(new BigDecimal(1));
+                i+=wmspInventoryCloseMapper.insertSelective(wmspInventoryClose);
+            }
+
+        }
+        return i;
     }
+
+    @Override
+    public int getClose() {
+        return wmspInventoryCloseMapper.getClose();
+    }
+
 }

+ 18 - 5
src/main/java/com/steerinfo/dil/service/impl/WmspSendReceiveServiceImpl.java

@@ -189,10 +189,20 @@ public class WmspSendReceiveServiceImpl implements IWmspSendReceiveService {
                 map2.put("materialId",materialId);
                 //统计今天的入库总数(只统计当前仓库没有预留的数量,不统计预留库的数量)
                 BigDecimal sendReceiveThisdayInbound = wmspSendReceiveMapper.countSndReceiveThisdayInbound(map2);
-                wmspSendReceive.setSendReceiveThisdayInbound(sendReceiveThisdayInbound);
+                if(sendReceiveThisdayInbound == null){
+                    wmspSendReceive.setSendReceiveThisdayInbound(new BigDecimal(0));
+                }else{
+                    wmspSendReceive.setSendReceiveThisdayInbound(sendReceiveThisdayInbound);
+                }
+                BigDecimal sendReceiveThisdayInbound1 = wmspSendReceive.getSendReceiveThisdayInbound();
                 //统计今天天的出库总数
                 BigDecimal sendReceiveThisdayOutbound = wmspSendReceiveMapper.countSendReceiveThisdayOutbound(map2);
-                wmspSendReceive.setSendReceiveThisdayOutbound(sendReceiveThisdayOutbound);
+                if(sendReceiveThisdayOutbound == null){
+                    wmspSendReceive.setSendReceiveThisdayOutbound(new BigDecimal(0));
+                }else {
+                    wmspSendReceive.setSendReceiveThisdayOutbound(sendReceiveThisdayOutbound);
+                }
+                BigDecimal sendReceiveThisdayOutbound1 = wmspSendReceive.getSendReceiveThisdayOutbound();
                 //昨天库存
                 BigDecimal sendReceiveLastdayInventory = wmspSendReceiveMapper.getSendReceiveLastdayInventory(map2);
                 if(sendReceiveLastdayInventory == null){
@@ -200,12 +210,15 @@ public class WmspSendReceiveServiceImpl implements IWmspSendReceiveService {
                 }else{
                     wmspSendReceive.setSendReceiveLastdayInventory(sendReceiveLastdayInventory);
                 }
+
                 BigDecimal sendReceiveLastdayInventory1 = wmspSendReceive.getSendReceiveLastdayInventory();
-                //今天库存
+
+                    //今天库存
                 BigDecimal sendReceiveThisdayInventory = new BigDecimal(sendReceiveLastdayInventory1.intValue()
-                                +sendReceiveThisdayInbound.intValue()-sendReceiveThisdayOutbound.intValue());
+                                +sendReceiveThisdayInbound1.intValue()-sendReceiveThisdayOutbound1.intValue());
+
+                    wmspSendReceive.setSendReceiveThisdayInventory(sendReceiveThisdayInventory);
 
-                wmspSendReceive.setSendReceiveThisdayInventory(sendReceiveThisdayInventory);
                 wmspSendReceive.setInsertUsername("admin");
                 wmspSendReceive.setInsertTime(new Date());
                 wmspSendReceive.setDeleted(new BigDecimal(1));

+ 51 - 16
src/main/resources/com/steerinfo/dil/mapper/WmspInventoryCloseMapper.xml

@@ -447,22 +447,23 @@
   <!-- 请将自己写的代码放在此标签之下,方便以后粘贴复制。-->
   <select id="selectWmspInventoryClose" resultType="java.util.LinkedHashMap">
     select
-rw.warehouse_name "warehouse_name",
-rm.material_name "material_name",
-wpic.close_lastmonth_inventory "close_lastmonth_inventory",
-wpic.close_thismonth_inbound "close_thismonth_inbound",
-wpic.close_thismonth_outbound "close_thismonth_outbound",
-wpic.close_thismonth_inventory "close_thismonth_inventory"
-from
-wmsp_inventory_close wpic
-join rms_material rm
-on rm.material_id=wpic.material_id
-join rms_warehouse rw
-on rw.warehouse_id=wpic.warehouse_id
-join rms_material_type rmt
-on rmt.material_type_id=rm.material_type_id
-join rms_warehouse_type rwt
-on rwt.warehouse_type_id=rw.warehouse_type_id
+          rw.warehouse_name "warehouse_name",
+          rm.material_name "material_name",
+          wpic.close_lastmonth_inventory "close_lastmonth_inventory",
+          wpic.close_thismonth_inbound "close_thismonth_inbound",
+          wpic.close_thismonth_outbound "close_thismonth_outbound",
+          wpic.close_thismonth_inventory "close_thismonth_inventory"
+   from
+          wmsp_inventory_close wpic
+  join rms_material rm
+  on rm.material_id=wpic.material_id
+  join rms_warehouse rw
+  on rw.warehouse_id=wpic.warehouse_id
+  where wpic.WAREHOUSE_ID = #{warehouseId}
+    <if test="value!=null">
+      and #{value}= to_char(wpic.INSERT_TIME,'yyyy-mm')
+    </if>
+
     <where>
       <if test="warehouse_name != null">
         and "warehouse_name" in
@@ -511,4 +512,38 @@ on rwt.warehouse_type_id=rw.warehouse_type_id
       </if>
     </if>
   </sql>
+
+  <select id="selectSendReceive" resultType="java.util.Map" parameterType="java.math.BigDecimal">
+     select distinct wsr.MATERIAL_ID "materialId"
+     from WMSP_SEND_RECEIVE wsr
+     left join RMS_WAREHOUSE rw
+     on wsr.WAREHOUSE_ID = rw.WAREHOUSE_ID
+     where wsr.WAREHOUSE_ID = #{warehouseId}
+    and wsr.INSERT_TIME BETWEEN add_months(sysdate,-1) and sysdate
+  </select>
+
+  <select id="selectCloseThismonthInbound" resultType="java.math.BigDecimal" parameterType="java.math.BigDecimal">
+    select sum(wsr.SEND_RECEIVE_THISDAY_INBOUND)
+    from WMSP_SEND_RECEIVE wsr
+    where wsr.MATERIAL_ID = #{materialId} and wsr.WAREHOUSE_ID = #{warehouseId}
+     and wsr.INSERT_TIME BETWEEN add_months(sysdate,-1) and sysdate
+  </select>
+
+  <select id="selectCloseThismonthOutbound" resultType="java.math.BigDecimal" parameterType="java.math.BigDecimal">
+    select sum(wsr.SEND_RECEIVE_THISDAY_OUTBOUND)
+    from WMSP_SEND_RECEIVE wsr
+    where wsr.MATERIAL_ID = #{materialId} and wsr.WAREHOUSE_ID = #{warehouseId}
+     and wsr.INSERT_TIME BETWEEN add_months(sysdate,-1) and sysdate
+  </select>
+
+  <select id="selectCloseLastmonthInventory" resultType="java.math.BigDecimal" parameterType="java.math.BigDecimal">
+    select sum(wic.CLOSE_THISMONTH_INVENTORY)
+    from WMSP_INVENTORY_CLOSE wic
+    where wic.MATERIAL_ID = #{materialId} and wic.WAREHOUSE_ID = #{warehouseId}
+        and wic.INSERT_TIME BETWEEN add_months(sysdate,-2) and sysdate
+  </select>
+
+  <select id="getClose" resultType="int">
+    select count(*) from WMSP_INVENTORY_CLOSE where  to_char(insert_time,'YYYY-MM-DD')=TO_CHAR(SYSDATE,'YYYY-MM-DD')
+  </select>
 </mapper>