Просмотр исходного кода

商品信息导出,库存修正

huang 1 месяц назад
Родитель
Сommit
625ba54f39

+ 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;
+
+}

+ 7 - 0
src/main/java/com/jsh/erp/service/DepotHeadService.java

@@ -177,4 +177,11 @@ public interface DepotHeadService extends IService<DepotHead> {
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     void batchAddDepotHeadAndDetail(String ids, HttpServletRequest request) throws Exception;
+
+    /**
+     * 根据商品id查询最后一条商品订单
+     * @param mid
+     * @return
+     */
+    DepotHead getDepotLastByMaterialId(long mid);
 }

+ 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);

+ 15 - 1
src/main/java/com/jsh/erp/service/MaterialService.java

@@ -3,7 +3,9 @@ package com.jsh.erp.service;
 
 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.vo.MaterialWarnListVo;
 import com.jsh.erp.utils.BaseResponseInfo;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -14,7 +16,7 @@ import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
-public interface MaterialService {
+public interface MaterialService extends IService<Material> {
     Material getMaterial(long id)throws Exception;
 
     List<Material> getMaterialListByIds(String ids)throws Exception;
@@ -34,6 +36,10 @@ public interface MaterialService {
     @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;
 
@@ -163,4 +169,12 @@ public interface MaterialService {
 
     Material getMaterialById(Long id);
 
+    /**
+     * 获取商品提醒
+     */
+    MaterialWarnListVo getMaterialWarn();
+
+
+    //导入表格
+    BaseResponseInfo importExcelTwo(MultipartFile file, HttpServletRequest request) throws Exception;
 }

+ 11 - 0
src/main/java/com/jsh/erp/service/impl/DepotHeadServiceImpl.java

@@ -1810,4 +1810,15 @@ public class DepotHeadServiceImpl extends ServiceImpl<DepotHeadMapper, DepotHead
                 new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_BATCH_ADD).append(sb).toString(),
                 ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
     }
+
+    /**
+     * 根据商品id获取最后一条销售订单
+     * @param mid 商品id
+     * @return
+     */
+    @Override
+    public DepotHead getDepotLastByMaterialId(long mid) {
+        return depotHeadMapper.getDepotLastByMaterialId(mid);
+    }
+
 }

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

@@ -66,6 +66,8 @@ public class DepotItemServiceImpl extends ServiceImpl<DepotItemMapper, DepotItem
     private MaterialCurrentStockMapperEx materialCurrentStockMapperEx;
     @Resource
     private LogService logService;
