소스 검색

三期:商品信息修改

huang 1 개월 전
부모
커밋
7248d5a9a0
36개의 변경된 파일1154개의 추가작업 그리고 640개의 파일을 삭제
  1. 10 11
      src/main/java/com/jsh/erp/controller/DepotItemController.java
  2. 76 15
      src/main/java/com/jsh/erp/controller/MaterialController.java
  3. 57 46
      src/main/java/com/jsh/erp/controller/MaterialExtendController.java
  4. 18 34
      src/main/java/com/jsh/erp/controller/UnitController.java
  5. 1 1
      src/main/java/com/jsh/erp/datasource/dto/DepotHeadDTO.java
  6. 5 1
      src/main/java/com/jsh/erp/datasource/dto/MaterialDTO.java
  7. 2 4
      src/main/java/com/jsh/erp/datasource/dto/MaterialQueryDTO.java
  8. 12 8
      src/main/java/com/jsh/erp/datasource/entities/Material.java
  9. 13 9
      src/main/java/com/jsh/erp/datasource/entities/MaterialExtend.java
  10. 0 1
      src/main/java/com/jsh/erp/datasource/entities/MaterialVo4Unit.java
  11. 22 6
      src/main/java/com/jsh/erp/datasource/entities/Unit.java
  12. 6 2
      src/main/java/com/jsh/erp/datasource/mappers/MaterialExtendMapperEx.java
  13. 2 3
      src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java
  14. 1 1
      src/main/java/com/jsh/erp/datasource/mappers/UnitMapper.java
  15. 36 0
      src/main/java/com/jsh/erp/datasource/vo/MaterialAndExtendVo.java
  16. 20 0
      src/main/java/com/jsh/erp/datasource/vo/MaterialExtendVo.java
  17. 1 1
      src/main/java/com/jsh/erp/service/LogService.java
  18. 37 1
      src/main/java/com/jsh/erp/service/MaterialExtendService.java
  19. 39 8
      src/main/java/com/jsh/erp/service/MaterialService.java
  20. 21 0
      src/main/java/com/jsh/erp/service/MaterialUnitService.java
  21. 21 0
      src/main/java/com/jsh/erp/service/MaterialUpcService.java
  22. 2 2
      src/main/java/com/jsh/erp/service/SyncTescoSystemService.java
  23. 44 291
      src/main/java/com/jsh/erp/service/UnitService.java
  24. 2 2
      src/main/java/com/jsh/erp/service/UserService.java
  25. 0 5
      src/main/java/com/jsh/erp/service/impl/DepotItemServiceImpl.java
  26. 1 1
      src/main/java/com/jsh/erp/service/impl/LogServiceImpl.java
  27. 144 7
      src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java
  28. 73 61
      src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java
  29. 41 0
      src/main/java/com/jsh/erp/service/impl/MaterialUnitServiceImpl.java
  30. 36 0
      src/main/java/com/jsh/erp/service/impl/MaterialUpcServiceImpl.java
  31. 363 0
      src/main/java/com/jsh/erp/service/impl/UnitServiceImpl.java
  32. 2 2
      src/main/java/com/jsh/erp/service/impl/UserServiceImpl.java
  33. 33 97
      src/main/resources/mapper_xml/MaterialExtendMapper.xml
  34. 7 7
      src/main/resources/mapper_xml/MaterialExtendMapperEx.xml
  35. 1 1
      src/main/resources/mapper_xml/MaterialMapper.xml
  36. 5 12
      src/main/resources/mapper_xml/MaterialMapperEx.xml

+ 10 - 11
src/main/java/com/jsh/erp/controller/DepotItemController.java

@@ -132,19 +132,18 @@ public class DepotItemController {
     }
 
     /**
-     * 根据商品条码和仓库id查询库存数量
+     * 根据商品sku和仓库id查询库存数量
      * @param depotId
      * @param barCode
      * @param request
      * @return
      * @throws Exception
      */
-    @GetMapping(value = "/findStockByDepotAndBarCode")
+    @GetMapping(value = "/findStockByDepotAndSku")
     @ApiOperation(value = "根据商品条码和仓库id查询库存数量")
