Browse Source

Merge remote-tracking branch 'origin/master_huangjunjie'

# Conflicts:
#	src/main/java/com/jsh/erp/service/DepotHeadService.java
#	src/main/java/com/jsh/erp/service/MaterialService.java
#	src/main/java/com/jsh/erp/service/impl/DepotHeadServiceImpl.java
#	src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java
#	src/main/resources/mapper_xml/MaterialMapperEx.xml
13660505945 1 month ago
parent
commit
1c6e3ec30e

+ 9 - 0
src/main/java/com/jsh/erp/controller/MaterialController.java

@@ -919,5 +919,14 @@ public class MaterialController extends BaseController {
         return res;
     }
 
+    @GetMapping(value = "/getMaterialWarn")
+    @ApiOperation(value = "获取商品提醒")
+    public BaseResponseInfo getMaterialWarn()throws Exception {
+        BaseResponseInfo res = new BaseResponseInfo();
+        res.code = 200;
+        res.data = materialService.getMaterialWarn();
+        return res;
+    }
+
 
 }

+ 1 - 0
src/main/java/com/jsh/erp/datasource/entities/Material.java

@@ -5,6 +5,7 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 /**

+ 8 - 0
src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapper.java

@@ -38,4 +38,12 @@ public interface DepotHeadMapper extends BaseMapperX<DepotHead> {
     int updateByPrimaryKeySelective(DepotHead record);
 
     int updateByPrimaryKey(DepotHead record);
+
+    /**
+     * 根据商品id获取最后一条销售订单
+     * @param id 商品id
+     * @return
+     */
+    DepotHead getDepotLastByMaterialId(long id);
+
 }

+ 3 - 1
src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapper.java

@@ -3,9 +3,11 @@ package com.jsh.erp.datasource.mappers;
 import com.jsh.erp.datasource.entities.MaterialCurrentStock;
 import com.jsh.erp.datasource.entities.MaterialCurrentStockExample;
 import java.util.List;
+
+import com.jsh.erp.datasource.entities.MaterialInitialStock;
 import org.apache.ibatis.annotations.Param;
 