+    @Resource
+    private MaterialExtendMapper materialExtendMapper;
 
     /**
      * pda根据订单信息查询商品列表
@@ -1060,6 +1062,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();
@@ -1072,7 +1076,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);
     }
 
     /**
@@ -1206,9 +1210,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

+ 404 - 7
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -9,6 +9,7 @@ import com.jsh.erp.constants.ExceptionConstants;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
+import com.jsh.erp.datasource.vo.MaterialWarnListVo;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.service.*;
@@ -29,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.*;
 
 @Service
@@ -71,6 +73,8 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     private MaterialExtendService materialExtendService;
     @Resource
     private SystemConfigService systemConfigService;
+    @Resource
+    private DepotHeadService depotHeadService;
 
     @Value(value="${file.uploadType}")
     private Long fileUploadType;
@@ -542,10 +546,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         //查询商品副条码相关列表
         Map<Long, MaterialExtend> otherMaterialMap = new HashMap<>();
         List<MaterialExtend> otherDataList = materialMapperEx.getOtherMaterialList();
-        for(MaterialExtend me: otherDataList) {
-            //遇到多个副条码的情况,只加第一个
-            otherMaterialMap.putIfAbsent(me.getMaterialId(), me);
-        }
         String nameStr = "名称*,规格,型号,颜色,品牌,类别,基础重量(kg),基本单位*,副单位,基本条码*,副条码,比例,多属性," +
                 "采购价,零售价,销售价,最低售价,状态*,序列号,批号,自定义1,自定义2,自定义3,备注,系统sku,生产日期,保质期,供应商,商品条码,批次号,仓库名称,仓位货架";
         List<String> nameList = StringUtil.strToStringList(nameStr);
@@ -598,9 +598,9 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 objs[25] = m.getProductionDate() == null ? "" : m.getProductionDate().toString();
                 objs[26] = m.getExpiryNum() == null ? "" : m.getExpiryNum().toString();
                 objs[27] = m.getSupplierId() == null ? "" : m.getSupplierId().toString();
-                objs[28] = m.getBarCode();
+                objs[28] = m.getmBarCode();
                 objs[29] = m.getBatchNumber();
-                objs[30] = m.getDepotId() == null ? "" : m.getDepotId().toString();
+                objs[30] = m.getDepotId() == null ? "" : depotService.getDepot(m.getDepotId()).getName();
                 objs[31] = m.getPosition();
                 //仓库期初库存
                 int i = 32;
@@ -1208,11 +1208,20 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     @Override
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     public void insertCurrentStockByMaterialAndDepot(Long depotId, Long mId, BigDecimal stock){
+        //查询当前商品当前库存
+        BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(mId,depotId);
         MaterialCurrentStock materialCurrentStock = new MaterialCurrentStock();
         materialCurrentStock.setDepotId(depotId);
         materialCurrentStock.setMaterialId(mId);
         materialCurrentStock.setCurrentNumber(stock);
-        materialCurrentStockMapper.insertSelective(materialCurrentStock); //存入当前库存
+        if (currentNumber == null){
+            materialCurrentStockMapper.insertSelective(materialCurrentStock); //存入当前库存
+        }else {
+            //已有库存,修改当前库存
+            currentNumber.add(materialCurrentStock.getCurrentNumber());
+            materialCurrentStock.setCurrentNumber(currentNumber);
+            materialCurrentStockMapper.updateByPrimaryKeySelective(materialCurrentStock);
+        }
     }
 
     /**
@@ -1608,4 +1617,392 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         return material;
     }
 
+    /**
+     * 获取商品提醒
+     */
+    @Override
+    public MaterialWarnListVo getMaterialWarn() {
+        MaterialWarnListVo vo = new MaterialWarnListVo();
+        List<String> noMovingPinReminders = new ArrayList<>();
+        List<String> expirationReminders = new ArrayList<>();
+        List<String> inventoryReminders = new ArrayList<>();
+        //获取商品信息
+        MaterialExample materialExample = new MaterialExample();
+        materialExample.createCriteria().andDeleteFlagEqualTo("0");
+        List<Material> materials = materialMapper.selectByExample(materialExample);
+        //获取商品子表信息
+        MaterialExtendExample materialExtendExample = new MaterialExtendExample();
+        materialExtendExample.createCriteria().andDeleteFlagEqualTo("0");
+        List<MaterialExtend> extendList = materialExtendMapper.selectByExample(materialExtendExample);
+        //无动销提醒
+        materials.stream().filter( v -> v.getMovingPinReminderCycle() != null)
+                        .forEach(v -> {
+                            //获取商品最后一条动销订单数据
+                            DepotHead depotHead = depotHeadService.getDepotLastByMaterialId(v.getId());
+                            if (depotHead != null){
+                                if (DateUtils.differentDaysByMillisecond(depotHead.getOperTime(),new Date()) > Integer.valueOf(v.getMovingPinReminderCycle())){
+                                    //当前时间对比订单时间是否大于动销提醒周期
+                                    String str = "商品名称:" + v.getName() + ",在[无动销提醒周期]内,无动销,请及时处理";
+                                    noMovingPinReminders.add(str);
+                                }
+                            }else{
+                                //获取商品批次信息
+                                MaterialExtend m = materialExtendMapper.selectByMId(v.getId()).get(0);
+                                if (DateUtils.differentDaysByMillisecond(m.getCreateTime(),new Date()) > Integer.valueOf(v.getMovingPinReminderCycle())){
+                                    String str = "商品名称:" + v.getName() + ",在[无动销提醒周期]内,无动销,请及时处理";
+                                    noMovingPinReminders.add(str);
+                                }
+                            }
+
+                        });
+        vo.setNoMovingPinReminder(noMovingPinReminders);
+        //过期提醒
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        extendList.stream().filter(v -> v.getInventory().doubleValue() > 0 && v.getProductionDate() != null && v.getExpiryNum() != null)
+                .forEach(v ->{
+                    if (DateUtils.differentDaysByMillisecond(v.getProductionDate(),new Date()) >  (v.getExpiryNum() -30)){
+                        String name = materialMapper.selectByPrimaryKey(v.getMaterialId()).getName();
+                        String str = "商品名称:" + name
+                                + ", 批次号:" + v.getBatchNumber()
+                                + ", 条码:" + v.getBarCode()
+                                + ", 生产日期:" + sdf.format(v.getProductionDate())
+                                + ", 保质期:" + v.getExpiryNum() + "天"
+                                + ", 库存:" + v.getInventory()
+                                + ",即将要过期,请及时处理";
+                        expirationReminders.add(str);
+                    }
+                });
+        vo.setExpirationReminder(expirationReminders);
+        //库存提醒
+        MaterialInitialStockExample initialStockExample = new MaterialInitialStockExample();
+        initialStockExample.createCriteria().andDeleteFlagEqualTo("0");
+
+        List<MaterialInitialStock> initialStocks = materialInitialStockMapper.selectByExample(initialStockExample);
+        initialStocks.stream().filter(v -> v.getLowSafeStock() != null && v.getLowSafeStock().doubleValue() > 0)
+                .forEach(v -> {
+                    //根据商品id和仓库id查询当前库存
+                    BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(v.getMaterialId(),v.getDepotId());
+                    if (currentNumber.doubleValue() <= v.getLowSafeStock().doubleValue()){
+                        Material material = materialMapper.selectByPrimaryKey(v.getMaterialId());
+                        String str = "商品名称:" + material.getName()
+                                + ",库存告警,请及时处理";
+                        inventoryReminders.add(str);
+                    }
+                });
+        vo.setInventoryReminder(inventoryReminders);
+        return vo;
+    }
+
+    //导入表格
+    @Override
+    public BaseResponseInfo importExcelTwo(MultipartFile file, HttpServletRequest request) throws Exception {
+        BaseResponseInfo info = new BaseResponseInfo();
+        try {
+            Long beginTime = System.currentTimeMillis();
+            //文件扩展名只能为xls
+            String fileName = file.getOriginalFilename();
+            if(StringUtil.isNotEmpty(fileName)) {
+                String fileExt = fileName.substring(fileName.indexOf(".")+1);
+                if(!"xls".equals(fileExt)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXTENSION_ERROR_CODE,
+                            ExceptionConstants.MATERIAL_EXTENSION_ERROR_MSG);
+                }
+            }
+            Workbook workbook = Workbook.getWorkbook(file.getInputStream());
+            Sheet src = workbook.getSheet(0);
+            //获取真实的行数,剔除掉空白行
+            int rightRows = ExcelUtils.getRightRows(src);
+            List<Depot> depotList= depotService.getDepot();
+            int depotCount = depotList.size();
+            Map<String, Long> depotMap = parseDepotToMap(depotList);
+            User user = userService.getCurrentUser();
+            List<MaterialWithInitStock> mList = new ArrayList<>();
+            //单次导入超出1000条
+            if(rightRows > 1002) {
+                throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_IMPORT_OVER_LIMIT_CODE,
+                        String.format(ExceptionConstants.MATERIAL_IMPORT_OVER_LIMIT_MSG));
+            }
+            for (int i = 2; i < rightRows; i++) {
+                String name = ExcelUtils.getContent(src, i, 0); //名称
+                String standard = ExcelUtils.getContent(src, i, 1); //规格
+                String model = ExcelUtils.getContent(src, i, 2); //型号
+                String color = ExcelUtils.getContent(src, i, 3); //颜色
+                String brand = ExcelUtils.getContent(src, i, 4); //品牌
+                String categoryName = ExcelUtils.getContent(src, i, 5); //类别
+                String weight = ExcelUtils.getContent(src, i, 6); //基础重量(kg)
+                String unit = ExcelUtils.getContent(src, i, 7); //基本单位
+                //名称为空
+                if(StringUtil.isEmpty(name)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_EMPTY_CODE,
+                            String.format(ExceptionConstants.MATERIAL_NAME_EMPTY_MSG, i+1));
+                }
+                //名称长度超出
+                if(name.length()>100) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_NAME_OVER_CODE,
+                            String.format(ExceptionConstants.MATERIAL_NAME_OVER_MSG, i+1));
+                }
+                //规格长度超出
+                if(StringUtil.isNotEmpty(standard) && standard.length()>100) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_STANDARD_OVER_CODE,
+                            String.format(ExceptionConstants.MATERIAL_STANDARD_OVER_MSG, i+1));
+                }
+                //型号长度超出
+                if(StringUtil.isNotEmpty(model) && model.length()>100) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_MODEL_OVER_CODE,
+                            String.format(ExceptionConstants.MATERIAL_MODEL_OVER_MSG, i+1));
+                }
+                //基本单位为空
+                if(StringUtil.isEmpty(unit)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_EMPTY_CODE,
+                            String.format(ExceptionConstants.MATERIAL_UNIT_EMPTY_MSG, i+1));
+                }
+                //类别为空
+                if(StringUtil.isEmpty(categoryName)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_Category_Name_EMPTY_CODE,
+                            String.format(ExceptionConstants.MATERIAL_Category_Name_EMPTY_MSG, i+1));
+                }
+                MaterialWithInitStock m = new MaterialWithInitStock();
+                //设置商品名字、规格、型号、颜色、品牌
+                m.setName(name);
+                m.setStandard(standard);
+                m.setModel(model);
+                m.setColor(color);
+                m.setBrand(brand);
+                //通过名称生成助记码
+                m.setMnemonic(PinYinUtil.getFirstLettersLo(name));
+                //通过类型名查询类型编号
+                Long categoryId = materialCategoryService.getCategoryIdByName(categoryName);
+                //获取类型编码
+                Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
+                //设置系统sku
+                m.setSystemSku(serial_no + DateUtils.dateTimeNow());
+                if(null!=categoryId){
+                    m.setCategoryId(categoryId);
+                }
+                if(StringUtil.isNotEmpty(weight)) {
+                    //校验基础重量是否是数字(含小数)
+                    if(!StringUtil.isPositiveBigDecimal(weight)) {
+                        throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_CODE,
+                                String.format(ExceptionConstants.MATERIAL_WEIGHT_NOT_DECIMAL_MSG, i+1));
+                    }
+                    m.setWeight(new BigDecimal(weight));
+                }
+                String manyUnit = ExcelUtils.getContent(src, i, 8); //副单位
+                String ratio = ExcelUtils.getContent(src, i, 9); //比例
+                String sku = ExcelUtils.getContent(src, i, 10); //多属性
+                String purchaseDecimal = ExcelUtils.getContent(src, i, 11); //采购价
+                String commodityDecimal = ExcelUtils.getContent(src, i, 12); //零售价
+                String wholesaleDecimal = ExcelUtils.getContent(src, i, 13); //销售价
+                String lowDecimal = ExcelUtils.getContent(src, i, 14); //最低售价
+                String enabled = ExcelUtils.getContent(src, i, 15); //状态
+                String enableSerialNumber = ExcelUtils.getContent(src, i, 16); //序列号
+                String enableBatchNumber = ExcelUtils.getContent(src, i, 17); //批号
+                String systemSku = ExcelUtils.getContent(src, i, 18); //系统sku
+                String productionDate = ExcelUtils.getContent(src, i, 19); //生产日期
+                String expiryNum = ExcelUtils.getContent(src, i, 20); //保质期天数
+                if(StringUtil.isNotEmpty(expiryNum)) {
+                    //校验保质期是否是正整数
+                    if(!StringUtil.isPositiveLong(expiryNum)) {
+                        throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE,
+                                String.format(ExceptionConstants.MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG, i+1));
+                    }
+                    //m.setExpiryNum(Integer.parseInt(expiryNum));
+                }
+                String supplier = ExcelUtils.getContent(src, i, 21); //供应商
+                String barCode = ExcelUtils.getContent(src, i, 22); //商品条码
+                String batchNumber = ExcelUtils.getContent(src, i, 23); //批次号
+                String depotName = ExcelUtils.getContent(src, i, 24); //仓库名称
+                String position = ExcelUtils.getContent(src, i, 25); //仓位货架
+                String otherField1 = ExcelUtils.getContent(src, i, 26); //自定义1
+                String otherField2 = ExcelUtils.getContent(src, i, 27); //自定义2
+                String otherField3 = ExcelUtils.getContent(src, i, 28); //自定义3
+                String remark = ExcelUtils.getContent(src, i, 29); //备注
+                // m.setPosition(StringUtil.isNotEmpty(position)?position:null);
+                //m.setMfrs(StringUtil.isNotEmpty(mfrs)?mfrs:null);
+                m.setOtherField1(StringUtil.isNotEmpty(otherField1)?otherField1:null);
+                m.setOtherField2(StringUtil.isNotEmpty(otherField2)?otherField2:null);
+                m.setOtherField3(StringUtil.isNotEmpty(otherField3)?otherField3:null);
+                m.setRemark(remark);
+                //状态格式错误
+                if(!"1".equals(enabled) && !"0".equals(enabled)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLED_ERROR_CODE,
+                            String.format(ExceptionConstants.MATERIAL_ENABLED_ERROR_MSG, i+1));
+                }
+                //基本条码为空
+                if(StringUtil.isEmpty(barCode)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_EMPTY_CODE,
+                            String.format(ExceptionConstants.MATERIAL_BARCODE_EMPTY_MSG, i+1));
+                }
+                //校验基本条码长度为4到40位
+                if(!StringUtil.checkBarCodeLength(barCode)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_CODE,
+                            String.format(ExceptionConstants.MATERIAL_BARCODE_LENGTH_ERROR_MSG, barCode));
+                }
+                //批量校验excel中有无重复商品,是指名称、规格、型号、颜色、单位、多属性
+                batchCheckExistMaterialListByParam(mList, name, standard, model, color, unit, sku);
+                //批量校验excel中有无重复条码(1-文档自身校验,2-和数据库里面的商品校验)
+                //batchCheckExistBarCodeByParam(mList, barCode, manyBarCode);
+                //设置商品拓展属性
+                JSONObject materialExObj = new JSONObject();
+                JSONObject basicObj = new JSONObject();
+                basicObj.put("barCode", barCode);
+                basicObj.put("commodityUnit", unit);
+                basicObj.put("sku", sku);
+                basicObj.put("purchaseDecimal", purchaseDecimal);
+                basicObj.put("commodityDecimal", commodityDecimal);
+                basicObj.put("wholesaleDecimal", wholesaleDecimal);
+                basicObj.put("lowDecimal", lowDecimal);
+                materialExObj.put("basic", basicObj);
+                if(StringUtil.isNotEmpty(manyUnit) && StringUtil.isNotEmpty(ratio)){ //多单位
+                    //校验比例是否是数字(含小数)
+                    if(!StringUtil.isPositiveBigDecimal(ratio.trim())) {
+                        throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_RATIO_NOT_INTEGER_CODE,
+                                String.format(ExceptionConstants.MATERIAL_RATIO_NOT_INTEGER_MSG, i+1));
+                    }
+                    Long unitId = unitService.getUnitIdByParam(unit, manyUnit, new BigDecimal(ratio.trim()));
+                    if(unitId != null) {
+                        m.setUnitId(unitId);
+                        m.setUnit("");
+                    }
+//                    else {
+//                        throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_UNIT_MATE_CODE,
+//                                String.format(ExceptionConstants.MATERIAL_UNIT_MATE_MSG, manyBarCode));
+//                    }
+                    JSONObject otherObj = new JSONObject();
+                    //otherObj.put("barCode", manyBarCode);
+                    otherObj.put("commodityUnit", manyUnit);
+                    otherObj.put("purchaseDecimal", parsePrice(purchaseDecimal,ratio));
+                    otherObj.put("commodityDecimal", parsePrice(commodityDecimal,ratio));
+                    otherObj.put("wholesaleDecimal", parsePrice(wholesaleDecimal,ratio));
+                    otherObj.put("lowDecimal", parsePrice(lowDecimal,ratio));
+                    materialExObj.put("other", otherObj);
+                } else {
+                    m.setUnit(unit);
+                    m.setUnitId(null);
+                }
+                m.setMaterialExObj(materialExObj);
+                m.setEnabled("1".equals(enabled));
+                if(StringUtil.isNotEmpty(enableSerialNumber) && "1".equals(enableSerialNumber)) {
+                    m.setEnableSerialNumber("1");
+                } else {
+                    m.setEnableSerialNumber("0");
+                }
+                if(StringUtil.isNotEmpty(enableBatchNumber) && "1".equals(enableBatchNumber)) {
+                    m.setEnableBatchNumber("1");
+                } else {
+                    m.setEnableBatchNumber("0");
+                }
+                if("1".equals(enableSerialNumber) && "1".equals(enableBatchNumber)) {
+                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_CODE,
+                            String.format(ExceptionConstants.MATERIAL_ENABLE_MUST_ONE_MSG, barCode));
+                }
+                m.setStockMap(getStockMapCache(src, depotCount, depotMap, i));
+                mList.add(m);
+            }
+            List<Long> deleteInitialStockMaterialIdList = new ArrayList<>();
+            List<Long> deleteCurrentStockMaterialIdList = new ArrayList<>();
+            List<MaterialInitialStock> insertInitialStockMaterialList = new ArrayList<>();
+            List<MaterialCurrentStock> insertCurrentStockMaterialList = new ArrayList<>();
+            //防止初始库存和当前库存出现重复
+            Map<String, String> materialDepotInitialMap = new HashMap<>();
+            Map<String, String> materialDepotCurrentMap = new HashMap<>();
+            for(MaterialWithInitStock m: mList) {
+                Long mId = 0L;
+                //判断该商品是否存在,如果不存在就新增,如果存在就更新
+                String basicBarCode = getBasicBarCode(m);
+                //根据条件返回产品列表
+                List<Material> materials = getMaterialListByParam(m.getName(),m.getStandard(),m.getModel(),m.getColor(),m.getUnit(),m.getUnitId(), basicBarCode);
+                if(materials.size() == 0) { //产品列表为0,新增商品
+                    materialMapperEx.insertSelectiveEx(m);
+                    mId = m.getId();
+                } else { //产品列表不为0,商品存在,修改商品属性
+                    mId = materials.get(0).getId();
+                    String materialJson = JSON.toJSONString(m);
+                    Material material = JSONObject.parseObject(materialJson, Material.class);
+                    material.setId(mId);
+                    materialMapper.updateByPrimaryKeySelective(material);
+                    //更新多单位
+                    if(material.getUnitId() == null) {
+                        materialMapperEx.setUnitIdToNull(material.getId());
+                    }
+                    //如果之前有保质期,则更新保质期
+//                    if(materials.get(0).getExpiryNum()!=null && material.getExpiryNum() == null) {
+//                        materialMapperEx.setExpiryNumToNull(material.getId());
+//                    }
+                }
+                //给商品新增或更新条码与价格相关信息
+                JSONObject materialExObj = m.getMaterialExObj();
+                insertOrUpdateMaterialExtend(materialExObj, "basic", "1", mId, user);
+                insertOrUpdateMaterialExtend(materialExObj, "other", "0", mId, user);
+                //给商品更新库存
+                Map<Long, BigDecimal> stockMap = m.getStockMap();
+                for(Depot depot: depotList){
+                    Long depotId = depot.getId();
+                    String materialDepotKey = mId + "_" + depotId;
+                    //获取初始库存
+                    BigDecimal initStock = getInitStock(mId, depotId);
+                    //excel里面的当前库存
+                    BigDecimal stock = stockMap.get(depot.getId());
+                    //新增或更新初始库存
+                    if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
+                        String basicStr = materialExObj.getString("basic");
+                        MaterialExtend materialExtend = JSONObject.parseObject(basicStr, MaterialExtend.class);
+                        if(StringUtil.isNotEmpty(materialExtend.getSku())) {
+                            throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_CODE,
+                                    String.format(ExceptionConstants.MATERIAL_SKU_BEGIN_STOCK_FAILED_MSG, materialExtend.getBarCode()));
+                        }
+                        buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
+                    } else {
+                        if(initStock.compareTo(BigDecimal.ZERO)!=0) {
+                            buildChangeInitialStock(deleteInitialStockMaterialIdList, insertInitialStockMaterialList, materialDepotInitialMap, mId, depotId, materialDepotKey, stock);
+                        }
+                    }
+                    //新增或更新当前库存
+                    Long billCount = depotItemService.getCountByMaterialAndDepot(mId, depotId);
+                    if(billCount == 0) {
+                        if(stock!=null && stock.compareTo(BigDecimal.ZERO)!=0) {
+                            buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
+                        } else {
+                            if(initStock.compareTo(BigDecimal.ZERO)!=0) {
+                                buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, stock);
+                            }
+                        }
+                    } else {
+                        BigDecimal currentNumber = getCurrentStockByMaterialIdAndDepotId(mId, depotId);
+                        //当前库存的更新:减去初始库存,再加上导入的新初始库存
+                        if(currentNumber!=null && initStock!=null && stock!=null) {
+                            currentNumber = currentNumber.subtract(initStock).add(stock);
+                        }
+                        buildChangeCurrentStock(deleteCurrentStockMaterialIdList, insertCurrentStockMaterialList, materialDepotCurrentMap, mId, depotId, materialDepotKey, currentNumber);
+                    }
+                }
+            }
+            //批量更新库存,先删除后新增
+            if(insertInitialStockMaterialList.size()>0) {
+                batchDeleteInitialStockByMaterialList(deleteInitialStockMaterialIdList);
+                materialInitialStockMapperEx.batchInsert(insertInitialStockMaterialList);
+            }
+            if(insertCurrentStockMaterialList.size()>0) {
+                batchDeleteCurrentStockByMaterialList(deleteCurrentStockMaterialIdList);
+                materialCurrentStockMapperEx.batchInsert(insertCurrentStockMaterialList);
+            }
+            //添加日志
+            logService.insertLog("商品",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_IMPORT).append(mList.size()).append(BusinessConstants.LOG_DATA_UNIT).toString(),
+                    ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+            Long endTime = System.currentTimeMillis();
+            logger.info("导入耗时:{}", endTime-beginTime);
+            info.code = 200;
+            info.data = "导入成功";
+        } catch (BusinessRunTimeException e) {
+            info.code = e.getCode();
+            info.data = e.getData().get("message");
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+            info.code = 500;
+            info.data = "导入失败";
+        }
+        return info;
+    }
+
 }