-    public BaseResponseInfo findStockByDepotAndBarCode(
-            @RequestParam(value = "depotId",required = false) Long depotId,
-            @RequestParam("barCode") String barCode,
-            HttpServletRequest request) throws Exception{
+    public BaseResponseInfo findStockByDepotAndBarCode(@RequestParam(value = "depotId",required = false) Long depotId,
+                                                       @RequestParam("sku") String barCode,
+                                                       HttpServletRequest request) throws Exception{
         BaseResponseInfo res = new BaseResponseInfo();
         Map<String, Object> map = new HashMap<String, Object>();
         try {
@@ -153,9 +152,9 @@ public class DepotItemController {
             List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode);
             if(list!=null && list.size()>0) {
                 MaterialVo4Unit materialVo4Unit = list.get(0);
-                if(StringUtil.isNotEmpty(materialVo4Unit.getSku())){
-                    stock = depotItemService.getSkuStockByParam(depotId,materialVo4Unit.getMeId(),null,null);
-                } else {
+//                if(StringUtil.isNotEmpty(materialVo4Unit.getSku())){
+//                    stock = depotItemService.getSkuStockByParam(depotId,materialVo4Unit.getMeId(),null,null);
+//                } else {
                     stock = depotItemService.getCurrentStockByParam(depotId, materialVo4Unit.getId());
                     if(materialVo4Unit.getUnitId()!=null) {
                         Unit unit = unitService.getUnit(materialVo4Unit.getUnitId());
@@ -163,7 +162,7 @@ public class DepotItemController {
                         stock = unitService.parseStockByUnit(stock, unit, commodityUnit);
                     }
                     position = materialService.getPositionByDidAndMid(depotId,materialVo4Unit.getId());
-                }
+//                }
             }
             map.put("stock", stock);
             map.put("position", position);
@@ -1041,7 +1040,7 @@ public class DepotItemController {
                         taxRate = ExcelUtils.getContent(src, i, 4);
                         remark = ExcelUtils.getContent(src, i, 5);
                     }
-                    if("CGRK".equals(prefixNo) || "XSCK".equals(prefixNo)) {
+                    if("CGRK".equals(prefixNo)) {
                         //采购入库
                         depotName = ExcelUtils.getContent(src, i, 0);
                         barCode = ExcelUtils.getContent(src, i, 1);

+ 76 - 15
src/main/java/com/jsh/erp/controller/MaterialController.java

@@ -2,9 +2,11 @@ package com.jsh.erp.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
 import com.jsh.erp.datasource.dto.MaterialDTO;
+import com.jsh.erp.datasource.dto.MaterialQueryDTO;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
 import com.jsh.erp.service.*;
@@ -75,43 +77,38 @@ public class MaterialController extends BaseController {
 
     @GetMapping(value = "/list")
     @ApiOperation(value = "获取信息列表")
-    public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search)throws Exception {
+    public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search) {
         String categoryId = StringUtil.getInfo(search, "categoryId");
         String materialParam = StringUtil.getInfo(search, "materialParam");
         String standard = StringUtil.getInfo(search, "standard");
         String model = StringUtil.getInfo(search, "model");
         String color = StringUtil.getInfo(search, "color");
         String brand = StringUtil.getInfo(search, "brand");
-        String mfrs = StringUtil.getInfo(search, "mfrs");
         String materialOther = StringUtil.getInfo(search, "materialOther");
         String weight = StringUtil.getInfo(search, "weight");
         String expiryNum = StringUtil.getInfo(search, "expiryNum");
         String enableSerialNumber = StringUtil.getInfo(search, "enableSerialNumber");
-        String enableBatchNumber = StringUtil.getInfo(search, "enableBatchNumber");
-        String position = StringUtil.getInfo(search, "position");
         String enabled = StringUtil.getInfo(search, "enabled");
         String remark = StringUtil.getInfo(search, "remark");
         String mpList = StringUtil.getInfo(search, "mpList");
         String reminder = StringUtil.getInfo(search, "reminder");
-        List<MaterialVo4Unit> list = materialService.select(materialParam, standard, model, color, brand, mfrs, materialOther, weight, expiryNum,
-                enableSerialNumber, enableBatchNumber, position, enabled, remark, categoryId, mpList, reminder);
+        List<MaterialVo4Unit> list = materialService.select(materialParam, standard, model, color, brand, materialOther, weight, expiryNum,
+                enableSerialNumber, enabled, remark, categoryId, mpList, reminder);
         return getDataTable(list);
     }
 
     @PostMapping(value = "/add")
     @ApiOperation(value = "新增")
-    public String addResource(@RequestBody MaterialDTO obj, HttpServletRequest request)throws Exception {
-        Map<String, Object> objectMap = new HashMap<>();
-        int insert = materialService.insertMaterial(obj, request);
-        return returnStr(objectMap, insert);
+    public AjaxResult addResource(@RequestBody MaterialDTO materialDTO, HttpServletRequest request)throws Exception {
+        materialService.insertMaterial(materialDTO, request);
+        return AjaxResult.success();
     }
 
     @PutMapping(value = "/update")
     @ApiOperation(value = "修改")
-    public String updateResource(@RequestBody MaterialDTO obj, HttpServletRequest request)throws Exception {
-        Map<String, Object> objectMap = new HashMap<>();
-        int update = materialService.updateMaterial(obj, request);
-        return returnStr(objectMap, update);
+    public AjaxResult updateResource(@RequestBody MaterialDTO materialDTO, HttpServletRequest request)throws Exception {
+        materialService.updateMaterial(materialDTO, request);
+        return  AjaxResult.success();
     }
 
     @DeleteMapping(value = "/delete")
@@ -397,6 +394,7 @@ public class MaterialController extends BaseController {
         return object;
     }
 
+
     /**
      * 根据商品id查找商品信息
      * @param meId
@@ -580,7 +578,7 @@ public class MaterialController extends BaseController {
      */
     @GetMapping(value = "/getMaterialByBarCode")
     @ApiOperation(value = "根据条码查询商品信息")
-    public BaseResponseInfo getMaterialByBarCode(@RequestParam("barCode") String barCode,
+    public BaseResponseInfo getMaterialByBarCode(@RequestParam("sku") String barCode,
                                                  @RequestParam(value = "organId", required = false) Long organId,
                                                  @RequestParam(value = "depotId", required = false) Long depotId,
                                                  @RequestParam("mpList") String mpList,
@@ -662,6 +660,69 @@ public class MaterialController extends BaseController {
     }
 
     /**
+     * 根据sku查询商品信息
+     * @return
+     * @throws Exception
+     */
+    @GetMapping(value = "/getMaterialBySku")
+    @ApiOperation(value = "根据条码查询商品信息")
+    public BaseResponseInfo getMaterialBySku(@RequestParam("sku") String barCode,
+                                             @RequestParam(value = "depotId", required = false) Long depotId,
+                                             @RequestParam(required = false, value = "prefixNo") String prefixNo,
+                                             HttpServletRequest request) throws Exception {
+        BaseResponseInfo res = new BaseResponseInfo();
+        try {
+            List<MaterialVo4Unit> list = materialService.getMaterialByBarCode(barCode);
+            if(list!=null && list.size()>0) {
+                for(MaterialVo4Unit mvo: list) {
+                    if ("LSCK".equals(prefixNo) || "LSTH".equals(prefixNo)) {
+                        //零售价
+                        mvo.setBillPrice(mvo.getCommodityDecimal());
+                    } else if ("CGDD".equals(prefixNo) || "CGRK".equals(prefixNo) || "CGTH".equals(prefixNo)) {
+                        //采购价
+                        mvo.setBillPrice(mvo.getDefaultPurchaseDecimal());
+                    } else if("QTRK".equals(prefixNo) || "DBCK".equals(prefixNo) || "ZZD".equals(prefixNo) || "CXD".equals(prefixNo)
+                            || "PDLR".equals(prefixNo) || "PDFP".equals(prefixNo)) {
+                        mvo.setBillPrice(mvo.getDefaultPurchaseDecimal());
+                    }
+                    if ("XSDD".equals(prefixNo) || "XSCK".equals(prefixNo) || "XSTH".equals(prefixNo) || "QTCK".equals(prefixNo)) {
+                        mvo.setBillPrice(mvo.getDefaultWholesaleDecimal());
+                    }
+                    //仓库id
+                    if (depotId == null) {
+                        JSONArray depotArr = depotService.findDepotByCurrentUser();
+                        for (Object obj : depotArr) {
+                            JSONObject depotObj = JSONObject.parseObject(obj.toString());
+                            if (depotObj.get("isDefault") != null) {
+                                Boolean isDefault = depotObj.getBoolean("isDefault");
+                                if (isDefault) {
+                                    Long id = depotObj.getLong("id");
+                                    if (!"CGDD".equals(prefixNo) && !"XSDD".equals(prefixNo)) {
+                                        //除订单之外的单据才有仓库
+                                        mvo.setDepotId(id);
+                                    }
+                                    getStockByMaterialInfo(mvo);
+                                }
+                            }
+                        }
+                    } else {
+                        mvo.setDepotId(depotId);
+                        getStockByMaterialInfo(mvo);
+                    }
+                    mvo.setInventory(mvo.getStock());
+                }
+            }
+            res.code = 200;
+            res.data = list;
+        } catch(Exception e){
+            logger.error(e.getMessage(), e);
+            res.code = 500;
+            res.data = "获取数据失败";
+        }
+        return res;
+    }
+
+    /**
      * 根据商品信息获取库存,进行赋值
      * @param mvo
      * @throws Exception

+ 57 - 46
src/main/java/com/jsh/erp/controller/MaterialExtendController.java

@@ -2,7 +2,9 @@ package com.jsh.erp.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.datasource.entities.MaterialExtend;
+import com.jsh.erp.datasource.vo.MaterialExtendVo;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import com.jsh.erp.service.MaterialExtendService;
 import com.jsh.erp.utils.BaseResponseInfo;
@@ -82,56 +84,65 @@ public class MaterialExtendController {
         return returnStr(objectMap, delete);
     }
 
+//    @GetMapping(value = "/getDetailList")
+//    @ApiOperation(value = "价格信息列表")
+//    public BaseResponseInfo getDetailList(@RequestParam("materialId") Long materialId,
+//                                          HttpServletRequest request)throws Exception {
+//        BaseResponseInfo res = new BaseResponseInfo();
+//        try {
+//            List<MaterialExtendVo4List> dataList = new ArrayList<MaterialExtendVo4List>();
+//            if(materialId!=0) {
+//                dataList = materialExtendService.getDetailList(materialId);
+//            }
+//            JSONObject outer = new JSONObject();
+//            outer.put("total", dataList.size());
+//            //存放数据json数组
+//            JSONArray dataArray = new JSONArray();
+//            if (null != dataList) {
+//                for (MaterialExtendVo4List md : dataList) {
+//                    JSONObject item = new JSONObject();
+//                    item.put("id", md.getId());
+//                    item.put("barCode", md.getBarCode());
+//                    item.put("commodityUnit", md.getCommodityUnit());
+//                    if(StringUtil.isNotEmpty(md.getSku())){
+//                        item.put("sku", md.getSku());
+//                    }
+//                    item.put("purchaseDecimal", md.getPurchaseDecimal());
+//                    item.put("commodityDecimal", md.getCommodityDecimal());
+//                    item.put("wholesaleDecimal", md.getWholesaleDecimal());
+//                    item.put("lowDecimal", md.getLowDecimal());
+//                    item.put("productionDate", md.getProductionDate() == null ? "": DateUtils.dateTime(md.getProductionDate()));
+//                    item.put("expiryNum",md.getExpiryNum());
+//                    item.put("supplierId",md.getSupplierId());
+//                    item.put("barCode",md.getBarCode());
+//                    item.put("batchNumber",md.getBatchNumber());
+//                    item.put("inventory",md.getInventory());
+//                    item.put("depotId",md.getDepotId());
+//                    item.put("position",md.getPosition());
+//                    item.put("ratio",md.getRatio());
+//                    dataArray.add(item);
+//                }
+//            }
+//            outer.put("rows", dataArray);
+//            res.code = 200;
+//            res.data = outer;
+//        } catch (Exception e) {
+//            logger.error(e.getMessage(), e);
+//            res.code = 500;
+//            res.data = "获取数据失败";
+//        }
+//        return res;
+//    }
+
     @GetMapping(value = "/getDetailList")
     @ApiOperation(value = "价格信息列表")
-    public BaseResponseInfo getDetailList(@RequestParam("materialId") Long materialId,
-                                          HttpServletRequest request)throws Exception {
-        BaseResponseInfo res = new BaseResponseInfo();
-        try {
-            List<MaterialExtendVo4List> dataList = new ArrayList<MaterialExtendVo4List>();
-            if(materialId!=0) {
-                dataList = materialExtendService.getDetailList(materialId);
-            }
-            JSONObject outer = new JSONObject();
-            outer.put("total", dataList.size());
-            //存放数据json数组
-            JSONArray dataArray = new JSONArray();
-            if (null != dataList) {
-                for (MaterialExtendVo4List md : dataList) {
-                    JSONObject item = new JSONObject();
-                    item.put("id", md.getId());
-                    item.put("barCode", md.getBarCode());
-                    item.put("commodityUnit", md.getCommodityUnit());
-                    if(StringUtil.isNotEmpty(md.getSku())){
-                        item.put("sku", md.getSku());
-                    }
-                    item.put("purchaseDecimal", md.getPurchaseDecimal());
-                    item.put("commodityDecimal", md.getCommodityDecimal());
-                    item.put("wholesaleDecimal", md.getWholesaleDecimal());
-                    item.put("lowDecimal", md.getLowDecimal());
-                    item.put("productionDate", md.getProductionDate() == null ? "": DateUtils.dateTime(md.getProductionDate()));
-                    item.put("expiryNum",md.getExpiryNum());
-                    item.put("supplierId",md.getSupplierId());
-                    item.put("barCode",md.getBarCode());
-                    item.put("batchNumber",md.getBatchNumber());
-                    item.put("inventory",md.getInventory());
-                    item.put("depotId",md.getDepotId());
-                    item.put("position",md.getPosition());
-                    item.put("ratio",md.getRatio());
-                    dataArray.add(item);
-                }
-            }
-            outer.put("rows", dataArray);
-            res.code = 200;
-            res.data = outer;
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-            res.code = 500;
-            res.data = "获取数据失败";
-        }
-        return res;
+    public AjaxResult getDetailList(@RequestParam("materialId") Long materialId) {
+        List<MaterialExtendVo> list = materialExtendService.getDetailList(materialId);
+        return AjaxResult.success(list);
     }
 
+
+
     /**
      * 根据条码查询商品信息
      * @param barCode

+ 18 - 34
src/main/java/com/jsh/erp/controller/UnitController.java

@@ -1,10 +1,10 @@
 package com.jsh.erp.controller;
 
 import com.alibaba.fastjson.JSONObject;
+import com.jsh.erp.base.AjaxResult;
 import com.jsh.erp.base.BaseController;
 import com.jsh.erp.base.TableDataInfo;
 import com.jsh.erp.datasource.entities.Unit;
-import com.jsh.erp.datasource.vo.UnitListVo;
 import com.jsh.erp.service.UnitService;
 import com.jsh.erp.utils.*;
 import io.swagger.annotations.Api;
@@ -15,8 +15,6 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
-import java.math.BigDecimal;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -55,8 +53,7 @@ public class UnitController extends BaseController {
 
     @GetMapping(value = "/list")
     @ApiOperation(value = "获取信息列表")
-    public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
-                                 HttpServletRequest request)throws Exception {
+    public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search)throws Exception {
         String name = StringUtil.getInfo(search, "name");
         List<Unit> list = unitService.select(name);
         return getDataTable(list);
@@ -64,18 +61,17 @@ public class UnitController extends BaseController {
 
     @PostMapping(value = "/add")
     @ApiOperation(value = "新增")
-    public String addResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
-        Map<String, Object> objectMap = new HashMap<>();
-        int insert = unitService.insertUnit(obj, request);
-        return returnStr(objectMap, insert);
+    public AjaxResult addResource(@RequestBody Unit unit, HttpServletRequest request)throws Exception {
+        int insert = unitService.insertUnit(unit, request);
+        return AjaxResult.success();
     }
 
     @PutMapping(value = "/update")
     @ApiOperation(value = "修改")
-    public String updateResource(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception {
+    public AjaxResult updateResource(@RequestBody Unit unit, HttpServletRequest request)throws Exception {
         Map<String, Object> objectMap = new HashMap<>();
-        int update = unitService.updateUnit(obj, request);
-        return returnStr(objectMap, update);
+        int update = unitService.updateUnit(unit, request);
+        return AjaxResult.success();
     }
 
     @DeleteMapping(value = "/delete")
@@ -96,30 +92,21 @@ public class UnitController extends BaseController {
 
     @GetMapping(value = "/checkIsNameExist")
     @ApiOperation(value = "检查名称是否存在")
-    public String checkIsNameExist(@RequestParam Long id, @RequestParam(value ="name", required = false) String name,
-                                   HttpServletRequest request)throws Exception {
-        Map<String, Object> objectMap = new HashMap<>();
-        int exist = unitService.checkIsNameExist(id, name);
+    public AjaxResult checkIsNameExist(@RequestParam(value ="name") String name) {
+        int exist = unitService.checkIsNameExist(name);
         if(exist > 0) {
-            objectMap.put("status", true);
-        } else {
-            objectMap.put("status", false);
+           return AjaxResult.error("单位名称已存在",true);
         }
-        return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
+        return AjaxResult.success("单位名称不存在",false);
     }
 
-    /**
-     * 单位列表
-     * @param request
-     * @return
-     * @throws Exception
-     */
+
     @GetMapping(value = "/getAllList")
     @ApiOperation(value = "单位列表")
-    public BaseResponseInfo getAllList(HttpServletRequest request) throws Exception{
+    public BaseResponseInfo getAllList() throws Exception{
         BaseResponseInfo res = new BaseResponseInfo();
         try {
-            List<Unit> unitList = unitService.getUnit();
+            List<Unit> unitList = unitService.unitList();
             res.code = 200;
             res.data = unitList;
         } catch(Exception e){
@@ -133,21 +120,18 @@ public class UnitController extends BaseController {
     /**
      * 批量设置状态-启用或者禁用
      * @param jsonObject
-     * @param request
      * @return
      */
     @PostMapping(value = "/batchSetStatus")
     @ApiOperation(value = "批量设置状态")
-    public String batchSetStatus(@RequestBody JSONObject jsonObject,
-                                 HttpServletRequest request)throws Exception {
+    public AjaxResult batchSetStatus(@RequestBody JSONObject jsonObject) {
         Boolean status = jsonObject.getBoolean("status");
         String ids = jsonObject.getString("ids");
-        Map<String, Object> objectMap = new HashMap<>();
         int res = unitService.batchSetStatus(status, ids);
         if(res > 0) {
-            return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
+            return AjaxResult.success();
         } else {
-            return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
+            return AjaxResult.error();
         }
     }
 

+ 1 - 1
src/main/java/com/jsh/erp/datasource/dto/DepotHeadDto.java → src/main/java/com/jsh/erp/datasource/dto/DepotHeadDTO.java

@@ -13,7 +13,7 @@ import java.util.List;
  * 单据信息
  */
 @Data
-public class DepotHeadDto {
+public class DepotHeadDTO {
 
     @ApiModelProperty("单据主表信息")
     private DepotHead info;

+ 5 - 1
src/main/java/com/jsh/erp/datasource/dto/MaterialDto.java → src/main/java/com/jsh/erp/datasource/dto/MaterialDTO.java

@@ -16,13 +16,17 @@ import java.util.List;
 public class MaterialDTO extends Material {
 
     @ApiModelProperty("商品条码信息")
-    private List<MaterialExtend> mbList;
+    private List<MaterialExtendDTO> meList;
 
     @ApiModelProperty("商品初始库存信息")
     private List<MaterialInitialStock> stock;
 
+    //以下字段去除
     private JSONArray sortList;
 
+    @ApiModelProperty("商品条码信息")
+    private List<MaterialExtend> mbList;
+
 
 
 }

+ 2 - 4
src/main/java/com/jsh/erp/datasource/dto/MaterialQueryDTO.java

@@ -2,6 +2,7 @@ package com.jsh.erp.datasource.dto;
 
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
 
@@ -9,7 +10,7 @@ import java.util.List;
 public class MaterialQueryDTO {
 
     @ApiModelProperty("商品类别ID")
-    private String categoryId;
+    private Long categoryId;
 
     @ApiModelProperty("关键字")
     private String materialParam;
@@ -59,7 +60,4 @@ public class MaterialQueryDTO {
     private String mpList;
 
 
-
-
-
 }

+ 12 - 8
src/main/java/com/jsh/erp/datasource/entities/Material.java

@@ -1,6 +1,8 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -19,6 +21,7 @@ import java.util.Map;
 public class Material {
 
     @ApiModelProperty("主键id")
+    @TableId(type = IdType.AUTO)
     private Long id;
 
     @ApiModelProperty("产品类型id")
@@ -60,8 +63,8 @@ public class Material {
     @ApiModelProperty("删除标记,0未删除,1删除")
     private String deleteFlag;
 
-    @ApiModelProperty("系统sku")
-    private String systemSku;
+    @ApiModelProperty("系统spu")
+    private String systemSpu;
 
     @ApiModelProperty("无动销提醒周期")
     private String movingPinReminderCycle;
@@ -78,6 +81,13 @@ public class Material {
     @ApiModelProperty("商品提醒")
     private String reminder;
 
+    @TableField(exist = false)
+    private List<MaterialExtend> list;
+
+    @TableField(exist = false)
+    private Map<Long,String> depotMap;
+
+    //以下字段去除
     @ApiModelProperty("型号")
     private String model;
 
@@ -99,12 +109,6 @@ public class Material {
     @ApiModelProperty("是否开启批号,0否,1是")
     private String enableBatchNumber;
 
-    @TableField(exist = false)
-    private List<MaterialExtend> list;
-
-    @TableField(exist = false)
-    private Map<Long,String> depotMap;
-
 
     public void setName(String name) {
         this.name = name == null ? null : name.trim();

+ 13 - 9
src/main/java/com/jsh/erp/datasource/entities/MaterialExtend.java

@@ -1,5 +1,7 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModelProperty;
@@ -18,11 +20,15 @@ import java.util.Date;
 public class MaterialExtend {
 
     @ApiModelProperty("主键id")
+    @TableId(type = IdType.AUTO)
     private Long id;
 
     @ApiModelProperty("商品id")
     private Long materialId;
 
+    @ApiModelProperty("sku")
+    private String sku;
+
     @ApiModelProperty("商品单位")
     private String commodityUnit;
 
@@ -48,12 +54,6 @@ public class MaterialExtend {
     @ApiModelProperty("删除标记,0未删除,1删除")
     private String deleteFlag;
 
-    @ApiModelProperty("商品条码")
-    private String barCode;
-
-    @ApiModelProperty("单位比例")
-    private Integer ratio;
-
     @ApiModelProperty("规格")
     private String standard;
 
@@ -69,9 +69,7 @@ public class MaterialExtend {
     @ApiModelProperty("启用 0-禁用  1-启用")
     private Boolean enabled;
 
-
-    @ApiModelProperty("商品属性")
-    private String sku;
+    //以下字段去除
 
     @ApiModelProperty("采购价格")
     private BigDecimal purchaseDecimal;
@@ -107,6 +105,12 @@ public class MaterialExtend {
     @ApiModelProperty("仓位货架")
     private String position;
 
+    @ApiModelProperty("单位比例")
+    private Integer ratio;
+
+    @ApiModelProperty("商品条码")
+    private String barCode;
+
     public void setBarCode(String barCode) {
         this.barCode = barCode == null ? null : barCode.trim();
     }

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

@@ -14,7 +14,6 @@ import java.util.List;
 @Accessors(chain = true)
 public class MaterialVo4Unit extends Material{
 
-
     private String unitName;
 
     private BigDecimal ratio;

+ 22 - 6
src/main/java/com/jsh/erp/datasource/entities/Unit.java

@@ -1,12 +1,34 @@
 package com.jsh.erp.datasource.entities;
 
+import com.baomidou.mybatisplus.annotation.TableName;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
 import java.math.BigDecimal;
 
+/**
+ * 多单位实体类
+ */
+@Data
+@TableName("jsh_unit")
 public class Unit {
+
+    @ApiModelProperty("主键id")
     private Long id;
 
+    @ApiModelProperty("单位名称")
     private String name;
 
+    @ApiModelProperty("启用")
+    private Boolean enabled;
+
+    @ApiModelProperty("租户id")
+    private Long tenantId;
+
+    @ApiModelProperty("删除标记,0未删除,1删除")
+    private String deleteFlag;
+
+    //以下字段去除
     private String basicUnit;
 
     private String otherUnit;
@@ -21,12 +43,6 @@ public class Unit {
 
     private BigDecimal ratioThree;
 
-    private Boolean enabled;
-
-    private Long tenantId;
-
-    private String deleteFlag;
-
     public Long getId() {
         return id;
     }

+ 6 - 2
src/main/java/com/jsh/erp/datasource/mappers/MaterialExtendMapperEx.java

@@ -2,6 +2,7 @@ package com.jsh.erp.datasource.mappers;
 
 import com.jsh.erp.datasource.entities.DepotItem;
 import com.jsh.erp.datasource.entities.MaterialExtend;
+import com.jsh.erp.datasource.vo.MaterialExtendVo;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import org.apache.ibatis.annotations.Param;
 
@@ -16,8 +17,11 @@ public interface MaterialExtendMapperEx {
      */
     int batchDeleteMaterialExtendByIds(@Param("ids") String ids[]);
 
-    List<MaterialExtendVo4List> getDetailList(
-            @Param("materialId") Long materialId);
+    /**
+     * 根据商品ID获取拓展信息明细
+     * @param materialId 商品id
+     */
+    List<MaterialExtendVo> getDetailList(@Param("materialId") Long materialId);
 
     Long getMaxTimeByTenantAndTime(
             @Param("tenantId") Long tenantId,

+ 2 - 3
src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java

@@ -1,9 +1,11 @@
 package com.jsh.erp.datasource.mappers;
 
+import com.jsh.erp.datasource.dto.MaterialQueryDTO;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
 import com.jsh.erp.datasource.pda.vo.PDAPrintVo;
+import com.jsh.erp.datasource.vo.MaterialAndExtendVo;
 import com.jsh.erp.datasource.vo.MaterialCurrentStock4SystemSku;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
 import com.jsh.erp.datasource.vo.TaskStocktakingItemVO;
@@ -27,13 +29,10 @@ public interface MaterialMapperEx {
             @Param("model") String model,
             @Param("color") String color,
             @Param("brand") String brand,
-            @Param("mfrs") String mfrs,
             @Param("materialOther") String materialOther,
             @Param("weight") String weight,
             @Param("expiryNum") String expiryNum,
             @Param("enableSerialNumber") String enableSerialNumber,
-            @Param("enableBatchNumber") String enableBatchNumber,
-            @Param("position") String position,
             @Param("enabled") String enabled,
             @Param("remark") String remark,
             @Param("idList") List<Long> idList,

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

@@ -5,7 +5,7 @@ import com.jsh.erp.datasource.entities.UnitExample;
 import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
-public interface UnitMapper {
+public interface UnitMapper extends BaseMapperX<Unit> {
     long countByExample(UnitExample example);
 
     int deleteByExample(UnitExample example);

+ 36 - 0
src/main/java/com/jsh/erp/datasource/vo/MaterialAndExtendVo.java

@@ -0,0 +1,36 @@
+package com.jsh.erp.datasource.vo;
+
+import com.jsh.erp.datasource.entities.Material;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 商品及拓展信息
+ */
+@Data
+public class MaterialAndExtendVo extends Material {
+
+    @ApiModelProperty("sku")
+    private String sku;
+
+    @ApiModelProperty("类型名称")
+    private String categoryName;
+
+    @ApiModelProperty("型号")
+    private String model;
+
+    @ApiModelProperty("颜色")
+    private String color;
+
+    @ApiModelProperty("品牌")
+    private String brand;
+
+    @ApiModelProperty("单位")
+    private String commodityUnit;
+
+    @ApiModelProperty("库存")
+    private BigDecimal stock;
+
+}

+ 20 - 0
src/main/java/com/jsh/erp/datasource/vo/MaterialExtendVo.java

@@ -0,0 +1,20 @@
+package com.jsh.erp.datasource.vo;
+
+import com.jsh.erp.datasource.entities.MaterialExtend;
+import com.jsh.erp.datasource.entities.MaterialUnit;
+import com.jsh.erp.datasource.entities.MaterialUpc;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class MaterialExtendVo extends MaterialExtend {
+
+    @ApiModelProperty("商品UPC集合")
+    private List<MaterialUpc> upcList;
+
+    @ApiModelProperty("商品单位集合")
+    private List<MaterialUnit> unitList;
+
+}

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

@@ -30,7 +30,7 @@ public interface LogService extends IService<Log> {
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int batchDeleteLog(String ids, HttpServletRequest request)throws Exception;
 
-    void insertLog(String moduleName, String content, HttpServletRequest request)throws Exception;
+    void insertLog(String moduleName, String content, HttpServletRequest request);
 
     void insertLogWithUserId(Long userId, Long tenantId, String moduleName, String content, HttpServletRequest request)throws Exception;
 }

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

@@ -2,7 +2,9 @@ package com.jsh.erp.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.dto.MaterialExtendDTO;
 import com.jsh.erp.datasource.entities.MaterialExtend;
+import com.jsh.erp.datasource.vo.MaterialExtendVo;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -12,23 +14,57 @@ import java.util.List;
 public interface MaterialExtendService extends IService<MaterialExtend> {
     MaterialExtend getMaterialExtend(long id)throws Exception;
 
-    List<MaterialExtendVo4List> getDetailList(Long materialId);
+    /**
+     * 根据产品id查询产品价格拓展信息
+     * @param materialId 商品ID
+     */
+    List<MaterialExtendVo> getDetailList(Long materialId);
 
     List<MaterialExtend> getListByMIds(List<Long> idList);
 
+    /**
+     * 保存商品拓展信息
+     * @param materialExtends 商品拓展信息
+     * @param sortList
+     * @param materialId 商品id
+     * @param type 操作类型
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     String saveDetails(List<MaterialExtend> materialExtends, String sortList, Long materialId, String type) throws Exception;
 
     /**
+     * 保存商品拓展信息
+     * @param materialExtends 商品拓展信息
+     * @param materialId 商品id
+     * @param type 操作类型
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    String saveDetails(List<MaterialExtendDTO> materialExtends, Long materialId, String type);
+
+    /**
      *  添加商品子信息
      * @param materialExtend 商品子信息
      */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int insertMaterialExtend(MaterialExtend materialExtend)throws Exception;
 
+    /**
+     *  添加商品子信息
+     * @param materialExtendDTO 商品子信息
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int insertMaterialExtend(MaterialExtendDTO materialExtendDTO);
+
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int updateMaterialExtend(MaterialExtend materialExtend) throws Exception;
 
+    /**
+     *  修改商品子信息
+     * @param materialExtendDTO 商品子信息
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int updateMaterialExtend(MaterialExtendDTO materialExtendDTO);
+
     int checkIsBarCodeExist(Long id, String barCode)throws Exception;
 
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)

+ 39 - 8
src/main/java/com/jsh/erp/service/MaterialService.java

@@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.jsh.erp.datasource.dto.MaterialDTO;
+import com.jsh.erp.datasource.dto.MaterialQueryDTO;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.vo.MaterialAndExtendVo;
 import com.jsh.erp.datasource.vo.MaterialCurrentStock4SystemSku;
 import com.jsh.erp.datasource.pda.vo.PDATypeTree;
 import com.jsh.erp.datasource.vo.MaterialWarnListVo;
@@ -31,25 +33,29 @@ public interface MaterialService extends IService<Material> {
     /**
      * 查询商品管理-商品信息列表查询
      */
-    List<MaterialVo4Unit> select(String materialParam, String standard, String model, String color, String brand, String mfrs,
+    List<MaterialVo4Unit> select(String materialParam, String standard, String model, String color, String brand,
                                  String materialOther, String weight, String expiryNum, String enableSerialNumber,
-                                 String enableBatchNumber, String position, String enabled, String remark, String categoryId,
+                                 String enabled, String remark, String categoryId,
                                  String mpList, String reminder);
 
     /**
      * 新增商品
-     * @param obj
+     * @param materialDTO
      */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    int insertMaterial(MaterialDTO obj, HttpServletRequest request)throws Exception;
+    boolean insertMaterial(MaterialDTO materialDTO, HttpServletRequest request);
 
     /**
      * 修改商品
-     * @param obj
+     * @param materialDTO
      */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    int updateMaterial(MaterialDTO obj, HttpServletRequest request) throws Exception;
+    boolean updateMaterial(MaterialDTO materialDTO, HttpServletRequest request);
 
+    /**
+     * 删除商品
+     * @param id 商品id
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     int deleteMaterial(Long id, HttpServletRequest request)throws Exception;
 
@@ -79,10 +85,35 @@ public interface MaterialService extends IService<Material> {
 
     JSONArray getMaterialByParam(String materialParam);
 
+    /**
+     * 商品选择-查找商品信息
+     * @param categoryId
+     * @param q
+     * @param standardOrModel
+     * @param color
+     * @param brand
+     * @param mfrs
+     * @param enableSerialNumber
+     * @param enableBatchNumber
+     * @param offset
+     * @param rows
+     * @param depotId
+     * @return
+     * @throws Exception
+     */
     List<MaterialVo4Unit> findBySelectWithBarCode(Long categoryId, String q, String standardOrModel, String color,
                                                   String brand, String mfrs, String enableSerialNumber, String enableBatchNumber,
                                                   Integer offset, Integer rows, Long depotId) throws Exception;
 
+    /**
+     * 商品选择-查找商品信息
+     * @param offset
+     * @param rows
+     * @return
+     * @throws Exception
+     */
+    List<MaterialVo4Unit> findBySelectWithBarCode(MaterialQueryDTO materialQueryDTO, Integer offset, Integer rows) throws Exception;
+
     int findBySelectWithBarCodeCount(Long categoryId, String q, String standardOrModel, String color,
                                      String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Long depotId) throws Exception;
 
@@ -149,8 +180,8 @@ public interface MaterialService extends IService<Material> {
     List<String> getMaterialNameList();
 
     /**
-     * 根据条码查询商品信息
-     * @param barCode 商品条码
+     * 根据sku查询商品信息
+     * @param barCode 商品sku
      */
     List<MaterialVo4Unit> getMaterialByBarCode(String barCode);
 

+ 21 - 0
src/main/java/com/jsh/erp/service/MaterialUnitService.java

@@ -0,0 +1,21 @@
+package com.jsh.erp.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.entities.MaterialUnit;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface MaterialUnitService extends IService<MaterialUnit> {
+
+    /**
+     * 保存商品单位
+     * @param units 商品单位集合
+     * @param meId  商品拓展id
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    Boolean saveDetails(List<MaterialUnit> units, Long meId);
+
+    int batchDeleteMaterialUnitByMIds();
+
+}

+ 21 - 0
src/main/java/com/jsh/erp/service/MaterialUpcService.java

@@ -0,0 +1,21 @@
+package com.jsh.erp.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jsh.erp.datasource.entities.MaterialUnit;
+import com.jsh.erp.datasource.entities.MaterialUpc;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface MaterialUpcService extends IService<MaterialUpc> {
+
+    /**
+     * 保存商品UPC
+     * @param upcList 商品UPC集合
+     * @param meId  商品拓展id
+     */
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    Boolean saveDetails(List<MaterialUpc> upcList, Long meId);
+
+
+}

+ 2 - 2
src/main/java/com/jsh/erp/service/SyncTescoSystemService.java

@@ -104,7 +104,7 @@ public class SyncTescoSystemService {
                 for (MaterialVo4Unit material : materialList) {
                     JSONObject item = new JSONObject();
                     item.put("barCode", material.getmBarCode());
-                    item.put("systemSku", material.getSystemSku());
+                    item.put("systemSku", material.getSystemSpu());
                     dataArray.add(item);
                 }
             } else {
@@ -383,7 +383,7 @@ public class SyncTescoSystemService {
         // 1. 获取所有商品信息
         List<String> systemSkuList = reqVOItems.stream().map(ErpXsddReqVO.OrderItem::getErpSku).collect(Collectors.toList());
         List<MaterialVo4Unit> materialList = materialService.getMaterialBySystemSku(systemSkuList);
-        Map<String, List<MaterialVo4Unit>> skuToMaterialMap = materialList.stream().collect(Collectors.groupingBy(MaterialVo4Unit::getSystemSku));
+        Map<String, List<MaterialVo4Unit>> skuToMaterialMap = materialList.stream().collect(Collectors.groupingBy(MaterialVo4Unit::getSystemSpu));
 
         // 2. 处理每个订单项
         for (ErpXsddReqVO.OrderItem reqVOItem : reqVOItems) {

+ 44 - 291
src/main/java/com/jsh/erp/service/UnitService.java

@@ -1,325 +1,78 @@
 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.Unit;
-import com.jsh.erp.datasource.entities.UnitExample;
-import com.jsh.erp.datasource.entities.User;
-import com.jsh.erp.datasource.mappers.MaterialMapperEx;
-import com.jsh.erp.datasource.mappers.UnitMapper;
-import com.jsh.erp.datasource.mappers.UnitMapperEx;
-import com.jsh.erp.datasource.vo.UnitListVo;
-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.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
-@Service
-public class UnitService {
-    private Logger logger = LoggerFactory.getLogger(UnitService.class);
+public interface UnitService extends IService<Unit> {
 
-    @Resource
-    private UnitMapper unitMapper;
+    Unit getUnit(long id);
 
-    @Resource
-    private UnitMapperEx unitMapperEx;
-    @Resource
-    private UserService userService;
-    @Resource
-    private LogService logService;
-    @Resource
-    private MaterialMapperEx materialMapperEx;
-
-    public Unit getUnit(long id)throws Exception {
-        Unit result=null;
-        try{
-            result=unitMapper.selectByPrimaryKey(id);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return result;
-    }
-
-    public List<Unit> getUnitListByIds(String ids)throws Exception {
-        List<Long> idList = StringUtil.strToLongList(ids);
-        List<Unit> list = new ArrayList<>();
-        try{
-            UnitExample example = new UnitExample();
-            example.createCriteria().andIdIn(idList);
-            list = unitMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Unit> getUnit()throws Exception {
-        UnitExample example = new UnitExample();
-        example.createCriteria().andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Unit> list=null;
-        try{
-            list=unitMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    public List<Unit> select(String name)throws Exception {
-        List<Unit> list=null;
-        try{
-            PageUtils.startPage();
-            list=unitMapperEx.selectByConditionUnit(name);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list;
-    }
-
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int insertUnit(JSONObject obj, HttpServletRequest request)throws Exception {
-        Unit unit = JSONObject.parseObject(obj.toJSONString(), Unit.class);
-        int result=0;
-        try{
-            parseNameByUnit(unit);
-            unit.setEnabled(true);
-            result=unitMapper.insertSelective(unit);
-            logService.insertLog("多单位",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(unit.getName()).toString(), request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
-
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int updateUnit(JSONObject obj, HttpServletRequest request)throws Exception {
-        Unit unit = JSONObject.parseObject(obj.toJSONString(), Unit.class);
-        int result=0;
-        try{
-            parseNameByUnit(unit);
-            result=unitMapper.updateByPrimaryKeySelective(unit);
-            if(unit.getRatioTwo()==null) {
-                unitMapperEx.updateRatioTwoById(unit.getId());
-            }
-            if(unit.getRatioThree()==null) {
-                unitMapperEx.updateRatioThreeById(unit.getId());
-            }
-            logService.insertLog("多单位",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(unit.getName()).toString(), request);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    List<Unit> getUnitListByIds(String ids)throws Exception;
 
     /**
-     * 根据单位信息生成名称的格式
-     * @param unit
+     * 所有单位集合
      */
-    private void parseNameByUnit(Unit unit) {
-        String unitName = unit.getBasicUnit() + "/" + "(" +  unit.getOtherUnit() + "=" + unit.getRatio().toString() + unit.getBasicUnit() + ")";
-        if(StringUtil.isNotEmpty(unit.getOtherUnitTwo()) && unit.getRatioTwo()!=null) {
-            unitName += "/" + "(" + unit.getOtherUnitTwo() + "=" + unit.getRatioTwo().toString() + unit.getBasicUnit() + ")";
-            if(StringUtil.isNotEmpty(unit.getOtherUnitThree()) && unit.getRatioThree()!=null) {
-                unitName += "/" + "(" + unit.getOtherUnitThree() + "=" + unit.getRatioThree().toString() + unit.getBasicUnit() + ")";
-            }
-        }
-        unit.setName(unitName);
-    }
-
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int deleteUnit(Long id, HttpServletRequest request)throws Exception {
-        return batchDeleteUnitByIds(id.toString());
-    }
+    List<Unit> unitList()throws Exception;
 
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteUnit(String ids, HttpServletRequest request) throws Exception{
-        return batchDeleteUnitByIds(ids);
-    }
+    List<Unit> select(String name)throws Exception;
 
+    /**
+     * 新增单位
+     * @param unit 单位
+     */
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteUnitByIds(String ids)throws Exception {
-        int result=0;
-        String [] idArray=ids.split(",");
-        //校验产品表	jsh_material
-        List<Material> materialList=null;
-        try{
-            materialList=materialMapperEx.getMaterialListByUnitIds(idArray);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        if(materialList!=null&&materialList.size()>0){
-            logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
-                    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<Unit> list = getUnitListByIds(ids);
-        for(Unit unit: list){
-            sb.append("[").append(unit.getName()).append("]");
-        }
-        logService.insertLog("多单位", sb.toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        User userInfo=userService.getCurrentUser();
-        //校验通过执行删除操作
-        try{
-            result=unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
-
-    public int checkIsNameExist(Long id, String name)throws Exception {
-        UnitExample example = new UnitExample();
-        example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Unit> list=null;
-        try{
-            list=unitMapper.selectByExample(example);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
-        }
-        return list==null?0:list.size();
-    }
+    int insertUnit(Unit unit, HttpServletRequest request)throws Exception;
 
     /**
-     * 根据条件查询单位id
-     * @param basicUnit
-     * @param otherUnit
-     * @param ratio
-     * @return
+     * 修改单位
+     * @param unit 单位
      */
-    public Long getUnitIdByParam(String basicUnit, String otherUnit, BigDecimal ratio){
-        Long unitId = null;
-        UnitExample example = new UnitExample();
-        example.createCriteria().andBasicUnitEqualTo(basicUnit).andOtherUnitEqualTo(otherUnit).andRatioEqualTo(ratio)
-                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
-        List<Unit> list = unitMapper.selectByExample(example);
-        if(list!=null && list.size()>0) {
-            unitId = list.get(0).getId();
-        }
-        return unitId;
-    }
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int updateUnit(Unit unit, HttpServletRequest request)throws Exception;
 
     /**
-     * 根据多单位的比例进行库存换算(保留两位小数)
-     * @param stock
-     * @param unitInfo
-     * @param materialUnit
-     * @return
+     * 删除单位
+     * @param id 单位id
+     * @param request
      */
-    public BigDecimal parseStockByUnit(BigDecimal stock, Unit unitInfo, String materialUnit) {
-        if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
-            stock = stock.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
-        }
-        if(materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo()!=null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO)!=0) {
-            stock = stock.divide(unitInfo.getRatioTwo(),2,BigDecimal.ROUND_HALF_UP);
-        }
-        if(materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree()!=null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO)!=0) {
-            stock = stock.divide(unitInfo.getRatioThree(),2,BigDecimal.ROUND_HALF_UP);
-        }
-        return stock;
-    }
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int deleteUnit(Long id, HttpServletRequest request);
 
     /**
-     * 根据多单位的比例进行单价换算(保留两位小数),变大
-     * @param unitPrice
-     * @param unitInfo
-     * @param materialUnit
-     * @return
+     * 批量删除单位
+     * @param ids 单位id字符集
+     * @param request
      */
-    public BigDecimal parseUnitPriceByUnit(BigDecimal unitPrice, Unit unitInfo, String materialUnit) {
-        if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
-            unitPrice = unitPrice.multiply(unitInfo.getRatio());
-        }
-        if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
-            unitPrice = unitPrice.multiply(unitInfo.getRatioTwo());
-        }
-        if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
-            unitPrice = unitPrice.multiply(unitInfo.getRatioThree());
-        }
-        return unitPrice;
-    }
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int batchDeleteUnit(String ids, HttpServletRequest request) throws Exception;
 
     /**
-     * 根据多单位的比例进行总金额换算(保留两位小数),变小
-     * @param allPrice
-     * @param unitInfo
-     * @param materialUnit
-     * @return
+     * 检查单位名称是否存在
+     * @param name 单位名称
+     * @return 单位数量
      */
-    public BigDecimal parseAllPriceByUnit(BigDecimal allPrice, Unit unitInfo, String materialUnit) {
-        if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
-            allPrice = allPrice.divide(unitInfo.getRatio(), 2, BigDecimal.ROUND_HALF_UP);
-        }
-        if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
-            allPrice = allPrice.divide(unitInfo.getRatioTwo(), 2, BigDecimal.ROUND_HALF_UP);
-        }
-        if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
-            allPrice = allPrice.divide(unitInfo.getRatioThree(), 2, BigDecimal.ROUND_HALF_UP);
-        }
-        return allPrice;
-    }
+    int checkIsNameExist(String name);
 
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchSetStatus(Boolean status, String ids)throws Exception {
-        logService.insertLog("多单位",
-                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
-                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
-        List<Long> unitIds = StringUtil.strToLongList(ids);
-        Unit unit = new Unit();
-        unit.setEnabled(status);
-        UnitExample example = new UnitExample();
-        example.createCriteria().andIdIn(unitIds);
-        int result=0;
-        try{
-            result = unitMapper.updateByExampleSelective(unit, example);
-        }catch(Exception e){
-            JshException.writeFail(logger, e);
-        }
-        return result;
-    }
+    Long getUnitIdByParam(String basicUnit, String otherUnit, BigDecimal ratio);
+
+    BigDecimal parseStockByUnit(BigDecimal stock, Unit unitInfo, String materialUnit);
+
+    BigDecimal parseUnitPriceByUnit(BigDecimal unitPrice, Unit unitInfo, String materialUnit);
+
+    BigDecimal parseAllPriceByUnit(BigDecimal allPrice, Unit unitInfo, String materialUnit);
 
     /**
-     * 根据单位id获取单位值集合
-     * @param id 单位id
+     * 批量设置状态
+     * @param status 状态
+     * @param ids 单位id
      */
-    public List getUnitListByID(Long id){
-        Unit unit = unitMapper.selectByPrimaryKey(id);
-        List<UnitListVo> list = new ArrayList();
-        UnitListVo unitListVo = new UnitListVo().setName(unit.getBasicUnit()).setRatio(new BigDecimal("1"));
-        list.add(unitListVo);
-        if (unit.getOtherUnit() != null){
-            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnit()).setRatio(unit.getRatio());
-            list.add(vo);
-        }
-        if (unit.getOtherUnitTwo() != null){
-            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnitTwo()).setRatio(unit.getRatioTwo());
-            list.add(vo);
-        }
-        if (unit.getOtherUnitThree() != null){
-            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnitThree()).setRatio(unit.getRatioThree());
-            list.add(vo);
-        }
-        return list;
-    }
+    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
+    int batchSetStatus(Boolean status, String ids);
+
+    List getUnitListByID(Long id);
 }

+ 2 - 2
src/main/java/com/jsh/erp/service/UserService.java

@@ -15,7 +15,7 @@ import java.util.List;
 import java.util.Map;
 
 public interface UserService extends IService<User> {
-    User getUser(long id)throws Exception;
+    User getUser(long id);
 
     /**
      * 生成用户下拉框
@@ -61,7 +61,7 @@ public interface UserService extends IService<User> {
 
     int checkIsNameExist(Long id, String name)throws Exception;
 
-    User getCurrentUser()throws Exception;
+    User getCurrentUser();
 
     Long getIdByLoginName(String loginName);
 

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

@@ -2,8 +2,6 @@ package com.jsh.erp.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jsh.erp.constants.BusinessConstants;
 import com.jsh.erp.constants.ExceptionConstants;
@@ -21,8 +19,6 @@ import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
 import com.jsh.erp.query.LambdaQueryWrapperX;
 import com.jsh.erp.service.*;
-import com.jsh.erp.utils.DateUtils;
-import com.jsh.erp.utils.HttpClient;
 import com.jsh.erp.utils.StringUtil;
 import com.jsh.erp.utils.Tools;
 import org.slf4j.Logger;
@@ -34,7 +30,6 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
-import java.sql.Timestamp;
 import java.util.*;
 
 @Service

+ 1 - 1
src/main/java/com/jsh/erp/service/impl/LogServiceImpl.java

@@ -140,7 +140,7 @@ public class LogServiceImpl extends ServiceImpl<LogMapper, Log> implements LogSe
     }
 
     @Override
-    public void insertLog(String moduleName, String content, HttpServletRequest request)throws Exception{
+    public void insertLog(String moduleName, String content, HttpServletRequest request){
         try{
             Long userId = userService.getUserId(request);
             if(userId!=null) {

+ 144 - 7
src/main/java/com/jsh/erp/service/impl/MaterialExtendServiceImpl.java

@@ -4,13 +4,17 @@ 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.dto.MaterialExtendDTO;
 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.MaterialExtendVo;
 import com.jsh.erp.datasource.vo.MaterialExtendVo4List;
 import com.jsh.erp.exception.BusinessRunTimeException;
 import com.jsh.erp.exception.JshException;
+import com.jsh.erp.query.LambdaQueryWrapperX;
+import com.jsh.erp.query.QueryWrapperX;
 import com.jsh.erp.service.*;
 import com.jsh.erp.utils.DateUtils;
 import com.jsh.erp.utils.RandomHelper;
@@ -51,6 +55,11 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     @Resource
     private SyncTescoSystemService syncTescoSystemService;
 
+    @Resource
+    private MaterialUnitService materialUnitService;
+    @Resource
+    private MaterialUpcService materialUpcService;
+
     @Override
     public MaterialExtend getMaterialExtend(long id)throws Exception {
         MaterialExtend result=null;
@@ -67,12 +76,11 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
      * @param materialId 产品id
      */
     @Override
-    public List<MaterialExtendVo4List> getDetailList(Long materialId) {
-        List<MaterialExtendVo4List> list=null;
-        try{
-            list = materialExtendMapperEx.getDetailList(materialId);
-        }catch(Exception e){
-            JshException.readFail(logger, e);
+    public List<MaterialExtendVo> getDetailList(Long materialId) {
+        List<MaterialExtendVo> list = materialExtendMapperEx.getDetailList(materialId);
+        for (MaterialExtendVo materialExtendVo : list) {
+            materialExtendVo.setUnitList(materialUnitService.list(new LambdaQueryWrapperX<MaterialUnit>().eq(MaterialUnit::getMaterialExtendId,materialExtendVo.getId()).eq(MaterialUnit::getDeleteFlag,false)));
+            materialExtendVo.setUpcList(materialUpcService.list(new LambdaQueryWrapperX<MaterialUpc>().eq(MaterialUpc::getMaterialExtendId,materialExtendVo.getId()).eq(MaterialUpc::getDeleteFlag,false)));
         }
         return list;
     }
@@ -265,6 +273,12 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
 //    }
 
 
+    /**
+     * 保存商品拓展信息
+     * @param materialExtends 商品拓展信息
+     * @param materialId 商品id
+     * @param type 操作类型
+     */
     @Override
     public String saveDetails(List<MaterialExtend> materialExtends, String sortList, Long materialId, String type) throws Exception {
         //添加商品条码集合
@@ -323,6 +337,69 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     }
 
     /**
+     * 保存商品拓展信息
+     * @param materialExtends 商品拓展信息
+     * @param materialId      商品id
+     * @param type            操作类型
+     */
+    @Override
+    public String saveDetails(List<MaterialExtendDTO> materialExtends, Long materialId, String type) {
+        //添加商品条码集合
+        List<MaterialExtendDTO> insertedList = new ArrayList<>();
+        //修改商品条码集合
+        List<MaterialExtendDTO> updatedList = new ArrayList<>();
+        //添加/修改行数据处理
+        if (null != materialExtends) {
+            if("insert".equals(type)){
+                for (int i = 0; i < materialExtends.size(); i++) {
+                    MaterialExtendDTO materialExtend = materialExtends.get(i);
+                    insertedList.add(materialExtend);
+                }
+            } else if("update".equals(type)){
+                for (int i = 0; i < materialExtends.size(); i++) {
+                    MaterialExtendDTO materialExtend = materialExtends.get(i);
+                    Long id = materialExtend.getId();
+                    if(id != null && id > 0){
+                        //id不等于空并且大于0,属于修改数据
+                        updatedList.add(materialExtend);
+                    } else {
+                        insertedList.add(materialExtend);
+                    }
+                }
+            }
+        }
+        //添加条码
+        if (!insertedList.isEmpty()) {
+            for (MaterialExtendDTO materialExtend : insertedList) {
+                //EXCEL中有条码在系统中已存在
+//                MaterialExtend me = getInfoByBarCode(materialExtend.getBarCode());
+//                if (me != null && !me.getBarCode().isEmpty()) {
+//                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_PROPERTY_BARCODE_EXIST_CODE,
+//                            String.format(ExceptionConstants.MATERIAL_PROPERTY_BARCODE_EXIST_MSG, materialExtend.getBarCode()));
+//                }
+                //设置商品id
+                materialExtend.setMaterialId(materialId);
+                //添加数据
+                this.insertMaterialExtend(materialExtend);
+            }
+        }
+        //修改拓展行
+        if (!updatedList.isEmpty()) {
+            for (MaterialExtendDTO materialExtend : updatedList) {
+                //新条码和原来条码不一致,判断新条码是否已存在
+//                MaterialExtend me = getInfoByBarCode(materialExtend.getBarCode());
+//                if (me != null && !materialExtend.getId().equals(me.getId())) {
+//                    throw new BusinessRunTimeException(ExceptionConstants.MATERIAL_PROPERTY_BARCODE_EXIST_CODE,
+//                            String.format(ExceptionConstants.MATERIAL_PROPERTY_BARCODE_EXIST_MSG, materialExtend.getBarCode()));
+//                }
+                //修改商品拓展
+                this.updateMaterialExtend(materialExtend);
+            }
+        }
+        return null;
+    }
+
+    /**
      * 添加商品拓展
      * @param materialExtend 商品拓展
      */
@@ -340,6 +417,30 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     }
 
     /**
+     * 添加商品子信息
+     * @param materialExtendDTO 商品子信息
+     */
+    @Override
+    public int insertMaterialExtend(MaterialExtendDTO materialExtendDTO) {
+        MaterialExtend materialExtend = materialExtendDTO;
+        User user = userService.getCurrentUser();
+        //设置sku
+        materialExtend.setSku(getSku(materialExtend.getMaterialId()));
+        //设置是否为默认单位
+        materialExtend.setDeleteFlag(BusinessConstants.DELETE_FLAG_EXISTS);
+        //创建时间
+        materialExtend.setCreateTime(new Date());
+        //创建用户
+        materialExtend.setCreateSerial(user.getLoginName());
+        int i = materialExtendMapper.insertSelective(materialExtend);
+        //保存商品单位
+        materialUnitService.saveDetails(materialExtendDTO.getUnitList(),materialExtend.getId());
+        //保存商品upc
+        materialUpcService.saveDetails(materialExtendDTO.getUpcList(),materialExtend.getId());
+        return i;
+    }
+
+    /**
      * 修改商品拓展
      * @param materialExtend 商品拓展
      */
@@ -352,6 +453,24 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         return materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
     }
 
+    /**
+     * 修改商品子信息
+     * @param materialExtendDTO 商品子信息
+     */
+    @Override
+    public int updateMaterialExtend(MaterialExtendDTO materialExtendDTO) {
+        MaterialExtend materialExtend = materialExtendDTO;
+        User user = userService.getCurrentUser();
+        materialExtend.setUpdateTime(System.currentTimeMillis());
+        materialExtend.setUpdateSerial(user.getLoginName());
+        materialExtendMapper.updateByPrimaryKeySelective(materialExtend);
+        //保存商品单位
+        materialUnitService.saveDetails(materialExtendDTO.getUnitList(),materialExtend.getId());
+        //保存商品upc
+        materialUpcService.saveDetails(materialExtendDTO.getUpcList(),materialExtend.getId());
+        return 0;
+    }
+
     @Override
     public int checkIsBarCodeExist(Long id, String barCode)throws Exception {
         MaterialExtendExample example = new MaterialExtendExample();
@@ -488,7 +607,7 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
     }
 
     @Override
-    public MaterialExtend getInfoByBarCode(String barCode)throws Exception {
+    public MaterialExtend getInfoByBarCode(String barCode) {
         MaterialExtendExample example = new MaterialExtendExample();
         example.createCriteria().andBarCodeLike(barCode).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
         List<MaterialExtend> list = materialExtendMapper.selectByExample(example);
@@ -631,5 +750,23 @@ public class MaterialExtendServiceImpl extends ServiceImpl<MaterialExtendMapper,
         }
     }
 
+    /**
+     * 获取sku
+     * @param mid 商品id
+     */
+    private String getSku(Long mid){
+        MaterialExtend materialExtend = getOne(new LambdaQueryWrapperX<MaterialExtend>()
+                .eq(MaterialExtend::getMaterialId,mid).eq(MaterialExtend::getDeleteFlag,"0")
+                .orderByDesc(MaterialExtend::getId));
+        if (materialExtend == null){
+            Material material = materialService.getMaterialById(mid);
+            return material.getSystemSpu() + "01";
+        }else {
+            String sku = materialExtend.getSku();
+            int i = Integer.parseInt(sku.substring(sku.length() - 2));
+            return sku.substring(0,sku.length()-2) + String.format("%02d", i + 1);
+        }
+    }
+
 
 }

+ 73 - 61
src/main/java/com/jsh/erp/service/impl/MaterialServiceImpl.java

@@ -9,10 +9,12 @@ 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.dto.MaterialDTO;
+import com.jsh.erp.datasource.dto.MaterialQueryDTO;
 import com.jsh.erp.datasource.entities.*;
 import com.jsh.erp.datasource.mappers.*;
 import com.jsh.erp.datasource.pda.dto.PDAInventoryDTO;
 import com.jsh.erp.datasource.pda.vo.PDADepotItemVO;
+import com.jsh.erp.datasource.vo.MaterialAndExtendVo;
 import com.jsh.erp.datasource.vo.MaterialCurrentStock4SystemSku;
 import com.jsh.erp.datasource.pda.vo.PDATypeTree;
 import com.jsh.erp.datasource.vo.MaterialVoSearch;
@@ -107,7 +109,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
     }
 
     @Override
-    public List<Material> getMaterialListByIds(String ids)throws Exception {
+    public List<Material> getMaterialListByIds(String ids) {
         List<Long> idList = StringUtil.strToLongList(ids);
         List<Material> list = new ArrayList<>();
         try{
@@ -139,9 +141,9 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
      * 查询商品管理-商品信息列表查询
      */
     @Override
-    public List<MaterialVo4Unit> select(String materialParam, String standard, String model, String color, String brand, String mfrs,
+    public List<MaterialVo4Unit> select(String materialParam, String standard, String model, String color, String brand,
                                         String materialOther, String weight, String expiryNum, String enableSerialNumber,
-                                        String enableBatchNumber, String position, String enabled, String remark, String categoryId,
+                                        String enabled, String remark, String categoryId,
                                         String mpList,String reminder) {
         String[] mpArr = new String[]{};
         if(StringUtil.isNotEmpty(mpList)){
@@ -155,8 +157,8 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 idList = getListByParentId(Long.parseLong(categoryId));
             }
             PageUtils.startPage();
-            list= materialMapperEx.selectByConditionMaterial(materialParam, standard, model, color, brand, mfrs, materialOther, weight, expiryNum,
-                    enableSerialNumber, enableBatchNumber, position, enabled, remark, idList, mpList,reminder);
+            list= materialMapperEx.selectByConditionMaterial(materialParam, standard, model, color, brand, materialOther, weight, expiryNum,
+                    enableSerialNumber, enabled, remark, idList, mpList,reminder);
             if (null != list && list.size()>0) {
                 Map<Long,BigDecimal> initialStockMap = getInitialStockMapByMaterialList(list);
                 Map<Long,BigDecimal> currentStockMap = getCurrentStockMapByMaterialList(list);
@@ -183,71 +185,66 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
      */
     @Override
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int insertMaterial(MaterialDTO material, HttpServletRequest request)throws Exception {
-        //商品主表信息
-        Material m = material;
-        //设置状态
-        m.setEnabled(true);
-        //获取类型编码
-        Long serial_no = materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
-        String sku = serial_no + DateUtils.dateTimeNow()  + RandomHelper.getRandomStr(6);
-        //设置系统sku
-        m.setSystemSku(sku);
+    public boolean insertMaterial(MaterialDTO materialDTO, HttpServletRequest request) {
         try{
-            //添加商品
-            materialMapperEx.insertSelectiveEx(m);
-            Long mId = m.getId();
-            //添加商品条码信息
-            materialExtendService.saveDetails(material.getMbList(),material.getSortList().toJSONString(),mId,"insert");
-            //设置初始库存
-            if(material.getStock()!=null) {
-                List<MaterialInitialStock> stockArr = material.getStock();
-                for (int i = 0; i < stockArr.size(); i++) {
-                    MaterialInitialStock jsonObj = stockArr.get(i);
-                    //此时id为仓库id,仓库id、最低安全库存数量、库位不为空
-                    if(jsonObj.getId() != null && jsonObj.getLowSafeStock() != null || jsonObj.getPosition() != null || jsonObj.getHighSafeStock() != null) {
-                        Long depotId = jsonObj.getId();
-                        jsonObj.setDepotId(depotId);
-                        jsonObj.setMaterialId(mId);
-                        jsonObj.setId(null);
-                        //设置初始库
-                        materialInitialStockMapper.insertSelective(jsonObj);
-                        //更新当前库存
-                        depotItemService.updateCurrentStockFun(mId,jsonObj.getDepotId());
+            //商品主表信息
+            Material m = materialDTO;
+            //设置状态
+            m.setEnabled(true);
+            //获取类型编码
+            Long serial_no = materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
+            String spu = serial_no + DateUtils.dateTimeNow("yyMMddHHmmss")  + RandomHelper.getRandomStr(6);
+            //设置系统sku
+            m.setSystemSpu(spu);
+                //添加商品
+                materialMapperEx.insertSelectiveEx(m);
+                Long mId = m.getId();
+                //保存商品条码信息
+                materialExtendService.saveDetails(materialDTO.getMeList(),mId,"insert");
+                //设置初始库存
+                if(materialDTO.getStock()!=null) {
+                    List<MaterialInitialStock> stockArr = materialDTO.getStock();
+                    for (int i = 0; i < stockArr.size(); i++) {
+                        MaterialInitialStock jsonObj = stockArr.get(i);
+                        //此时id为仓库id,仓库id、最低安全库存数量、库位不为空
+                        if(jsonObj.getId() != null && jsonObj.getLowSafeStock() != null || jsonObj.getPosition() != null || jsonObj.getHighSafeStock() != null) {
+                            Long depotId = jsonObj.getId();
+                            jsonObj.setDepotId(depotId);
+                            jsonObj.setMaterialId(mId);
+                            jsonObj.setId(null);
+                            //设置初始库
+                            materialInitialStockMapper.insertSelective(jsonObj);
+                            //更新当前库存
+                            depotItemService.updateCurrentStockFun(mId,jsonObj.getDepotId());
+                        }
                     }
                 }
-            }
-            logService.insertLog("商品",
-                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(m.getName()).toString(), request);
-            return 1;
-        }
-        catch (BusinessRunTimeException ex) {
+                logService.insertLog("商品",
+                        new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(m.getName()).toString(), request);
+        } catch (BusinessRunTimeException ex) {
             throw new BusinessRunTimeException(ex.getCode(), ex.getMessage());
-        }
-        catch(Exception e){
+        } catch(Exception e){
             JshException.writeFail(logger, e);
-            return 0;
+            return false;
         }
+        return true;
     }
 
     /**
      * 修改商品
-     * @param obj
+     * @param materialDTO
      * @param request
      */
     @Override
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int updateMaterial(MaterialDTO obj, HttpServletRequest request) throws Exception{
-        Material material = obj;
+    public boolean updateMaterial(MaterialDTO materialDTO, HttpServletRequest request){
         try{
+            Material material = materialDTO;
             //修改商品属性
             materialMapper.updateByPrimaryKeySelective(material);
-            if(material.getUnitId() == null) {
-                materialMapperEx.setUnitIdToNull(material.getId());
-            }
-            materialExtendService.saveDetails(obj.getMbList(), obj.getSortList().toJSONString(),material.getId(), "update");
-            if(obj.getStock()!=null) {
-                List<MaterialInitialStock> stockArr = obj.getStock();
+            materialExtendService.saveDetails(materialDTO.getMeList(),material.getId(), "update");
+            if(materialDTO.getStock()!=null) {
+                List<MaterialInitialStock> stockArr = materialDTO.getStock();
                 for (int i = 0; i < stockArr.size(); i++) {
                     MaterialInitialStock jsonObj = stockArr.get(i);
                     if(jsonObj.getId() != null && jsonObj.getLowSafeStock() != null || jsonObj.getPosition() != null || jsonObj.getNumber() != null) {
@@ -275,19 +272,18 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
             }
             logService.insertLog("商品",
                     new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(material.getName()).toString(), request);
-            return 1;
         }
         catch (BusinessRunTimeException ex) {
             throw new BusinessRunTimeException(ex.getCode(), ex.getMessage());
         }
         catch(Exception e){
             JshException.writeFail(logger, e);
-            return 0;
+            return false;
         }
+        return true;
     }
 
     @Override
-    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
     public int deleteMaterial(Long id, HttpServletRequest request)throws Exception {
         return batchDeleteMaterialByIds(id.toString());
     }
@@ -300,7 +296,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
 
     @Override
     @Transactional(value = "transactionManager", rollbackFor = Exception.class)
-    public int batchDeleteMaterialByIds(String ids) throws Exception{
+    public int batchDeleteMaterialByIds(String ids){
         String [] idArray = ids.split(",");
         //校验单据子表	jsh_depot_item
         List<DepotItem> depotItemList =null;
@@ -503,6 +499,20 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         return list;
     }
 
+    /**
+     * 商品选择-查找商品信息
+     *
+     * @param materialQueryDTO
+     * @param offset
+     * @param rows
+     * @return
+     * @throws Exception
+     */
+    @Override
+    public List<MaterialVo4Unit> findBySelectWithBarCode(MaterialQueryDTO materialQueryDTO, Integer offset, Integer rows) throws Exception {
+        return null;
+    }
+
     @Override
     public int findBySelectWithBarCodeCount(Long categoryId, String q, String standardOrModel, String color,
                                             String brand, String mfrs, String enableSerialNumber, String enableBatchNumber, Long depotId) throws Exception{
@@ -598,7 +608,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 objs[10] = m.getSku();
                 objs[11] = m.getEnabled() ? "1" : "0";
                 objs[12] = m.getEnableSerialNumber();
-                objs[13] = m.getSystemSku();
+                objs[13] = m.getSystemSpu();
                 objs[14] = m.getBarCode();
                 objs[15] = m.getDefaultPurchaseDecimal() == null ? "" : m.getDefaultPurchaseDecimal().toString();
                 objs[16] = m.getDefaultWholesaleDecimal() == null ? "" : m.getDefaultWholesaleDecimal().toString();
@@ -706,7 +716,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 //获取类型编码
                 Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
                 //设置系统sku
-                m.setSystemSku(serial_no + DateUtils.dateTimeNow());
+                m.setSystemSpu(serial_no + DateUtils.dateTimeNow());
                 if(null!=categoryId){
                     m.setCategoryId(categoryId);
                 }
@@ -1533,7 +1543,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
      * @throws Exception
      */
     @Override
-    public String getBigUnitStock(BigDecimal stock, Long unitId) throws Exception {
+    public String getBigUnitStock(BigDecimal stock, Long unitId) {
         String bigUnitStock = "";
         if(null!= unitId) {
             Unit unit = unitService.getUnit(unitId);
@@ -1903,7 +1913,7 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
                 //获取类型编码
                 Long serial_no = categoryId == null ? null : materialCategoryService.getMaterialCategory(m.getCategoryId()).getSerialNo();
                 //设置系统sku
-                m.setSystemSku(serial_no + DateUtils.dateTimeNow() + RandomHelper.getRandomStr(6));
+                m.setSystemSpu(serial_no + DateUtils.dateTimeNow() + RandomHelper.getRandomStr(6));
                 //设置默认采购价
                 m.setDefaultPurchaseDecimal(StringUtil.isNotEmpty(defaultPurchaseDecimal) ? new BigDecimal(defaultPurchaseDecimal) : null);
                 //设置默认销售价
@@ -2167,4 +2177,6 @@ public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> i
         materialMap.values().forEach(v -> materials.add(v));
         return materials;
     }
+
+
 }

+ 41 - 0
src/main/java/com/jsh/erp/service/impl/MaterialUnitServiceImpl.java

@@ -0,0 +1,41 @@
+package com.jsh.erp.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jsh.erp.datasource.entities.MaterialUnit;
+import com.jsh.erp.datasource.mappers.MaterialUnitMapper;
+import com.jsh.erp.query.LambdaQueryWrapperX;
+import com.jsh.erp.service.MaterialUnitService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+@Slf4j
+public class MaterialUnitServiceImpl extends ServiceImpl<MaterialUnitMapper,MaterialUnit> implements MaterialUnitService {
+
+    @Resource
+    private MaterialUnitMapper materialUnitMapper;
+
+    /**
+     * 保存商品单位
+     * @param units 商品单位集合
+     * @param meId  商品拓展id
+     */
+    @Override
+    public Boolean saveDetails(List<MaterialUnit> units, Long meId) {
+        update(new UpdateWrapper<MaterialUnit>().set("delete_flag",true).eq("material_extend_id",meId));
+        for (MaterialUnit unit : units) {
+            unit.setMaterialExtendId(meId);
+        }
+        return saveOrUpdateBatch(units);
+    }
+
+    @Override
+    public int batchDeleteMaterialUnitByMIds() {
+        return 0;
+    }
+
+}

+ 36 - 0
src/main/java/com/jsh/erp/service/impl/MaterialUpcServiceImpl.java

@@ -0,0 +1,36 @@
+package com.jsh.erp.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jsh.erp.datasource.entities.MaterialUnit;
+import com.jsh.erp.datasource.entities.MaterialUpc;
+import com.jsh.erp.datasource.mappers.MaterialUpcMapper;
+import com.jsh.erp.service.MaterialUpcService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+@Slf4j
+public class MaterialUpcServiceImpl extends ServiceImpl<MaterialUpcMapper,MaterialUpc> implements MaterialUpcService {
+
+    @Resource
+    private MaterialUpcMapper materialUpcMapper;
+
+    /**
+     * 保存商品UPC
+     * @param upcList 商品UPC集合
+     * @param meId 商品拓展id
+     */
+    @Override
+    public Boolean saveDetails(List<MaterialUpc> upcList, Long meId) {
+        update(new UpdateWrapper<MaterialUpc>().set("delete_flag",true).eq("material_extend_id",meId));
+        for (MaterialUpc materialUpc : upcList) {
+            materialUpc.setMaterialExtendId(meId);
+        }
+        return saveOrUpdateBatch(upcList);
+    }
+
+}

+ 363 - 0
src/main/java/com/jsh/erp/service/impl/UnitServiceImpl.java

@@ -0,0 +1,363 @@
+package com.jsh.erp.service.impl;
+
+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.Material;
+import com.jsh.erp.datasource.entities.Unit;
+import com.jsh.erp.datasource.entities.UnitExample;
+import com.jsh.erp.datasource.entities.User;
+import com.jsh.erp.datasource.mappers.MaterialMapperEx;
+import com.jsh.erp.datasource.mappers.UnitMapper;
+import com.jsh.erp.datasource.mappers.UnitMapperEx;
+import com.jsh.erp.datasource.vo.UnitListVo;
+import com.jsh.erp.exception.BusinessRunTimeException;
+import com.jsh.erp.exception.JshException;
+import com.jsh.erp.service.LogService;
+import com.jsh.erp.service.UnitService;
+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.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class UnitServiceImpl extends ServiceImpl<UnitMapper,Unit> implements UnitService {
+    private Logger logger = LoggerFactory.getLogger(UnitServiceImpl.class);
+
+    @Resource
+    private UnitMapper unitMapper;
+    @Resource
+    private UnitMapperEx unitMapperEx;
+    @Resource
+    private UserService userService;
+    @Resource
+    private LogService logService;
+    @Resource
+    private MaterialMapperEx materialMapperEx;
+
+    @Override
+    public Unit getUnit(long id) {
+        Unit result=null;
+        try{
+            result=unitMapper.selectByPrimaryKey(id);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return result;
+    }
+
+    @Override
+    public List<Unit> getUnitListByIds(String ids) {
+        List<Long> idList = StringUtil.strToLongList(ids);
+        List<Unit> list = new ArrayList<>();
+        try{
+            UnitExample example = new UnitExample();
+            example.createCriteria().andIdIn(idList);
+            list = unitMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    /**
+     * 所有单位集合
+     */
+    @Override
+    public List<Unit> unitList() {
+        UnitExample example = new UnitExample();
+        example.createCriteria().andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Unit> list = null;
+        try{
+            list = unitMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    @Override
+    public List<Unit> select(String name)throws Exception {
+        List<Unit> list=null;
+        try{
+            PageUtils.startPage();
+            list=unitMapperEx.selectByConditionUnit(name);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list;
+    }
+
+    /**
+     * 新增单位
+     * @param unit 单位
+     */
+    @Override
+    public int insertUnit(Unit unit, HttpServletRequest request)throws Exception {
+        int result=0;
+        try{
+            unit.setEnabled(true);
+            result=unitMapper.insertSelective(unit);
+            logService.insertLog("多单位",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(unit.getName()).toString(), request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    /**
+     * 修改单位
+     * @param unit 单位
+     */
+    @Override
+    public int updateUnit(Unit unit, HttpServletRequest request) {
+        int result=0;
+        try{
+            result = unitMapper.updateByPrimaryKeySelective(unit);
+            logService.insertLog("多单位",
+                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(unit.getName()).toString(), request);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    /**
+     * 根据单位信息生成名称的格式
+     * @param unit
+     */
+    private void parseNameByUnit(Unit unit) {
+        String unitName = unit.getBasicUnit() + "/" + "(" +  unit.getOtherUnit() + "=" + unit.getRatio().toString() + unit.getBasicUnit() + ")";
+        if(StringUtil.isNotEmpty(unit.getOtherUnitTwo()) && unit.getRatioTwo()!=null) {
+            unitName += "/" + "(" + unit.getOtherUnitTwo() + "=" + unit.getRatioTwo().toString() + unit.getBasicUnit() + ")";
+            if(StringUtil.isNotEmpty(unit.getOtherUnitThree()) && unit.getRatioThree()!=null) {
+                unitName += "/" + "(" + unit.getOtherUnitThree() + "=" + unit.getRatioThree().toString() + unit.getBasicUnit() + ")";
+            }
+        }
+        unit.setName(unitName);
+    }
+
+    /**
+     * 删除单位
+     * @param id 单位id
+     * @param request
+     */
+    @Override
+    public int deleteUnit(Long id, HttpServletRequest request) {
+        return batchDeleteUnitByIds(id.toString());
+    }
+
+    /**
+     * 批量删除单位
+     * @param ids 单位id字符集
+     * @param request
+     */
+    @Override
+    public int batchDeleteUnit(String ids, HttpServletRequest request){
+        return batchDeleteUnitByIds(ids);
+    }
+
+    /**
+     * 检查单位名称是否存在
+     * @param name 单位名称
+     * @return 单位数量
+     */
+    @Override
+    public int checkIsNameExist(String name) {
+        UnitExample example = new UnitExample();
+        example.createCriteria().andNameEqualTo(name.replaceAll(" ", "")).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Unit> list = null;
+        try{
+            list = unitMapper.selectByExample(example);
+        }catch(Exception e){
+            JshException.readFail(logger, e);
+        }
+        return list == null ? 0 : list.size();
+    }
+
+    /**
+     * 根据条件查询单位id
+     * @param basicUnit
+     * @param otherUnit
+     * @param ratio
+     * @return
+     */
+    @Override
+    public Long getUnitIdByParam(String basicUnit, String otherUnit, BigDecimal ratio){
+        Long unitId = null;
+        UnitExample example = new UnitExample();
+        example.createCriteria().andBasicUnitEqualTo(basicUnit).andOtherUnitEqualTo(otherUnit).andRatioEqualTo(ratio)
+                .andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
+        List<Unit> list = unitMapper.selectByExample(example);
+        if(list!=null && list.size()>0) {
+            unitId = list.get(0).getId();
+        }
+        return unitId;
+    }
+
+    /**
+     * 根据多单位的比例进行库存换算(保留两位小数)
+     * @param stock
+     * @param unitInfo
+     * @param materialUnit
+     * @return
+     */
+    @Override
+    public BigDecimal parseStockByUnit(BigDecimal stock, Unit unitInfo, String materialUnit) {
+        if(materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio()!=null && unitInfo.getRatio().compareTo(BigDecimal.ZERO)!=0) {
+            stock = stock.divide(unitInfo.getRatio(),2,BigDecimal.ROUND_HALF_UP);
+        }
+        if(materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo()!=null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO)!=0) {
+            stock = stock.divide(unitInfo.getRatioTwo(),2,BigDecimal.ROUND_HALF_UP);
+        }
+        if(materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree()!=null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO)!=0) {
+            stock = stock.divide(unitInfo.getRatioThree(),2,BigDecimal.ROUND_HALF_UP);
+        }
+        return stock;
+    }
+
+    /**
+     * 根据多单位的比例进行单价换算(保留两位小数),变大
+     * @param unitPrice
+     * @param unitInfo
+     * @param materialUnit
+     * @return
+     */
+    @Override
+    public BigDecimal parseUnitPriceByUnit(BigDecimal unitPrice, Unit unitInfo, String materialUnit) {
+        if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
+            unitPrice = unitPrice.multiply(unitInfo.getRatio());
+        }
+        if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
+            unitPrice = unitPrice.multiply(unitInfo.getRatioTwo());
+        }
+        if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
+            unitPrice = unitPrice.multiply(unitInfo.getRatioThree());
+        }
+        return unitPrice;
+    }
+
+    /**
+     * 根据多单位的比例进行总金额换算(保留两位小数),变小
+     * @param allPrice
+     * @param unitInfo
+     * @param materialUnit
+     * @return
+     */
+    @Override
+    public BigDecimal parseAllPriceByUnit(BigDecimal allPrice, Unit unitInfo, String materialUnit) {
+        if (materialUnit.equals(unitInfo.getOtherUnit()) && unitInfo.getRatio() != null && unitInfo.getRatio().compareTo(BigDecimal.ZERO) != 0) {
+            allPrice = allPrice.divide(unitInfo.getRatio(), 2, BigDecimal.ROUND_HALF_UP);
+        }
+        if (materialUnit.equals(unitInfo.getOtherUnitTwo()) && unitInfo.getRatioTwo() != null && unitInfo.getRatioTwo().compareTo(BigDecimal.ZERO) != 0) {
+            allPrice = allPrice.divide(unitInfo.getRatioTwo(), 2, BigDecimal.ROUND_HALF_UP);
+        }
+        if (materialUnit.equals(unitInfo.getOtherUnitThree()) && unitInfo.getRatioThree() != null && unitInfo.getRatioThree().compareTo(BigDecimal.ZERO) != 0) {
+            allPrice = allPrice.divide(unitInfo.getRatioThree(), 2, BigDecimal.ROUND_HALF_UP);
+        }
+        return allPrice;
+    }
+
+    /**
+     * 批量设置状态
+     * @param status 状态
+     * @param ids 单位id
+     */
+    @Override
+    public int batchSetStatus(Boolean status, String ids){
+        logService.insertLog("多单位",
+                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        List<Long> unitIds = StringUtil.strToLongList(ids);
+        Unit unit = new Unit();
+        unit.setEnabled(status);
+        UnitExample example = new UnitExample();
+        example.createCriteria().andIdIn(unitIds);
+        int result=0;
+        try{
+            result = unitMapper.updateByExampleSelective(unit, example);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+
+    /**
+     * 根据单位id获取单位值集合
+     * @param id 单位id
+     */
+    @Override
+    public List getUnitListByID(Long id){
+        Unit unit = unitMapper.selectByPrimaryKey(id);
+        List<UnitListVo> list = new ArrayList();
+        UnitListVo unitListVo = new UnitListVo().setName(unit.getBasicUnit()).setRatio(new BigDecimal("1"));
+        list.add(unitListVo);
+        if (unit.getOtherUnit() != null){
+            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnit()).setRatio(unit.getRatio());
+            list.add(vo);
+        }
+        if (unit.getOtherUnitTwo() != null){
+            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnitTwo()).setRatio(unit.getRatioTwo());
+            list.add(vo);
+        }
+        if (unit.getOtherUnitThree() != null){
+            UnitListVo vo = new UnitListVo().setName(unit.getOtherUnitThree()).setRatio(unit.getRatioThree());
+            list.add(vo);
+        }
+        return list;
+    }
+
+    /**
+     * 批量删除多单位
+     * @param ids
+     * @return
+     * @throws Exception
+     */
+    private int batchDeleteUnitByIds(String ids) {
+        int result=0;
+        String [] idArray = ids.split(",");
+        //校验产品表	jsh_material
+//        List<Material> materialList = null;
+//        try{
+//            materialList = materialMapperEx.getMaterialListByUnitIds(idArray);
+//        }catch(Exception e){
+//            JshException.readFail(logger, e);
+//        }
+//        if(materialList!=null&&materialList.size()>0){
+//            logger.error("异常码[{}],异常提示[{}],参数,UnitIds[{}]",
+//                    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<Unit> list = getUnitListByIds(ids);
+        for(Unit unit: list){
+            sb.append("[").append(unit.getName()).append("]");
+        }
+        logService.insertLog("多单位", sb.toString(),
+                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
+        User userInfo = userService.getCurrentUser();
+        //校验通过执行删除操作
+        try{
+            result = unitMapperEx.batchDeleteUnitByIds(new Date(),userInfo == null ? null : userInfo.getId(),idArray);
+        }catch(Exception e){
+            JshException.writeFail(logger, e);
+        }
+        return result;
+    }
+}

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

@@ -66,7 +66,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     private Integer tryDayLimit;
 
     @Override
-    public User getUser(long id)throws Exception {
+    public User getUser(long id) {
         User result=null;
         try{
             result=userMapper.selectByPrimaryKey(id);
@@ -468,7 +468,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
      * @return com.jsh.erp.datasource.entities.User
      */
     @Override
-    public User getCurrentUser()throws Exception{
+    public User getCurrentUser(){
         HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
         Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
         return getUser(userId);

+ 33 - 97
src/main/resources/mapper_xml/MaterialExtendMapper.xml

@@ -139,7 +139,7 @@
       #{deleteFlag,jdbcType=VARCHAR})
   </insert>
 
-  <insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.MaterialExtend">
+  <insert id="insertSelective" parameterType="com.jsh.erp.datasource.entities.MaterialExtend" useGeneratedKeys="true" keyProperty="id">
     insert into jsh_material_extend
     <trim prefix="(" suffix=")" suffixOverrides=",">
       <if test="id != null">
@@ -154,18 +154,6 @@
       <if test="sku != null">
         sku,
       </if>
-      <if test="purchaseDecimal != null">
-        purchase_decimal,
-      </if>
-      <if test="commodityDecimal != null">
-        commodity_decimal,
-      </if>
-      <if test="wholesaleDecimal != null">
-        wholesale_decimal,
-      </if>
-      <if test="lowDecimal != null">
-        low_decimal,
-      </if>
       <if test="defaultFlag != null">
         default_flag,
       </if>
@@ -187,32 +175,20 @@
       <if test="deleteFlag != null">
         delete_Flag,
       </if>
-      <if test="productionDate != null">
-        production_date,
-      </if>
-      <if test="expiryNum != null">
-        expiry_num,
-      </if>
-      <if test="supplierId != null">
-        supplier_id,
+      <if test="standard != null">
+        standard,
       </if>
-      <if test="barCode != null">
-        bar_code,
+      <if test="color != null">
+        color,
       </if>
-      <if test="batchNumber != null">
-        batch_number,
+      <if test="weight != null">
+        weight,
       </if>
-      <if test="inventory != null">
-        inventory,
+      <if test="model != null">
+        model,
       </if>
-      <if test="depotId != null">
-        depot_id,
-      </if>
-      <if test="position != null">
-        position,
-      </if>
-      <if test="ratio != null">
-        ratio,
+      <if test="enabled != null">
+        enabled,
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -228,18 +204,6 @@
       <if test="sku != null">
         #{sku,jdbcType=VARCHAR},
       </if>
-      <if test="purchaseDecimal != null">
-        #{purchaseDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="commodityDecimal != null">
-        #{commodityDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="wholesaleDecimal != null">
-        #{wholesaleDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="lowDecimal != null">
-        #{lowDecimal,jdbcType=DECIMAL},
-      </if>
       <if test="defaultFlag != null">
         #{defaultFlag,jdbcType=VARCHAR},
       </if>
@@ -261,32 +225,20 @@
       <if test="deleteFlag != null">
         #{deleteFlag,jdbcType=VARCHAR},
       </if>
-      <if test="productionDate != null">
-        #{productionDate,jdbcType=DATE},
+      <if test="standard != null">
+        #{standard},
       </if>
-      <if test="expiryNum != null">
-        #{expiryNum,jdbcType=INTEGER},
+      <if test="color != null">
+        #{color},
       </if>
-      <if test="supplierId != null">
-        #{supplierId,jdbcType=BIGINT},
+      <if test="weight != null">
+        #{weight},
       </if>
-      <if test="barCode != null">
-        #{barCode,jdbcType=VARCHAR},
+      <if test="model != null">
+        #{model},
       </if>
-      <if test="batchNumber != null">
-        #{batchNumber,jdbcType=VARCHAR},
-      </if>
-      <if test="inventory != null">
-        #{inventory,jdbcType=DECIMAL},
-      </if>
-      <if test="depotId != null">
-        #{depotId,jdbcType=BIGINT},
-      </if>
-      <if test="position != null">
-        #{position,jdbcType=VARCHAR},
-      </if>
-      <if test="ratio != null">
-        #{ratio,jdbcType=INTEGER},
+      <if test="enabled != null">
+        #{enabled},
       </if>
     </trim>
   </insert>
@@ -375,6 +327,7 @@
       <include refid="Update_By_Example_Where_Clause" />
     </if>
   </update>
+
   <update id="updateByPrimaryKeySelective" parameterType="com.jsh.erp.datasource.entities.MaterialExtend">
     update jsh_material_extend
     <set>
@@ -387,18 +340,6 @@
       <if test="sku != null">
         sku = #{sku,jdbcType=VARCHAR},
       </if>
-      <if test="purchaseDecimal != null">
-        purchase_decimal = #{purchaseDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="commodityDecimal != null">
-        commodity_decimal = #{commodityDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="wholesaleDecimal != null">
-        wholesale_decimal = #{wholesaleDecimal,jdbcType=DECIMAL},
-      </if>
-      <if test="lowDecimal != null">
-        low_decimal = #{lowDecimal,jdbcType=DECIMAL},
-      </if>
       <if test="defaultFlag != null">
         default_flag = #{defaultFlag,jdbcType=VARCHAR},
       </if>
@@ -420,30 +361,25 @@
       <if test="deleteFlag != null">
         delete_Flag = #{deleteFlag,jdbcType=VARCHAR},
       </if>
-      <if test="productionDate != null">
-        production_date = #{productionDate,jdbcType=DATE},
+      <if test="standard != null">
+        standard = #{standard},
       </if>
-      <if test="expiryNum != null">
-        expiry_num = #{expiryNum,jdbcType=INTEGER},
+      <if test="color != null">
+        color = #{color},
       </if>
-      <if test="supplierId != null">
-        supplier_id = #{supplierId,jdbcType=BIGINT},
+      <if test="weight != null">
+        weight = #{weight},
       </if>
-      <if test="barCode != null">
-        bar_code = #{barCode,jdbcType=VARCHAR},
+      <if test="model != null">
+        model = #{model},
       </if>
-      <if test="depotId != null">
-        depot_id = #{depotId,jdbcType=BIGINT},
-      </if>
-      <if test="position != null">
-        position = #{position,jdbcType=VARCHAR},
-      </if>
-      <if test="ratio != null">
-        ratio = #{ratio,jdbcType=INTEGER},
+      <if test="enabled != null">
+        enabled = #{enabled},
       </if>
     </set>
     where id = #{id,jdbcType=BIGINT}
   </update>
+
   <update id="updateByPrimaryKey" parameterType="com.jsh.erp.datasource.entities.MaterialExtend">
     update jsh_material_extend
     set material_id = #{materialId,jdbcType=BIGINT},

+ 7 - 7
src/main/resources/mapper_xml/MaterialExtendMapperEx.xml

@@ -5,13 +5,13 @@
 
     </resultMap>
 
-    <select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.MaterialExtendExample" resultType="com.jsh.erp.datasource.vo.MaterialExtendVo4List">
-        select distinct d.id,d.commodity_unit,d.sku,d.commodity_decimal,d.purchase_decimal,d.wholesale_decimal,
-                        d.low_decimal,d.default_flag,d.production_date,d.expiry_num,d.supplier_id,d.bar_code,d.batch_number,d.inventory,d.depot_id,d.position,d.ratio
-        from jsh_material_extend d
-        where d.material_id = #{materialId}
-        and ifnull(d.delete_flag,'0') !='1'
-        order by d.default_flag desc,d.id asc
+    <select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.MaterialExtendExample" resultType="com.jsh.erp.datasource.vo.MaterialExtendVo">
+        select
+          id,commodity_unit,sku,default_flag,bar_code,standard,color,weight,model,enabled
+        from jsh_material_extend
+        where material_id = #{materialId}
+        and ifnull(delete_flag,'0') !='1'
+        order by default_flag desc,id asc
     </select>
 
     <select id="getMaxTimeByTenantAndTime" resultType="java.lang.Long">

+ 1 - 1
src/main/resources/mapper_xml/MaterialMapper.xml

@@ -91,7 +91,7 @@
   <sql id="Base_Column_List">
     id, category_id, name, model, standard, brand, mnemonic, color, unit, remark,
     img_name, unit_id, weight, enabled, other_field1, other_field2, other_field3,
-    enable_serial_number, enable_batch_number, tenant_id, delete_flag, system_sku,
+    enable_serial_number, enable_batch_number, tenant_id, delete_flag, system_spu,
     moving_pin_reminder_cycle,expiry_num,default_purchase_decimal,default_wholesale_decimal
   </sql>
 

+ 5 - 12
src/main/resources/mapper_xml/MaterialMapperEx.xml

@@ -89,13 +89,6 @@
         <if test="enableSerialNumber != null and enableSerialNumber !=''">
             and m.enable_serial_number = #{enableSerialNumber}
         </if>
-        <if test="enableBatchNumber != null and enableBatchNumber !=''">
-            and m.enable_batch_number = #{enableBatchNumber}
-        </if>
-        <if test="position != null and position !=''">
-            <bind name="bindPosition" value="'%'+position+'%'"/>
-            and m.position like #{bindPosition}
-        </if>
         <if test="enabled != null and enabled !=''">
             and m.enabled = #{enabled}
         </if>
@@ -189,8 +182,8 @@
             <if test="deleteFlag != null">
                 delete_flag,
             </if>
-            <if test="systemSku != null">
-                system_sku,
+            <if test="systemSpu != null">
+                system_spu,
             </if>
             <if test="movingPinReminderCycle != null">
                 moving_pin_reminder_cycle,
@@ -269,8 +262,8 @@
             <if test="deleteFlag != null">
                 #{deleteFlag,jdbcType=VARCHAR},
             </if>
-            <if test="systemSku != null">
-                #{systemSku,jdbcType=VARCHAR},
+            <if test="systemSpu != null">
+                #{systemSpu},
             </if>
             <if test="movingPinReminderCycle != null">
                 #{movingPinReminderCycle,jdbcType=VARCHAR},
@@ -580,7 +573,7 @@
         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'
         where
-        me.bar_code in (
+        me.sku in (
         <foreach collection="barCodeArray" item="barCode" separator=",">
             #{barCode}
         </foreach>