-public interface MaterialCurrentStockMapper {
+public interface MaterialCurrentStockMapper extends BaseMapperX<MaterialCurrentStock> {
     long countByExample(MaterialCurrentStockExample example);
 
     int deleteByExample(MaterialCurrentStockExample example);

+ 11 - 1
src/main/java/com/jsh/erp/datasource/mappers/MaterialExtendMapper.java

@@ -1,8 +1,9 @@
 package com.jsh.erp.datasource.mappers;
 
-import com.jsh.erp.datasource.entities.Material;
 import com.jsh.erp.datasource.entities.MaterialExtend;
 import com.jsh.erp.datasource.entities.MaterialExtendExample;
+
+import java.math.BigDecimal;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
@@ -42,4 +43,13 @@ public interface MaterialExtendMapper extends BaseMapperX<MaterialExtend>{
      */
     MaterialExtend selectByBatchNumber(@Param("batchNumber") String batchNumber);
 
+    /**
+     * 根据仓库id和商品id查询商品库存
+     * @param depotList 仓库id
+     * @param mid   商品id
+     * @return
+     */
+    BigDecimal getInventorySumByDepotAndMid(@Param("depotList") List<Long> depotList,
+                                            @Param("mid") long mid);
+
 }

+ 2 - 1
src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapper.java

@@ -1,11 +1,12 @@
 package com.jsh.erp.datasource.mappers;
 
+import com.jsh.erp.datasource.entities.Material;
 import com.jsh.erp.datasource.entities.MaterialInitialStock;
 import com.jsh.erp.datasource.entities.MaterialInitialStockExample;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
-public interface MaterialInitialStockMapper {
+public interface MaterialInitialStockMapper extends BaseMapperX<MaterialInitialStock> {
     long countByExample(MaterialInitialStockExample example);
 
     int deleteByExample(MaterialInitialStockExample example);

+ 25 - 0
src/main/java/com/jsh/erp/datasource/vo/MaterialWarnListVo.java

@@ -0,0 +1,25 @@
+package com.jsh.erp.datasource.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.util.List;
+
+/**
+ * 商品库存提醒
+ */
+@Data
+@Accessors(chain = true)
+public class MaterialWarnListVo {
+
+    @ApiModelProperty("无动销提醒")
+    private List<String> NoMovingPinReminder;
+
+    @ApiModelProperty("过期提醒")
+    private List<String> expirationReminder;
+
+    @ApiModelProperty("库存提醒")
+    private List<String> inventoryReminder;
+
+}

+ 3 - 1
src/main/java/com/jsh/erp/service/MaterialExtendService.java

@@ -1,6 +1,8 @@
 package com.jsh.erp.service;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.entities.Log;
 import com.jsh.erp.datasource.entities.MaterialExtend;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import org.springframework.transaction.annotation.Transactional;
@@ -8,7 +10,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 
-public interface MaterialExtendService {
+public interface MaterialExtendService extends IService<MaterialExtend> {
     MaterialExtend getMaterialExtend(long id)throws Exception;
 
     List<MaterialExtendVo4List> getDetailList(Long materialId);

+ 7 - 3
src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java

@@ -69,6 +69,8 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
     private MaterialCurrentStockMapperEx materialCurrentStockMapperEx;
     @Resource
     private LogService logService;
+    @Resource
+    private MaterialExtendMapper materialExtendMapper;
 
     /**
      * pda根据订单信息查询商品列表
@@ -1109,6 +1111,8 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
         BigDecimal stockCheckSum = depotItemMapperEx.getStockCheckSumByDepotList(depotList, mId, forceFlag, beginTime, endTime);
         DepotItemVo4Stock stockObj = depotItemMapperEx.getStockByParamWithDepotList(depotList, mId, forceFlag, inOutManageFlag, beginTime, endTime);
         BigDecimal stockSum = BigDecimal.ZERO;
+        //获取商品子表单的库存总数
+        BigDecimal inventory = materialExtendMapper.getInventorySumByDepotAndMid(depotList,mId);
         if(stockObj!=null) {
             BigDecimal inTotal = stockObj.getInTotal();
             BigDecimal transfInTotal = stockObj.getTransfInTotal();
@@ -1121,7 +1125,7 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
             stockSum = inTotal.add(transfInTotal).add(assemInTotal).add(disAssemInTotal)
                     .subtract(outTotal).subtract(transfOutTotal).subtract(assemOutTotal).subtract(disAssemOutTotal);
         }
-        return initStock.add(stockCheckSum).add(stockSum);
+        return initStock.add(stockCheckSum).add(inventory).add(stockSum);
     }
 
     /**
@@ -1255,9 +1259,9 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
     public void updateCurrentStockFun(Long mId, Long dId) throws Exception {
         if(mId!=null && dId!=null) {
             MaterialCurrentStockExample example = new MaterialCurrentStockExample();
-            //条件添加商品id,仓库id ,删除状态
+            //条件 添加商品id,仓库id ,删除状态
             example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
-                    .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+                    .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_EXISTS);
             //获取商品当前库存信息
             List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
             MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();

+ 49 - 3
src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java

@@ -6,15 +6,15 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.constants.BusinessConstants;
 import com.jsh.erp.constants.ExceptionConstants;
-import com.jsh.erp.datasource.entities.MaterialExtend;
-import com.jsh.erp.datasource.entities.MaterialExtendExample;
-import com.jsh.erp.datasource.entities.User;
+import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.mappers.MaterialCurrentStockMapper;
 import com.jsh.erp.datasource.mappers.MaterialExtendMapper;
 import com.jsh.erp.datasource.mappers.MaterialExtendMapperEx;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.service.MaterialExtendService;
+import com.jsh.erp.service.MaterialService;
 import com.jsh.erp.service.RedisService;
 import com.jsh.erp.service.UserService;
 import com.jsh.erp.utils.DateUtils;
@@ -29,6 +29,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -43,10 +44,15 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     @Resource
     private MaterialExtendMapperEx materialExtendMapperEx;
     @Resource
+    private MaterialCurrentStockMapper materialCurrentStockMapper;
+    @Resource
     private UserService userService;
     @Resource
     private RedisService redisService;
 
+    @Resource
+    private MaterialService materialService;
+
     @Override
     public MaterialExtend getMaterialExtend(long id)throws Exception {
         MaterialExtend result=null;
@@ -276,9 +282,14 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         int result = 0;
         try{
             result= materialExtendMapper.insertSelective(materialExtend);
+
         }catch(Exception e){
             JshException.writeFail(logger, e);
         }
+        //修改当前库存
+        if (materialExtend.getDepotId() != null && materialExtend.getInventory() != null){
+            insertCurrentStockByMaterialAndDepot(materialExtend.getDepotId(),materialExtend.getMaterialId(),materialExtend.getInventory(),"add");
+        }
         return result;
     }
 
@@ -479,6 +490,41 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     }
 
     /**
+     * 设置当前库存
+     * @param depotId 仓库id
+     * @param mId   商品id
+     * @param stock 库存数量
+     */
+    /**
+     * 设置当前库存
+     * @param depotId 仓库id
+     * @param mId 商品id
+     * @param stock 库存数量
+     * @param type  加减操作 add|subtract
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public void insertCurrentStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock,String type){
+        //查询当前商品当前库存
+        BigDecimal currentNumber = materialService.getCurrentStockByMaterialIdAndDepotId(mId,depotId);
+        MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
+        materialCurrentStock.setDepotId(depotId);
+        materialCurrentStock.setMaterialId(mId);
+        materialCurrentStock.setCurrentNumber(stock);
+        if (currentNumber == null || currentNumber.compareTo(BigDecimal.ZERO) == 0){
+            materialCurrentStockMapper.insertSelective(materialCurrentStock); //存入当前库存
+        }else {
+            BigDecimal sumNumber = new BigDecimal("0");
+            if ("add".equals(type)){
+                sumNumber = currentNumber.add(materialCurrentStock.getCurrentNumber());
+            }else if ("subtract".equals(type)){
+                sumNumber = currentNumber.subtract(materialCurrentStock.getCurrentNumber());
+            }
+            materialCurrentStock.setCurrentNumber(sumNumber);
+            materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
+        }
+    }
+
+    /**
      * 将Json对象的数据赋值到商品拓展对象中
      * @param tempJson
      * @param materialExtend

+ 10 - 0
src/main/resources/mapper_xml/DepotHeadMapper.xml

@@ -702,4 +702,14 @@
     </where>
       GROUP BY dh.id
   </select>
+
+  <select id="getDepotLastByMaterialId" resultType="com.jsh.erp.datasource.entities.DepotHead">
+    SELECT dh.* FROM jsh_depot_item di
+    LEFT JOIN jsh_depot_head dh ON di.header_id = dh.id
+    WHERE di.material_id = #{id}
+    AND dh.type = '出库'
+    AND ifnull(dh.delete_flag,'0') != '1'
+    ORDER BY dh.oper_time DESC LIMIT 1
+  </select>
+
 </mapper>

+ 1 - 0
src/main/resources/mapper_xml/DepotHeadMapperEx.xml

@@ -1418,4 +1418,5 @@
         and dh.pay_type = '预付款'
         and ifnull(dh.delete_flag,'0') !='1'
     </select>
+
 </mapper>

+ 13 - 0
src/main/resources/mapper_xml/MaterialExtendMapper.xml

@@ -471,4 +471,17 @@
     <include refid="Base_Column_List" />
     from jsh_material_extend WHERE batch_number = #{batchNumber}
   </select>
+
+  <select id="getInventorySumByDepotAndMid"  resultType="java.math.BigDecimal">
+    select ifnull(sum(me.inventory),0) inventory from jsh_material_extend me
+    where me.material_id = #{mid}
+    <if test="depotList.size()>0">
+      and me.depot_id in
+      <foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
+        #{item}
+      </foreach>
+    </if>
+    AND ifnull(me.delete_Flag,'0') !='1'
+  </select>
+
 </mapper>

+ 5 - 38
src/main/resources/mapper_xml/MaterialMapper.xml

@@ -130,22 +130,22 @@
 
   <insert id="insert" parameterType="com.jsh.erp.datasource.entities.Material">
     insert into jsh_material (id, category_id, name, 
-      mfrs, model, standard, 
+      model, standard,
       brand, mnemonic, color, 
       unit, remark, img_name, 
       unit_id, expiry_num, weight, 
       enabled, other_field1, other_field2, 
       other_field3, enable_serial_number, enable_batch_number, 
-      position, tenant_id, delete_flag
+       tenant_id, delete_flag
       )
     values (#{id,jdbcType=BIGINT}, #{categoryId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, 
-      #{mfrs,jdbcType=VARCHAR}, #{model,jdbcType=VARCHAR}, #{standard,jdbcType=VARCHAR}, 
+      #{model,jdbcType=VARCHAR}, #{standard,jdbcType=VARCHAR},
       #{brand,jdbcType=VARCHAR}, #{mnemonic,jdbcType=VARCHAR}, #{color,jdbcType=VARCHAR}, 
       #{unit,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{imgName,jdbcType=VARCHAR}, 
-      #{unitId,jdbcType=BIGINT}, #{expiryNum,jdbcType=INTEGER}, #{weight,jdbcType=DECIMAL}, 
+      #{unitId,jdbcType=BIGINT}, #{weight,jdbcType=DECIMAL},
       #{enabled,jdbcType=BIT}, #{otherField1,jdbcType=VARCHAR}, #{otherField2,jdbcType=VARCHAR}, 
       #{otherField3,jdbcType=VARCHAR}, #{enableSerialNumber,jdbcType=VARCHAR}, #{enableBatchNumber,jdbcType=VARCHAR}, 
-      #{position,jdbcType=VARCHAR}, #{tenantId,jdbcType=BIGINT}, #{deleteFlag,jdbcType=VARCHAR}
+      #{tenantId,jdbcType=BIGINT}, #{deleteFlag,jdbcType=VARCHAR}
       )
   </insert>
 
@@ -161,9 +161,6 @@
       <if test="name != null">
         name,
       </if>
-      <if test="mfrs != null">
-        mfrs,
-      </if>
       <if test="model != null">
         model,
       </if>
@@ -191,9 +188,6 @@
       <if test="unitId != null">
         unit_id,
       </if>
-      <if test="expiryNum != null">
-        expiry_num,
-      </if>
       <if test="weight != null">
         weight,
       </if>
@@ -215,9 +209,6 @@
       <if test="enableBatchNumber != null">
         enable_batch_number,
       </if>
-      <if test="position != null">
-        position,
-      </if>
       <if test="tenantId != null">
         tenant_id,
       </if>
@@ -235,9 +226,6 @@
       <if test="name != null">
         #{name,jdbcType=VARCHAR},
       </if>
-      <if test="mfrs != null">
-        #{mfrs,jdbcType=VARCHAR},
-      </if>
       <if test="model != null">
         #{model,jdbcType=VARCHAR},
       </if>
@@ -265,9 +253,6 @@
       <if test="unitId != null">
         #{unitId,jdbcType=BIGINT},
       </if>
-      <if test="expiryNum != null">
-        #{expiryNum,jdbcType=INTEGER},
-      </if>
       <if test="weight != null">
         #{weight,jdbcType=DECIMAL},
       </if>
@@ -289,9 +274,6 @@
       <if test="enableBatchNumber != null">
         #{enableBatchNumber,jdbcType=VARCHAR},
       </if>
-      <if test="position != null">
-        #{position,jdbcType=VARCHAR},
-      </if>
       <if test="tenantId != null">
         #{tenantId,jdbcType=BIGINT},
       </if>
@@ -320,9 +302,6 @@
       <if test="record.name != null">
         name = #{record.name,jdbcType=VARCHAR},
       </if>
-      <if test="record.mfrs != null">
-        mfrs = #{record.mfrs,jdbcType=VARCHAR},
-      </if>
       <if test="record.model != null">
         model = #{record.model,jdbcType=VARCHAR},
       </if>
@@ -350,9 +329,6 @@
       <if test="record.unitId != null">
         unit_id = #{record.unitId,jdbcType=BIGINT},
       </if>
-      <if test="record.expiryNum != null">
-        expiry_num = #{record.expiryNum,jdbcType=INTEGER},
-      </if>
       <if test="record.weight != null">
         weight = #{record.weight,jdbcType=DECIMAL},
       </if>
@@ -374,9 +350,6 @@
       <if test="record.enableBatchNumber != null">
         enable_batch_number = #{record.enableBatchNumber,jdbcType=VARCHAR},
       </if>
-      <if test="record.position != null">
-        position = #{record.position,jdbcType=VARCHAR},
-      </if>
       <if test="record.tenantId != null">
         tenant_id = #{record.tenantId,jdbcType=BIGINT},
       </if>
@@ -394,7 +367,6 @@
     set id = #{record.id,jdbcType=BIGINT},
       category_id = #{record.categoryId,jdbcType=BIGINT},
       name = #{record.name,jdbcType=VARCHAR},
-      mfrs = #{record.mfrs,jdbcType=VARCHAR},
       model = #{record.model,jdbcType=VARCHAR},
       standard = #{record.standard,jdbcType=VARCHAR},
       brand = #{record.brand,jdbcType=VARCHAR},
@@ -404,7 +376,6 @@
       remark = #{record.remark,jdbcType=VARCHAR},
       img_name = #{record.imgName,jdbcType=VARCHAR},
       unit_id = #{record.unitId,jdbcType=BIGINT},
-      expiry_num = #{record.expiryNum,jdbcType=INTEGER},
       weight = #{record.weight,jdbcType=DECIMAL},
       enabled = #{record.enabled,jdbcType=BIT},
       other_field1 = #{record.otherField1,jdbcType=VARCHAR},
@@ -412,7 +383,6 @@
       other_field3 = #{record.otherField3,jdbcType=VARCHAR},
       enable_serial_number = #{record.enableSerialNumber,jdbcType=VARCHAR},
       enable_batch_number = #{record.enableBatchNumber,jdbcType=VARCHAR},
-      position = #{record.position,jdbcType=VARCHAR},
       tenant_id = #{record.tenantId,jdbcType=BIGINT},
       delete_flag = #{record.deleteFlag,jdbcType=VARCHAR}
     <if test="_parameter != null">
@@ -497,7 +467,6 @@
     update jsh_material
     set category_id = #{categoryId,jdbcType=BIGINT},
       name = #{name,jdbcType=VARCHAR},
-      mfrs = #{mfrs,jdbcType=VARCHAR},
       model = #{model,jdbcType=VARCHAR},
       standard = #{standard,jdbcType=VARCHAR},
       brand = #{brand,jdbcType=VARCHAR},
@@ -507,7 +476,6 @@
       remark = #{remark,jdbcType=VARCHAR},
       img_name = #{imgName,jdbcType=VARCHAR},
       unit_id = #{unitId,jdbcType=BIGINT},
-      expiry_num = #{expiryNum,jdbcType=INTEGER},
       weight = #{weight,jdbcType=DECIMAL},
       enabled = #{enabled,jdbcType=BIT},
       other_field1 = #{otherField1,jdbcType=VARCHAR},
@@ -515,7 +483,6 @@
       other_field3 = #{otherField3,jdbcType=VARCHAR},
       enable_serial_number = #{enableSerialNumber,jdbcType=VARCHAR},
       enable_batch_number = #{enableBatchNumber,jdbcType=VARCHAR},
-      position = #{position,jdbcType=VARCHAR},
       tenant_id = #{tenantId,jdbcType=BIGINT},
       delete_flag = #{deleteFlag,jdbcType=VARCHAR}
     where id = #{id,jdbcType=BIGINT}