+ 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}

+ 10 - 9
src/main/resources/mapper_xml/MaterialMapperEx.xml

@@ -393,14 +393,13 @@
     </select>
 
     <select id="exportExcel" parameterType="com.jsh.erp.datasource.entities.MaterialExample" resultMap="ResultMapList">
-        select m.*,u.name unitName, u.ratio, mc.name categoryName,me.bar_code,me.commodity_unit,me.purchase_decimal, me.commodity_decimal,
+        select m.*,u.name unitName, u.ratio, mc.name categoryName,me.commodity_unit,me.purchase_decimal, me.commodity_decimal,
         me.wholesale_decimal, me.low_decimal, me.sku, me.production_date, me.expiry_num, me.supplier_id, me.bar_code, me.batch_number, me.depot_id, me.position
-        from jsh_material m
-        left join jsh_material_extend me on m.id=me.material_id and ifnull(me.delete_Flag,'0') !='1'
+        from  jsh_material_extend me
+        left join jsh_material m on m.id=me.material_id and ifnull(m.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'
         where 1=1
-        and (me.default_flag=1 or (me.sku is not null and me.sku!=''))
         <if test="materialParam != null and materialParam !=''">
             <bind name="bindKey" value="'%'+materialParam+'%'"/>
             and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
@@ -439,7 +438,7 @@
                 #{item}
             </foreach>
         </if>
-        and ifnull(m.delete_flag,'0') !='1'
+        and ifnull(me.delete_flag,'0') !='1'
         order by m.id desc, me.default_flag desc, me.id asc
     </select>
 
@@ -614,7 +613,7 @@
     </select>
 
     <select id="getListWithStock" resultMap="ResultMapListWithStock">
-        select m.id, m.name, m.standard, m.model, m.color, m.brand, m.position,
+        select m.id, m.name, m.standard, m.model, m.color, m.brand,
                me.commodity_unit unitName, mc.name categoryName, me.bar_code mBarCode,
         ifnull(me.purchase_decimal,0) purchaseDecimal,
         ifnull(mcs.current_unit_price,0) currentUnitPrice,
@@ -643,7 +642,7 @@
         </if>
         <if test="position != null and position !=''">
             <bind name="bindPosition" value="'%'+position+'%'"/>
-            and m.position like #{bindPosition}
+            and me.position like #{bindPosition}
         </if>
         <if test="materialParam != null">
             <bind name="bindKey" value="'%'+materialParam+'%'"/>
@@ -691,7 +690,7 @@
         </if>
         <if test="position != null and position !=''">
             <bind name="bindPosition" value="'%'+position+'%'"/>
-            and m.position like #{bindPosition}
+            and me.position like #{bindPosition}
         </if>
         <if test="materialParam != null">
             <bind name="bindKey" value="'%'+materialParam+'%'"/>
@@ -734,7 +733,7 @@
         </if>
         <if test="position != null and position !=''">
             <bind name="bindPosition" value="'%'+position+'%'"/>
-            and m.position like #{bindPosition}
+            and me.position like #{bindPosition}
         </if>
         <if test="materialParam != null">
             <bind name="bindKey" value="'%'+materialParam+'%'"/>
@@ -809,4 +808,6 @@
         order by m.id desc, me.default_flag desc, me.id asc
     </select>
 
+
+
 </mapper>