Browse Source

pda订单提交,修改库存

huang 1 month ago
parent
commit
086f5091c0
27 changed files with 575 additions and 317 deletions
  1. 1 0
      src/main/java/com/jsh/erp/controller/MaterialCategoryController.java
  2. 2 1
      src/main/java/com/jsh/erp/controller/MaterialExtendController.java
  3. 13 6
      src/main/java/com/jsh/erp/controller/pda/PdaController.java
  4. 43 0
      src/main/java/com/jsh/erp/datasource/entities/InventoryLog.java
  5. 2 0
      src/main/java/com/jsh/erp/datasource/entities/MaterialCategory.java
  6. 2 0
      src/main/java/com/jsh/erp/datasource/entities/MaterialCurrentStock.java
  7. 3 0
      src/main/java/com/jsh/erp/datasource/entities/MaterialExtend.java
  8. 9 0
      src/main/java/com/jsh/erp/datasource/mappers/InventoryLogMapper.java
  9. 2 1
      src/main/java/com/jsh/erp/datasource/mappers/MaterialCategoryMapper.java
  10. 5 0
      src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java
  11. 5 0
      src/main/java/com/jsh/erp/datasource/pda/vo/PDADepotItemVO.java
  12. 2 0
      src/main/java/com/jsh/erp/datasource/vo/MaterialExtendVo4List.java
  13. 8 0
      src/main/java/com/jsh/erp/service/InventoryLogService.java
  14. 28 266
      src/main/java/com/jsh/erp/service/MaterialCategoryService.java
  15. 5 0
      src/main/java/com/jsh/erp/service/MaterialExtendService.java
  16. 13 0
      src/main/java/com/jsh/erp/service/MaterialService.java
  17. 30 15
      src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java
  18. 12 0
      src/main/java/com/jsh/erp/service/impl/InventoryLogServiceImpl.java
  19. 316 0
      src/main/java/com/jsh/erp/service/impl/MaterialCategoryServiceImpl.java
  20. 29 13
      src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java
  21. 10 2
      src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java
  22. 9 3
      src/main/resources/mapper_xml/DepotItemMapper.xml
  23. 5 0
      src/main/resources/mapper_xml/InventoryLogMapper.xml
  24. 5 6
      src/main/resources/mapper_xml/MaterialCategoryMapper.xml
  25. 3 1
      src/main/resources/mapper_xml/MaterialCategoryMapperEx.xml
  26. 0 3
      src/main/resources/mapper_xml/MaterialExtendMapper.xml
  27. 13 0
      src/main/resources/mapper_xml/MaterialMapperEx.xml

+ 1 - 0
src/main/java/com/jsh/erp/controller/MaterialCategoryController.java

@@ -8,6 +8,7 @@ import com.jsh.erp.base.TableDataInfo;
 import com.jsh.erp.datasource.entities.MaterialCategory;
 import com.jsh.erp.datasource.vo.TreeNode;
 import com.jsh.erp.service.MaterialCategoryService;
+
 import com.jsh.erp.utils.BaseResponseInfo;
 import com.jsh.erp.utils.Constants;
 import com.jsh.erp.utils.ErpInfo;

+ 2 - 1
src/main/java/com/jsh/erp/controller/MaterialExtendController.java

@@ -6,6 +6,7 @@ import com.jsh.erp.datasource.entities.MaterialExtend;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import com.jsh.erp.service.MaterialExtendService;
 import com.jsh.erp.utils.BaseResponseInfo;
+import com.jsh.erp.utils.DateUtils;
 import com.jsh.erp.utils.ErpInfo;
 import com.jsh.erp.utils.StringUtil;
 import io.swagger.annotations.Api;
@@ -108,7 +109,7 @@ public class MaterialExtendController {
                     item.put("commodityDecimal", md.getCommodityDecimal());
                     item.put("wholesaleDecimal", md.getWholesaleDecimal());
                     item.put("lowDecimal", md.getLowDecimal());
-                    item.put("productionDate",md.getProductionDate());
+                    item.put("productionDate", DateUtils.dateTime(md.getProductionDate()));
                     item.put("expiryNum",md.getExpiryNum());
                     item.put("supplierId",md.getSupplierId());
                     item.put("barCode",md.getBarCode());

+ 13 - 6
src/main/java/com/jsh/erp/controller/pda/PdaController.java

@@ -5,14 +5,13 @@ import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
 import com.jsh.erp.datasource.entities.DepotHead;
+import com.jsh.erp.datasource.entities.MaterialVo4Unit;
 import com.jsh.erp.datasource.entities.Supplier;
 import com.jsh.erp.datasource.pda.dto.PDADepotHeadDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotHeadVO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.query.LambdaQueryWrapperX;
-import com.jsh.erp.service.DepotHeadService;
-import com.jsh.erp.service.DepotItemService;
-import com.jsh.erp.service.SupplierService;
+import com.jsh.erp.service.*;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
@@ -35,6 +34,9 @@ public class PdaController extends BaseController {
     @Resource
     private SupplierService supplierService;
 
+    @Resource
+    private MaterialService materialService;
+
     /**
      * 采购入库
      * @return
@@ -105,9 +107,6 @@ public class PdaController extends BaseController {
         return AjaxResult.success();
     }
 
-    /**
-     * PDA订单提交
-     */
     @PostMapping ("/orderSubmit")
     @ApiOperation(value = "订单提交")
     public AjaxResult orderSubmit(@RequestBody PDADepotHeadDTO pdaDepotHeadDTO) {
@@ -120,4 +119,12 @@ public class PdaController extends BaseController {
         return AjaxResult.success();
     }
 
+    @ApiOperation("商品存货查询")
+    @GetMapping("/inventoryInquiry/{type}/{keyword}")
+    public TableDataInfo inventoryInquiry(@PathVariable("type") String type,@PathVariable("keyword") String keyword){
+        startPage();
+        List<PDADepotItemVO> list = materialService.inventoryInquiry(type , keyword);
+        return getDataTable(list);
+    }
+
 }

+ 43 - 0
src/main/java/com/jsh/erp/datasource/entities/InventoryLog.java

@@ -0,0 +1,43 @@
+package com.jsh.erp.datasource.entities;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * 商品库存修改日志表实体类
+ */
+@Data
+@TableName("jsh_inventory_log")
+public class InventoryLog {
+
+    @ApiModelProperty("主键id")
+    private Long id;
+
+    @ApiModelProperty("单据主表id")
+    private Long depotHeadId;
+
+    @ApiModelProperty("单据子表id")
+    private Long depotItemId;
+
+    @ApiModelProperty("商品id")
+    private Long materialId;
+
+    @ApiModelProperty("商品子表id")
+    private Long materialExtendId;
+
+    @ApiModelProperty("原始库存")
+    private Integer originalStock;
+
+    @ApiModelProperty("当前库存")
+    private Integer currentStock;
+
+    @ApiModelProperty("更新时间")
+    private Date updateTime;
+
+    @ApiModelProperty("更新用户")
+    private Long updateUser;
+
+}

+ 2 - 0
src/main/java/com/jsh/erp/datasource/entities/MaterialCategory.java

@@ -1,5 +1,6 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
@@ -10,6 +11,7 @@ import java.util.Date;
  */
 @Data
 @Accessors(chain = true)
+@TableName("jsh_material_category")
 public class MaterialCategory {
 
     private Long id;

+ 2 - 0
src/main/java/com/jsh/erp/datasource/entities/MaterialCurrentStock.java

@@ -1,5 +1,6 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.experimental.Accessors;
 
@@ -10,6 +11,7 @@ import java.math.BigDecimal;
  */
 @Data
 @Accessors(chain = true)
+@TableName("jsh_material_current_stock")
 public class MaterialCurrentStock {
     private Long id;
 

+ 3 - 0
src/main/java/com/jsh/erp/datasource/entities/MaterialExtend.java

@@ -1,6 +1,7 @@
 package com.jsh.erp.datasource.entities;
 
 import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
@@ -42,6 +43,7 @@ public class MaterialExtend {
     private String defaultFlag;
 
     @ApiModelProperty("创建日期")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
     @ApiModelProperty("创建人编码")
@@ -60,6 +62,7 @@ public class MaterialExtend {
     private String deleteFlag;
 
     @ApiModelProperty("生产日期")
+    @JsonFormat(pattern = "yyyy-MM-dd")
     private Date productionDate;
 
     @ApiModelProperty("保质期天数")

+ 9 - 0
src/main/java/com/jsh/erp/datasource/mappers/InventoryLogMapper.java

@@ -0,0 +1,9 @@
+package com.jsh.erp.datasource.mappers;
+
+import com.jsh.erp.datasource.entities.InventoryLog;
+
+public interface InventoryLogMapper extends BaseMapperX<InventoryLog> {
+
+
+
+}

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

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

+ 5 - 0
src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java

@@ -1,6 +1,7 @@
 package com.jsh.erp.datasource.mappers;
 
 import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
 import org.apache.ibatis.annotations.Param;
 
@@ -161,4 +162,8 @@ public interface MaterialMapperEx {
     List<MaterialVo4Unit> getMaterialByBatchNumber(@Param("batchNumberArray") String [] batchNumberArray);
 
     List<MaterialVo4Unit> getMaterialBySystemSku(@Param("systemSkuArray") String [] systemSkuArray);
+
+    List<PDADepotItemVO> inventoryInquiry();
+
+
 }

+ 5 - 0
src/main/java/com/jsh/erp/datasource/pda/vo/PDADepotItemVO.java

@@ -61,4 +61,9 @@ public class PDADepotItemVO{
 
     @ApiModelProperty("实际出入库数量")
     private String actualQuantityInStorage;
+
+    @ApiModelProperty("图片名称")
+    private String imgName;
+
+
 }

+ 2 - 0
src/main/java/com/jsh/erp/datasource/vo/MaterialExtendVo4List.java

@@ -1,9 +1,11 @@
 package com.jsh.erp.datasource.vo;
 
 import com.jsh.erp.datasource.entities.MaterialExtend;
+import lombok.Data;
 
 import java.math.BigDecimal;
 
+@Data
 public class MaterialExtendVo4List extends MaterialExtend {
 
     private String supplier;

+ 8 - 0
src/main/java/com/jsh/erp/service/InventoryLogService.java

@@ -0,0 +1,8 @@
+package com.jsh.erp.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.entities.InventoryLog;
+
+public interface InventoryLogService extends IService<InventoryLog> {
+
+}

+ 28 - 266
src/main/java/com/jsh/erp/service/MaterialCategoryService.java

@@ -1,301 +1,63 @@
 package com.jsh.erp.service;
 
 import com.alibaba.fastjson.JSONObject;
-import com.jsh.erp.constants.BusinessConstants;
-import com.jsh.erp.constants.ExceptionConstants;
-import com.jsh.erp.datasource.entities.Material;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.MaterialCategory;
-import com.jsh.erp.datasource.entities.MaterialCategoryExample;
-import com.jsh.erp.datasource.entities.User;
-import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
-import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
-import com.jsh.erp.datasource.mappers.MaterialMapperEx;
 import com.jsh.erp.datasource.vo.TreeNode;
-import com.jsh.erp.exception.BusinessRunTimeException;
-import com.jsh.erp.exception.JshException;
-import com.jsh.erp.utils.PageUtils;
-import com.jsh.erp.utils.StringUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
 
-import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
-@Service
-public class MaterialCategoryService {
-    private Logger logger = LoggerFactory.getLogger(MaterialCategoryService.class);
+public interface MaterialCategoryService extends IService<MaterialCategory> {
 
-    @Resource
-    private MaterialCategoryMapper materialCategoryMapper;
-    @Resource
-    private MaterialCategoryMapperEx materialCategoryMapperEx;
-    @Resource
-    private UserService userService;
-    @Resource
-    private LogService logService;
-    @Resource
-    private MaterialMapperEx materialMapperEx;
 
-    public MaterialCategory getMaterialCategory(long id)throws Exception {
-        MaterialCategory result=null;
-        try{
-            result=materialCategoryMapper.selectByPrimaryKey(id);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return result;
-    }
+    MaterialCategory getMaterialCategory(long id)throws Exception;
 
-    public List<MaterialCategory> getMaterialCategoryListByIds(String ids)throws Exception {
-        List<Long> idList = StringUtil.strToLongList(ids);
-        List<MaterialCategory> list = new ArrayList<>();
-        try{
-            MaterialCategoryExample example = new MaterialCategoryExample();
-            example.createCriteria().andIdIn(idList);
-            list = materialCategoryMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+    List<MaterialCategory> getMaterialCategoryListByIds(String ids)throws Exception;
 
-    public List<MaterialCategory> getMaterialCategory()throws Exception {
-        MaterialCategoryExample example = new MaterialCategoryExample();
-        List<MaterialCategory> list=null;
-        try{
-            list=materialCategoryMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+    List<MaterialCategory> getMaterialCategory()throws Exception;
 
-    public List<MaterialCategory> getAllList(Long parentId)throws Exception {
-        List<MaterialCategory> list=null;
-        try{
-            list = getMCList(parentId);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+    List<MaterialCategory> getAllList(Long parentId)throws Exception;
 
-    public List<MaterialCategory> getMCList(Long parentId)throws Exception {
-        List<MaterialCategory> res= new ArrayList<MaterialCategory>();
-        List<MaterialCategory> list=null;
-        MaterialCategoryExample example = new MaterialCategoryExample();
-        example.createCriteria().andParentIdEqualTo(parentId).andIdNotEqualTo(1L);
-        example.setOrderByClause("id");
-        list=materialCategoryMapper.selectByExample(example);
-        if(list!=null && list.size()>0) {
-            res.addAll(list);
-            for(MaterialCategory mc : list) {
-                List<MaterialCategory> mcList = getMCList(mc.getId());
-                if(mcList!=null && mcList.size()>0) {
-                    res.addAll(mcList);
-                }
-            }
-        }
-        return res;
-    }
+    List<MaterialCategory> getMCList(Long parentId)throws Exception;
 
-    public List<MaterialCategory> select(String name, Integer parentId) throws Exception{
-        List<MaterialCategory> list=null;
-        try{
-            PageUtils.startPage();
-            list=materialCategoryMapperEx.selectByConditionMaterialCategory(name, parentId);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
+    List<MaterialCategory> select(String name, Integer parentId) throws Exception;
 
+    /**
+     * 新增商品类别
+     * @param obj 商品类别数据
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int insertMaterialCategory(JSONObject obj, HttpServletRequest request)throws Exception {
-        MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
-        materialCategory.setCreateTime(new Date());
-        materialCategory.setUpdateTime(new Date());
-        materialCategory.setSerialNo(materialCategoryMapper.selectMaxId()+10001);
-        int result=0;
-        try{
-            result=materialCategoryMapper.insertSelective(materialCategory);
-            logService.insertLog("商品类型",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialCategory.getName()).toString(), request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    int insertMaterialCategory(JSONObject obj, HttpServletRequest request)throws Exception;
 
+    /**
+     * 修改商品类别
+     * @param obj 商品类别数据
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int updateMaterialCategory(JSONObject obj, HttpServletRequest request) throws Exception{
-        MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
-        materialCategory.setUpdateTime(new Date());
-        int result=0;
-        try{
-            result=materialCategoryMapperEx.editMaterialCategory(materialCategory);
-            logService.insertLog("商品类型",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialCategory.getName()).toString(), request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    int updateMaterialCategory(JSONObject obj, HttpServletRequest request) throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int deleteMaterialCategory(Long id, HttpServletRequest request)throws Exception {
-        return batchDeleteMaterialCategoryByIds(id.toString());
-    }
+    int deleteMaterialCategory(Long id, HttpServletRequest request)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteMaterialCategory(String ids, HttpServletRequest request)throws Exception {
-        return batchDeleteMaterialCategoryByIds(ids);
-    }
+    int batchDeleteMaterialCategory(String ids, HttpServletRequest request)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteMaterialCategoryByIds(String ids) throws Exception {
-        int result=0;
-        String [] idArray=ids.split(",");
-        //校验产品表	jsh_material
-        List<Material> materialList=null;
-        try{
-            materialList= materialMapperEx.getMaterialListByCategoryIds(idArray);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        if(materialList!=null&&materialList.size()>0){
-            logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
-            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
-                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
-        }
-        StringBuffer sb = new StringBuffer();
-        sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
-        List<MaterialCategory> list = getMaterialCategoryListByIds(ids);
-        for(MaterialCategory materialCategory: list){
-            sb.append("[").append(materialCategory.getName()).append("]");
-        }
-        logService.insertLog("商品类型", sb.toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        //更新时间
-        Date updateDate =new Date();
-        //更新人
-        User userInfo=userService.getCurrentUser();
-        Long updater=userInfo==null?null:userInfo.getId();
-        String strArray[]=ids.split(",");
-        if(strArray.length<1){
-            return 0;
-        }
-        List<MaterialCategory> mcList = materialCategoryMapperEx.getMaterialCategoryListByCategoryIds(idArray);
-        if(mcList!=null && mcList.size()>0) {
-            logger.error("异常码[{}],异常提示[{}]",
-                    ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_CODE,ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_MSG);
-            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_CODE,
-                    ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_MSG);
-        } else {
-            result=materialCategoryMapperEx.batchDeleteMaterialCategoryByIds(updateDate,updater,strArray);
-        }
-        return result;
-    }
+    int batchDeleteMaterialCategoryByIds(String ids) throws Exception;
 
-    public int checkIsNameExist(Long id, String name)throws Exception {
-        MaterialCategoryExample example = new MaterialCategoryExample();
-        example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<MaterialCategory> list=null;
-        try{
-            list= materialCategoryMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list==null?0:list.size();
-    }
+    int checkIsNameExist(Long id, String name)throws Exception;
 
-    public List<MaterialCategory> findById(Long id)throws Exception {
-        List<MaterialCategory> list=null;
-        if(id!=null) {
-            MaterialCategoryExample example = new MaterialCategoryExample();
-            example.createCriteria().andIdEqualTo(id);
-            try{
-                list=materialCategoryMapper.selectByExample(example);
-            }catch(Exception e){
-                JshException.readFail(logger, e);
-            }
-        }
-        return list;
-    }
-    /**
-     * description:
-     * 获取商品类别树数据
-     */
-    public List<TreeNode> getMaterialCategoryTree(Long id) throws Exception{
-        List<TreeNode> list=null;
-        try{
-            list=materialCategoryMapperEx.getNodeTree(id);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-       return list;
-    }
-    /**
-     * 根据商品类别编号判断商品类别是否已存在
-     * */
-    public void  checkMaterialCategorySerialNo(MaterialCategory mc)throws Exception {
-        if(mc==null){
-            return;
-        }
-        if( mc.getSerialNo() < 0){
-            return;
-        }
-        //根据商品类别编号查询商品类别
-        List<MaterialCategory> mList=null;
-        try{
-            mList= materialCategoryMapperEx.getMaterialCategoryBySerialNo(mc.getSerialNo(), mc.getId());
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        if(mList==null||mList.size()<1){
-            //未查询到对应数据,编号可用
-            return;
-        }
-        if(mList.size()>1){
-            //查询到的数据条数大于1,编号已存在
-            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
-                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
-        }
-        if(mc.getId()==null){
-            //新增时,编号已存在
-            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
-                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
-        }
-        /**
-         * 包装类型用equals来比较
-         * */
-        if(mc.getId().equals(mList.get(0).getId())){
-            //修改时,相同编号,id不同
-            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
-                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
-        }
-    }
+    List<MaterialCategory> findById(Long id)throws Exception;
+
+    List<TreeNode> getMaterialCategoryTree(Long id) throws Exception;
+
+    void  checkMaterialCategorySerialNo(MaterialCategory mc)throws Exception;
 
     /**
      * 根据名称获取类型
      * @param name
      */
-    public Long getCategoryIdByName(String name){
-        Long categoryId = null;
-        MaterialCategoryExample example = new MaterialCategoryExample();
-        example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<MaterialCategory> list = materialCategoryMapper.selectByExample(example);
-        if(list!=null && list.size()>0) {
-            categoryId = list.get(0).getId();
-        }
-        return categoryId;
-    }
+    Long getCategoryIdByName(String name);
 }

+ 5 - 0
src/main/java/com/jsh/erp/service/MaterialExtendService.java

@@ -54,4 +54,9 @@ public interface MaterialExtendService extends IService<MaterialExtend> {
     int getCountByManyBarCodeWithoutUs(String manyBarCode, String barCode);
 
     MaterialExtend getInfoByBatchNumber(String batchNumber)throws Exception;
+
+    /**
+     * 修改子商品库存
+     */
+    void updateInventory(Long depotHeadId, Long depotItemId,MaterialExtend materialExtend) throws Exception;
 }

+ 13 - 0
src/main/java/com/jsh/erp/service/MaterialService.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.entities.*;
+import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.vo.MaterialWarnListVo;
 import com.jsh.erp.utils.BaseResponseInfo;
 import org.springframework.transaction.annotation.Transactional;
@@ -36,6 +37,10 @@ public interface MaterialService extends IService<Material> {
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int insertMaterial(JSONObject obj, HttpServletRequest request)throws Exception;
 
+    /**
+     * 修改商品
+     * @param obj
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int updateMaterial(JSONObject obj, HttpServletRequest request) throws Exception;
 
@@ -177,4 +182,12 @@ public interface MaterialService extends IService<Material> {
 
     //导入表格
     BaseResponseInfo importExcelTwo(MultipartFile file, HttpServletRequest request) throws Exception;
+
+    /**
+     * PDA库存查询
+     * @param type 库存类别 有/无/全部
+     * @param keyword 关键字
+     * @return
+     */
+    List<PDADepotItemVO> inventoryInquiry(String type,String keyword);
 }

+ 30 - 15
src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java

@@ -751,6 +751,15 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
                         }
                     }
                 }
+                if(BusinessConstants.DEPOTHEAD_TYPE_IN.equals(depotHead.getType())){
+                    //表单入库,修改商品库存
+                    materialExtend.setInventory(materialExtend.getInventory().add(depotItem.getBasicNumber()));
+                    materialExtendService.updateInventory(depotHead.getId(),depotItem.getId(),materialExtend);
+                }else if(BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType())){
+                    //表单入库,修改商品库存
+                    materialExtend.setInventory(materialExtend.getInventory().subtract(depotItem.getBasicNumber()));
+                    materialExtendService.updateInventory(depotHead.getId(),depotItem.getId(),materialExtend);
+                }
                 this.insertDepotItemWithObj(depotItem);
                 //更新当前库存
                 updateCurrentStock(depotItem);
@@ -801,7 +810,6 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
             for (DepotItemXsddRequestVO item : itemList) {
                 DepotItem depotItem = new DepotItem();
                 BeanUtils.copyProperties(item, depotItem);
-
                 // 以下进行单位换算
                 Unit unitInfo = materialService.findUnit(depotItem.getMaterialId()); // 查询多单位信息
                 if (depotItem.getOperNumber() != null) {
@@ -1150,7 +1158,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(inventory).add(stockSum);
+        return initStock.add(stockCheckSum).add(inventory);
     }
 
     /**
@@ -1283,26 +1291,28 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
     @Override
     public void updateCurrentStockFun(Long mId, Long dId) throws Exception {
         if(mId!=null && dId!=null) {
-            MaterialCurrentStockExample example = new MaterialCurrentStockExample();
+//            MaterialCurrentStockExample example = new MaterialCurrentStockExample();
             //条件 添加商品id,仓库id ,删除状态
-            example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
-                    .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_EXISTS);
+//            example.createCriteria().andMaterialIdEqualTo(mId).andDepotIdEqualTo(dId)
+//                    .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
             //获取商品当前库存信息
-            List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
+//            List<MaterialCurrentStock> list = materialCurrentStockMapper.selectByExample(example);
+            //-先清除再插入,防止商品仓库变更,数据对不上
+            materialCurrentStockMapper.delete(new LambdaQueryWrapperX<MaterialCurrentStock>().eq(MaterialCurrentStock::getMaterialId,mId).eqIfPresent(MaterialCurrentStock::getDepotId,dId));
             MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
             materialCurrentStock.setMaterialId(mId);
             materialCurrentStock.setDepotId(dId);
             //设置当前库存数量
             materialCurrentStock.setCurrentNumber(getStockByParam(dId,mId,null,null));
-            if(list!=null && list.size()>0) {
-                //当前库存信息存在,修改当前库存信息
-                Long mcsId = list.get(0).getId();
-                materialCurrentStock.setId(mcsId);
-                materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
-            } else {
+//            if(list!=null && list.size()>0) {
+//                //当前库存信息存在,修改当前库存信息
+//                Long mcsId = list.get(0).getId();
+//                materialCurrentStock.setId(mcsId);
+//                materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
+//            } else {
                 //当前库存信息不存在,新增当前库存信息
                 materialCurrentStockMapper.insertSelective(materialCurrentStock);
-            }
+//            }
         }
     }
 
@@ -1459,7 +1469,8 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
         //根据批次号获取商品数据
         List<MaterialVo4Unit> list = new ArrayList<>();
         if ("XSDD".equals(prefixNo)){ //销售订单导入
-            List<String> strings = Arrays.asList(batchNumbers.replace("^\"|\"$","").split(","));
+            String systemSku = batchNumbers.replace("'","");
+            List<String> strings = Arrays.asList(systemSku.split(","));
             //根据系统sku查询商品
             for (String str : strings) {
                 MaterialVo4Unit materialVo4Unit = depotItemMapperEx.getDepotMaterialBySystemSku(str);
@@ -1473,7 +1484,11 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
         //仓库集合
         Map<String, Long> depotMap = new HashMap<>();
         for (MaterialVo4Unit material: list) {
-            materialMap.put(material.getBatchNumber(), material);
+            if ("XSDD".equals(prefixNo)){
+                materialMap.put(material.getSystemSku(), material);
+            }else {
+                materialMap.put(material.getBatchNumber(), material);
+            }
         }
         //获取当前用户所有仓库
         JSONArray depotArr = depotService.findDepotByCurrentUser();

+ 12 - 0
src/main/java/com/jsh/erp/service/impl/InventoryLogServiceImpl.java

@@ -0,0 +1,12 @@
+package com.jsh.erp.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jsh.erp.datasource.entities.InventoryLog;
+import com.jsh.erp.datasource.mappers.InventoryLogMapper;
+import com.jsh.erp.service.InventoryLogService;
+import org.springframework.stereotype.Service;
+
+@Service
+public class InventoryLogServiceImpl extends ServiceImpl<InventoryLogMapper, InventoryLog> implements InventoryLogService {
+
+}

+ 316 - 0
src/main/java/com/jsh/erp/service/impl/MaterialCategoryServiceImpl.java

@@ -0,0 +1,316 @@
+package com.jsh.erp.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+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.*;
+import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
+import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
+import com.jsh.erp.datasource.mappers.MaterialMapperEx;
+import com.jsh.erp.datasource.vo.TreeNode;
+import com.jsh.erp.exception.BusinessRunTimeException;
+import com.jsh.erp.exception.JshException;
+import com.jsh.erp.service.LogService;
+import com.jsh.erp.service.MaterialCategoryService;
+import com.jsh.erp.service.UserService;
+import com.jsh.erp.utils.PageUtils;
+import com.jsh.erp.utils.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class MaterialCategoryServiceImpl extends ServiceImpl<MaterialCategoryMapper, MaterialCategory> implements MaterialCategoryService {
+    private Logger logger = LoggerFactory.getLogger(MaterialCategoryServiceImpl.class);
+
+    @Resource
+    private MaterialCategoryMapper materialCategoryMapper;
+    @Resource
+    private MaterialCategoryMapperEx materialCategoryMapperEx;
+    @Resource
+    private UserService userService;
+    @Resource
+    private LogService logService;
+    @Resource
+    private MaterialMapperEx materialMapperEx;
+
+    @Override
+    public MaterialCategory getMaterialCategory(long id)throws Exception {
+        MaterialCategory result=null;
+        try{
+            result=materialCategoryMapper.selectByPrimaryKey(id);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    public List<MaterialCategory> getMaterialCategoryListByIds(String ids)throws Exception {
+        List<Long> idList = StringUtil.strToLongList(ids);
+        List<MaterialCategory> list = new ArrayList<>();
+        try{
+            MaterialCategoryExample example = new MaterialCategoryExample();
+            example.createCriteria().andIdIn(idList);
+            list = materialCategoryMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<MaterialCategory> getMaterialCategory()throws Exception {
+        MaterialCategoryExample example = new MaterialCategoryExample();
+        List<MaterialCategory> list=null;
+        try{
+            list=materialCategoryMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<MaterialCategory> getAllList(Long parentId)throws Exception {
+        List<MaterialCategory> list=null;
+        try{
+            list = getMCList(parentId);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<MaterialCategory> getMCList(Long parentId)throws Exception {
+        List<MaterialCategory> res= new ArrayList<MaterialCategory>();
+        List<MaterialCategory> list=null;
+        MaterialCategoryExample example = new MaterialCategoryExample();
+        example.createCriteria().andParentIdEqualTo(parentId).andIdNotEqualTo(1L);
+        example.setOrderByClause("id");
+        list=materialCategoryMapper.selectByExample(example);
+        if(list!=null && list.size()>0) {
+            res.addAll(list);
+            for(MaterialCategory mc : list) {
+                List<MaterialCategory> mcList = getMCList(mc.getId());
+                if(mcList!=null && mcList.size()>0) {
+                    res.addAll(mcList);
+                }
+            }
+        }
+        return res;
+    }
+
+    @Override
+    public List<MaterialCategory> select(String name, Integer parentId) throws Exception{
+        List<MaterialCategory> list=null;
+        try{
+            PageUtils.startPage();
+            list=materialCategoryMapperEx.selectByConditionMaterialCategory(name, parentId);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int insertMaterialCategory(JSONObject obj, HttpServletRequest request)throws Exception {
+        MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
+        materialCategory.setCreateTime(new Date());
+        materialCategory.setUpdateTime(new Date());
+        User user = userService.getCurrentUser();
+        materialCategory.setTenantId(user.getId());
+        int result = 0;
+        try{
+            result = materialCategoryMapper.insertSelective(materialCategory);
+            logService.insertLog("商品类型",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(materialCategory.getName()).toString(), request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int updateMaterialCategory(JSONObject obj, HttpServletRequest request) throws Exception{
+        MaterialCategory materialCategory = JSONObject.parseObject(obj.toJSONString(), MaterialCategory.class);
+        materialCategory.setUpdateTime(new Date());
+        int result=0;
+        try{
+            result=materialCategoryMapperEx.editMaterialCategory(materialCategory);
+            logService.insertLog("商品类型",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialCategory.getName()).toString(), request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int deleteMaterialCategory(Long id, HttpServletRequest request)throws Exception {
+        return batchDeleteMaterialCategoryByIds(id.toString());
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchDeleteMaterialCategory(String ids, HttpServletRequest request)throws Exception {
+        return batchDeleteMaterialCategoryByIds(ids);
+    }
+
+    @Override
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    public int batchDeleteMaterialCategoryByIds(String ids) throws Exception {
+        int result=0;
+        String [] idArray=ids.split(",");
+        //校验产品表	jsh_material
+        List<Material> materialList=null;
+        try{
+            materialList= materialMapperEx.getMaterialListByCategoryIds(idArray);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        if(materialList!=null&&materialList.size()>0){
+            logger.error("异常码[{}],异常提示[{}],参数,CategoryIds[{}]",
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
+            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
+                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
+        }
+        StringBuffer sb = new StringBuffer();
+        sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
+        List<MaterialCategory> list = getMaterialCategoryListByIds(ids);
+        for(MaterialCategory materialCategory: list){
+            sb.append("[").append(materialCategory.getName()).append("]");
+        }
+        logService.insertLog("商品类型", sb.toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        //更新时间
+        Date updateDate = new Date();
+        //更新人
+        User userInfo = userService.getCurrentUser();
+        Long updater = userInfo==null ? null : userInfo.getId();
+        String strArray[]=ids.split(",");
+        if(strArray.length<1){
+            return 0;
+        }
+        List<MaterialCategory> mcList = materialCategoryMapperEx.getMaterialCategoryListByCategoryIds(idArray);
+        if(mcList!=null && mcList.size()>0) {
+            logger.error("异常码[{}],异常提示[{}]",
+                    ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_CODE,ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_MSG);
+            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_CODE,
+                    ExceptionConstants.MATERIAL_CATEGORY_CHILD_NOT_SUPPORT_DELETE_MSG);
+        } else {
+            result=materialCategoryMapperEx.batchDeleteMaterialCategoryByIds(updateDate,updater,strArray);
+        }
+        return result;
+    }
+
+    @Override
+    public int checkIsNameExist(Long id, String name)throws Exception {
+        MaterialCategoryExample example = new MaterialCategoryExample();
+        example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<MaterialCategory> list=null;
+        try{
+            list= materialCategoryMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list==null?0:list.size();
+    }
+
+    @Override
+    public List<MaterialCategory> findById(Long id)throws Exception {
+        List<MaterialCategory> list=null;
+        if(id!=null) {
+            MaterialCategoryExample example = new MaterialCategoryExample();
+            example.createCriteria().andIdEqualTo(id);
+            try{
+                list=materialCategoryMapper.selectByExample(example);
+            }catch(Exception e){
+                JshException.readFail(logger, e);
+            }
+        }
+        return list;
+    }
+
+    /**
+     * description:
+     * 获取商品类别树数据
+     */
+    @Override
+    public List<TreeNode> getMaterialCategoryTree(Long id) throws Exception{
+        List<TreeNode> list=null;
+        try{
+            list=materialCategoryMapperEx.getNodeTree(id);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+       return list;
+    }
+    /**
+     * 根据商品类别编号判断商品类别是否已存在
+     * */
+    @Override
+    public void  checkMaterialCategorySerialNo(MaterialCategory mc)throws Exception {
+        if(mc==null){
+            return;
+        }
+        if( mc.getSerialNo() < 0){
+            return;
+        }
+        //根据商品类别编号查询商品类别
+        List<MaterialCategory> mList=null;
+        try{
+            mList= materialCategoryMapperEx.getMaterialCategoryBySerialNo(mc.getSerialNo(), mc.getId());
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        if(mList==null||mList.size()<1){
+            //未查询到对应数据,编号可用
+            return;
+        }
+        if(mList.size()>1){
+            //查询到的数据条数大于1,编号已存在
+            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
+                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
+        }
+        if(mc.getId()==null){
+            //新增时,编号已存在
+            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
+                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
+        }
+        /**
+         * 包装类型用equals来比较
+         * */
+        if(mc.getId().equals(mList.get(0).getId())){
+            //修改时,相同编号,id不同
+            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_CODE,
+                    ExceptionConstants.MATERIAL_CATEGORY_SERIAL_ALREADY_EXISTS_MSG);
+        }
+    }
+
+    @Override
+    public Long getCategoryIdByName(String name){
+        Long categoryId = null;
+        MaterialCategoryExample example = new MaterialCategoryExample();
+        example.createCriteria().andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<MaterialCategory> list = materialCategoryMapper.selectByExample(example);
+        if(list!=null && list.size()>0) {
+            categoryId = list.get(0).getId();
+        }
+        return categoryId;
+    }
+}

+ 29 - 13
src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java

@@ -1,22 +1,17 @@
 package com.jsh.erp.service.impl;
-
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 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.*;
 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.service.*;
 import com.jsh.erp.utils.DateUtils;
 import com.jsh.erp.utils.RandomHelper;
 import com.jsh.erp.utils.StringUtil;
@@ -49,9 +44,12 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     private UserService userService;
     @Resource
     private RedisService redisService;
-
     @Resource
     private MaterialService materialService;
+    @Resource
+    private DepotItemService depotItemService;
+    @Resource
+    private InventoryLogService inventoryLogService;
 
     @Override
     public MaterialExtend getMaterialExtend(long id)throws Exception {
@@ -283,7 +281,8 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         int result = 0;
         try{
             result= materialExtendMapper.insertSelective(materialExtend);
-
+            //更新当前库存
+            depotItemService.updateCurrentStockFun(materialExtend.getMaterialId(), materialExtend.getDepotId());
         }catch(Exception e){
             JshException.writeFail(logger, e);
         }
@@ -306,6 +305,8 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         materialExtend.setUpdateSerial(user.getLoginName());
         int res =0;
         try{
+            //修改库存
+            updateInventory(null,null,materialExtend);
             res= materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
         }catch(Exception e){
             JshException.writeFail(logger, e);
@@ -491,11 +492,26 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     }
 
     /**
-     * 设置当前库存
-     * @param depotId 仓库id
-     * @param mId   商品id
-     * @param stock 库存数量
+     * 修改子商品库存
      */
+    @Override
+    public synchronized void updateInventory(Long depotHeadId, Long depotItemId, MaterialExtend materialExtend) throws Exception {
+        if (materialExtend.getInventory() != null){
+            User user = userService.getCurrentUser();
+            InventoryLog log = new InventoryLog();
+            log.setUpdateUser(user.getId());
+            log.setUpdateTime(new Date());
+            log.setMaterialId(materialExtend.getMaterialId());
+            log.setMaterialExtendId(materialExtend.getId());
+            log.setOriginalStock(materialExtendMapper.selectByPrimaryKey(materialExtend.getId()).getInventory().intValue());
+            Integer i = materialExtend.getInventory().intValue();
+            log.setCurrentStock(i);
+            log.setDepotHeadId(depotHeadId);
+            log.setDepotItemId(depotItemId);
+            inventoryLogService.save(log);
+            update(new UpdateWrapper<MaterialExtend>().set("inventory",materialExtend.getInventory()).eq("id",materialExtend.getId()));;
+        }
+    }
     /**
      * 设置当前库存
      * @param depotId 仓库id

+ 10 - 2
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -9,6 +9,7 @@ import com.jsh.erp.constants.BusinessConstants;
 import com.jsh.erp.constants.ExceptionConstants;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
+import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
 import com.jsh.erp.datasource.vo.MaterialWarnListVo;
 import com.jsh.erp.exception.BusinessRunTimeException;
@@ -209,11 +210,14 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                             //设置初始库
                             insertInitialStockByMaterialAndDepot(depotId, mId, parseBigDecimalEx(number), lowSafeStock, highSafeStock);
                             //设置当前库
-                            insertCurrentStockByMaterialAndDepot(depotId, mId, parseBigDecimalEx(number));
+                            //insertCurrentStockByMaterialAndDepot(depotId, mId, parseBigDecimalEx(number));
+                            //更新当前库存
+                            depotItemService.updateCurrentStockFun(mId, depotId);
                         }
                     }
                 }
             }
+
             logService.insertLog("商品",
                     new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(m.getName()).toString(), request);
             return 1;
@@ -236,7 +240,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     public int updateMaterial(JSONObject obj, HttpServletRequest request) throws Exception{
         Material material = JSONObject.parseObject(obj.toJSONString(), Material.class);
-
         try{
             //修改商品属性
             materialMapper.updateByPrimaryKeySelective(material);
@@ -1987,6 +1990,11 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         return info;
     }
 
+    @Override
+    public List<PDADepotItemVO> inventoryInquiry(String type, String keyword) {
+        return materialMapperEx.inventoryInquiry();
+    }
+
     /**
      * 解析excel表格数据为商品对象
      */

+ 9 - 3
src/main/resources/mapper_xml/DepotItemMapper.xml

@@ -576,7 +576,10 @@
 	  me.bar_code AS bar_code,
 	  di.oper_number AS oper_number,
       me.commodity_unit AS commodity_unit,
-      di.material_unit AS material_unit
+      di.material_unit AS material_unit,
+      di.actual_quantity_in_storage AS actual_quantity_in_storage,
+      di.material_id AS material_id,
+      m.img_name AS img_name
     FROM
       jsh_depot_item di
     LEFT JOIN jsh_material m ON di.material_id = m.id
@@ -598,7 +601,9 @@
 	  me.bar_code AS bar_code,
 	  di.oper_number AS oper_number,
       di.material_unit AS material_unit,
-      me.create_time AS create_time
+      me.create_time AS create_time,
+      di.material_id AS material_id,
+      m.img_name AS img_name
     FROM
       jsh_depot_item di
       LEFT JOIN jsh_material m ON di.material_id = m.id
@@ -617,7 +622,8 @@
       m.standard AS material_standard,
       di.actual_quantity_in_storage AS actual_quantity_in_storage,
       di.warehousing_time AS warehousing_time,
-      me.commodity_unit AS commodity_unit
+      me.commodity_unit AS commodity_unit,
+      m.img_name AS img_name
     FROM
       jsh_depot_item di
       LEFT JOIN jsh_depot_head dh ON di.header_id = dh.id

+ 5 - 0
src/main/resources/mapper_xml/InventoryLogMapper.xml

@@ -0,0 +1,5 @@
+<?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="com.jsh.erp.datasource.mappers.InventoryLogMapper">
+
+</mapper>

+ 5 - 6
src/main/resources/mapper_xml/MaterialCategoryMapper.xml

@@ -116,9 +116,11 @@
       #{remark,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, 
       #{tenantId,jdbcType=BIGINT}, #{deleteFlag,jdbcType=VARCHAR})
   </insert>
+
   <insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.MaterialCategory">
     insert into jsh_material_category
     <trim prefix="(" suffix=")" suffixOverrides=",">
+      serial_no,
       <if test="id != null">
         id,
       </if>
@@ -134,9 +136,6 @@
       <if test="sort != null">
         sort,
       </if>
-      <if test="serialNo != null">
-        serial_no,
-      </if>
       <if test="remark != null">
         remark,
       </if>
@@ -154,6 +153,7 @@
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
+      (select ifnull(MAX(id),0) + 10001 from jsh_material_category AS mc),
       <if test="id != null">
         #{id,jdbcType=BIGINT},
       </if>
@@ -169,9 +169,7 @@
       <if test="sort != null">
         #{sort,jdbcType=VARCHAR},
       </if>
-      <if test="serialNo != null">
-        #{serialNo,jdbcType=VARCHAR},
-      </if>
+
       <if test="remark != null">
         #{remark,jdbcType=VARCHAR},
       </if>
@@ -189,6 +187,7 @@
       </if>
     </trim>
   </insert>
+
   <select id="countByExample" parameterType="com.jsh.erp.datasource.entities.MaterialCategoryExample" resultType="java.lang.Long">
     select count(*) from jsh_material_category
     <if test="_parameter != null">

+ 3 - 1
src/main/resources/mapper_xml/MaterialCategoryMapperEx.xml

@@ -102,13 +102,15 @@
         </foreach>
        )
     </update>
+
     <update id="editMaterialCategory">
        update jsh_material_category
        set update_time=#{updateTime},
-        parent_id=#{parentId},sort=#{sort},serial_no=#{serialNo},
+        parent_id=#{parentId},sort=#{sort},
         name=#{name},remark=#{remark}
        where id =#{id}
     </update>
+
     <select  id="getMaterialCategoryBySerialNo" resultMap="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.BaseResultMap">
         select
         <include refid="com.jsh.erp.datasource.mappers.MaterialCategoryMapper.Base_Column_List"/>

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

@@ -426,9 +426,6 @@
       <if test="barCode != null">
         bar_code = #{barCode,jdbcType=VARCHAR},
       </if>
-      <if test="inventory != null">
-        inventory = #{inventory,jdbcType=DECIMAL},
-      </if>
       <if test="depotId != null">
         depot_id = #{depotId,jdbcType=BIGINT},
       </if>

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

@@ -826,4 +826,17 @@
         order by m.id desc, me.default_flag desc,me.production_date asc, me.batch_number asc
     </select>
 
+    <select id="inventoryInquiry" resultType="com.jsh.erp.datasource.entities.com.jsh.erp.datasource.pda.vo.PDADepotItemVO">
+        select m.*,u.name unit_name,mc.name categoryName,me.bar_code,me.id meId,me.commodity_unit,me.sku,
+        me.production_date,me.expiry_num,me.supplier_id,me.batch_number,me.depot_id,me.position,d.`name` depotName,s.supplier supplierName
+        from jsh_material m
+        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
+        left join jsh_unit u on m.unit_id=u.id and ifnull(u.delete_Flag,'0') !='1'
+        left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
+        left JOIN jsh_depot d on me.depot_id = d.id and ifnull(d.delete_Flag,'0') !='1'
+        left JOIN jsh_supplier s on me.supplier_id = s.id and ifnull(s.delete_Flag,'0') !='1'
+        where m.enabled=1 and me.id is not null
+        and ifnull(me.delete_flag,'0') !='1'
+    </select>
+
 </mapper>