瀏覽代碼

[CODE]: 基础资料仓库管理、库位信息

maxianghua 4 年之前
父節點
當前提交
344fa252f7
共有 19 個文件被更改,包括 489 次插入45 次删除
  1. 0 1
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TCorpsController.java
  2. 0 2
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TGoodsController.java
  3. 8 0
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TWarehouseAreaController.java
  4. 77 17
      ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TWarehouseController.java
  5. 8 0
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java
  6. 14 0
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/domain/TWarehouseArea.java
  7. 0 1
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TGoodsMapper.java
  8. 11 1
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TWarehouseAreaMapper.java
  9. 45 1
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TWarehouseMapper.java
  10. 0 1
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITCorpsService.java
  11. 7 0
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITWarehouseAreaService.java
  12. 35 1
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITWarehouseService.java
  13. 0 2
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TCorpsServiceImpl.java
  14. 53 2
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseAreaServiceImpl.java
  15. 141 5
      ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseServiceImpl.java
  16. 2 1
      ruoyi-warehouse/src/main/java/com/ruoyi/reportManagement/service/impl/TWhgenlegServiceImpl.java
  17. 1 0
      ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java
  18. 29 9
      ruoyi-warehouse/src/main/resources/mapper/basicData/TWarehouseAreaMapper.xml
  19. 58 1
      ruoyi-warehouse/src/main/resources/mapper/basicData/TWarehouseMapper.xml

+ 0 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TCorpsController.java

@@ -2,7 +2,6 @@ package com.ruoyi.web.controller.warehouse.basicData;
 
 import com.alibaba.fastjson.JSONArray;
 import com.ruoyi.basicData.domain.TCorps;
-import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.basicData.service.ITCorpsService;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;

+ 0 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TGoodsController.java

@@ -1,8 +1,6 @@
 package com.ruoyi.web.controller.warehouse.basicData;
 
-import com.alibaba.fastjson.JSONArray;
 import com.ruoyi.basicData.domain.TGoods;
-import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.basicData.service.ITGoodsService;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;

+ 8 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TWarehouseAreaController.java

@@ -3,10 +3,12 @@ package com.ruoyi.web.controller.warehouse.basicData;
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import com.ruoyi.basicData.service.ITWarehouseAreaService;
 import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -61,6 +63,11 @@ public class TWarehouseAreaController extends BaseController {
     @Log(title = "库区", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TWarehouseArea tWarehouseArea) {
+        // 校验是否为库区
+        if (UserConstants.NOT_UNIQUE.equals(tWarehouseAreaService.checkUFTWarehouseUnique(tWarehouseArea))){
+            return AjaxResult.error("新增仓库库位'" + tWarehouseArea.getfName() + "'失败,请选择库区");
+        }
+        tWarehouseArea.setCreateBy(SecurityUtils.getUsername());
         return toAjax(tWarehouseAreaService.insertTWarehouseArea(tWarehouseArea));
     }
 
@@ -70,6 +77,7 @@ public class TWarehouseAreaController extends BaseController {
     @Log(title = "库区", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody TWarehouseArea tWarehouseArea) {
+        tWarehouseArea.setUpdateBy(SecurityUtils.getUsername());
         return toAjax(tWarehouseAreaService.updateTWarehouseArea(tWarehouseArea));
     }
 

+ 77 - 17
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TWarehouseController.java

@@ -1,27 +1,25 @@
 package com.ruoyi.web.controller.warehouse.basicData;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.basicData.domain.TWarehouse;
-import com.ruoyi.basicData.domain.TWarehouseArea;
+
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 import com.ruoyi.basicData.service.ITWarehouseService;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.core.domain.model.LoginUser;
-import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.enums.BusinessType;
-import com.ruoyi.common.utils.ServletUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.common.utils.spring.SpringUtils;
-import com.ruoyi.framework.web.service.TokenService;
+import org.apache.commons.lang3.ArrayUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
+
+import java.util.Iterator;
 import java.util.List;
 
 /**
@@ -41,10 +39,10 @@ public class TWarehouseController extends BaseController {
      */
     @PreAuthorize("@ss.hasPermi('basicdata:warehouse:list')")
     @GetMapping("/list")
-    public TableDataInfo list(TWarehouse tWarehouse) {
-        startPage();
+    public AjaxResult list(TWarehouse tWarehouse) {
+        // startPage();
         List<TWarehouse> list = tWarehouseService.selectTWarehouseList(tWarehouse);
-        return getDataTable(list);
+        return  AjaxResult.success(list); // getDataTable(list);
     }
 
     /**
@@ -64,15 +62,32 @@ public class TWarehouseController extends BaseController {
      */
     @PreAuthorize("@ss.hasPermi('basicdata:warehouse:query')")
     @GetMapping(value = "/{fId}")
-    public AjaxResult getInfo(@PathVariable("fId") Long fId) {
-        return AjaxResult.success(tWarehouseService.selectTWarehouseById1(fId));
+    public AjaxResult getInfo(@PathVariable Long fId) {
+        return AjaxResult.success(tWarehouseService.selectTWarehouseById(fId));
+    }
+
+    /**
+     * 查询仓库列表(排除节点)
+     */
+    @GetMapping("/list/exclude/{deptId}")
+    public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) {
+        List<TWarehouse> tWarehouses = tWarehouseService.selectTWarehouseList(new TWarehouse());
+        Iterator<TWarehouse> it = tWarehouses.iterator();
+        while (it.hasNext()) {
+            TWarehouse d = (TWarehouse) it.next();
+            if (d.getfId().intValue() == deptId
+                    || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")) {
+                it.remove();
+            }
+        }
+        return AjaxResult.success(tWarehouses);
     }
 
 
     /**
      * 新增仓库
      */
-    @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
+   /* @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
     @Log(title = "仓库", businessType = BusinessType.INSERT)
     @PostMapping
     @RepeatSubmit
@@ -98,18 +113,54 @@ public class TWarehouseController extends BaseController {
         // 获取当前的用户
         LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
         return tWarehouseService.insertTWarehouse1(tWarehouse, tWarehouseArea, loginUser);
+    }*/
+
+    /**
+     * 新增仓库
+     */
+    @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
+    @Log(title = "仓库", businessType = BusinessType.INSERT)
+    @PostMapping
+    @RepeatSubmit
+    public AjaxResult add(@Validated @RequestBody TWarehouse tWarehouse) {
+        if (UserConstants.NOT_UNIQUE.equals(tWarehouseService.checkUFNoUnique(tWarehouse))) {
+            return AjaxResult.error("新增仓库'" + tWarehouse.getfNo() + "'失败,编号已存在");
+        } else if (UserConstants.NOT_UNIQUE.equals(tWarehouseService.checkUFNnameUnique(tWarehouse))) {
+            return AjaxResult.error("新增仓库'" + tWarehouse.getfName() + "'失败,名称已存在");
+        } else if (UserConstants.NOT_UNIQUE.equals(tWarehouseService.checkUFAreUnique(tWarehouse))){
+            return AjaxResult.error("新增仓库库区'" + tWarehouse.getfName() + "'失败,已有库位存在");
+        }
+        tWarehouse.setCreateBy(SecurityUtils.getUsername());
+        return toAjax(tWarehouseService.insertTWarehouse(tWarehouse));
     }
 
     /**
      * 修改仓库
      */
-    @PreAuthorize("@ss.hasPermi('basicdata:warehouse:edit')")
+    /*@PreAuthorize("@ss.hasPermi('basicdata:warehouse:edit')")
     @Log(title = "仓库", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody TWarehouse tWarehouse) {
         return tWarehouseService.updateTWarehouse(tWarehouse);
+    }*/
+
+    @PreAuthorize("@ss.hasPermi('system:dept:edit')")
+    @PutMapping
+    @RepeatSubmit
+    public AjaxResult edit(@Validated @RequestBody TWarehouse tWarehouse) {
+        if (UserConstants.NOT_UNIQUE.equals(tWarehouseService.checkUFNoUnique(tWarehouse))) {
+            return AjaxResult.error("新增仓库'" + tWarehouse.getfNo() + "'失败,编号已存在");
+        } else if (UserConstants.NOT_UNIQUE.equals(tWarehouseService.checkUFNnameUnique(tWarehouse))) {
+            return AjaxResult.error("新增仓库'" + tWarehouse.getfName() + "'失败,名称已存在");
+        } else if (StringUtils.equals(UserConstants.DEPT_DISABLE, tWarehouse.getfStatus())
+                && tWarehouseService.selectNormalChildrenDeptById(tWarehouse.getfId()) > 0) {
+            return AjaxResult.error("该仓库包含未停用的库区!");
+        }
+        tWarehouse.setUpdateBy(SecurityUtils.getUsername());
+        return toAjax(tWarehouseService.updateTWarehouses(tWarehouse));
     }
 
+
     /**
      * 删除仓库
      */
@@ -121,6 +172,15 @@ public class TWarehouseController extends BaseController {
         return tWarehouseService.deleteTWarehouseByIds(fIds);
     }
 
+    /**
+     * 获取部门下拉树列表
+     */
+    @GetMapping("/treeselect")
+    public AjaxResult treeselect(TWarehouse tWarehouse) {
+        List<TWarehouse> tWarehouses = tWarehouseService.selectTWarehouseList(tWarehouse);
+        return AjaxResult.success(tWarehouseService.buildDeptTreeSelect(tWarehouses));
+    }
+
 
 
 }

+ 8 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/TreeSelect.java

@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
 import com.fasterxml.jackson.annotation.JsonInclude;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysMenu;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 
 /**
  * Treeselect树结构实体类
@@ -45,6 +46,13 @@ public class TreeSelect implements Serializable
         this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
     }
 
+    public TreeSelect(TWarehouse tWarehouse)
+    {
+        this.id = tWarehouse.getfId();
+        this.label = tWarehouse.getfName();
+        this.children = tWarehouse.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
+    }
+
     public Long getId()
     {
         return id;

+ 14 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/domain/TWarehouseArea.java

@@ -6,6 +6,8 @@ import com.ruoyi.common.core.domain.BaseEntity;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 
+import java.math.BigDecimal;
+
 /**
  * 库区对象 t_warehouse_area
  *
@@ -38,6 +40,10 @@ public class TWarehouseArea extends BaseEntity {
     @Excel(name = "名称")
     private String fName;
 
+    /** 库容 */
+    @Excel(name = "库容")
+    private BigDecimal fTotalgross;
+
     /**
      * 地址
      */
@@ -112,6 +118,14 @@ public class TWarehouseArea extends BaseEntity {
         return delFlag;
     }
 
+    public BigDecimal getfTotalgross() {
+        return fTotalgross;
+    }
+
+    public void setfTotalgross(BigDecimal fTotalgross) {
+        this.fTotalgross = fTotalgross;
+    }
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

+ 0 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TGoodsMapper.java

@@ -1,7 +1,6 @@
 package com.ruoyi.basicData.mapper;
 
 import com.ruoyi.basicData.domain.TGoods;
-import com.ruoyi.basicData.domain.TWarehouse;
 
 import java.util.List;
 

+ 11 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TWarehouseAreaMapper.java

@@ -1,9 +1,9 @@
 package com.ruoyi.basicData.mapper;
 
-import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -77,5 +77,15 @@ public interface TWarehouseAreaMapper {
      */
     public TWarehouseArea checkUFNnameUnique(@Param("fNname")String fNname,@Param("fWarehouseid")Long  fWarehouseid);
 
+    /**
+     * 查询库区
+     *
+     * @param fId 库区ID
+     * @return 库区
+     */
+    public TWarehouseArea selectTWarehouseAreaByWarehouseId(Long fId);
+
+
+    public BigDecimal selectTWarehouseArea(Long fId);
 
 }

+ 45 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TWarehouseMapper.java

@@ -1,6 +1,9 @@
 package com.ruoyi.basicData.mapper;
 
-import com.ruoyi.basicData.domain.TWarehouse;
+
+import com.ruoyi.basicData.domain.TWarehouseArea;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -80,5 +83,46 @@ public interface TWarehouseMapper {
      */
     public TWarehouse checkUFAaddrUnique(String fAaddr);
 
+    /**
+     * 根据ID查询所有子部门(正常状态)
+     *
+     * @param fId 部门ID
+     * @return 子部门数
+     */
+    public int selectNormalChildrenDeptById(Long fId);
+
+    /**
+     * 根据ID查询所有子部门
+     *
+     * @param deptId 部门ID
+     * @return 部门列表
+     */
+    public List<TWarehouse> selectChildrenDeptById(Long deptId);
 
+    /**
+     * 修改子元素关系
+     *
+     * @param depts 子元素
+     * @return 结果
+     */
+    public int updateDeptChildren(@Param("depts") List<TWarehouse> depts);
+
+    /**
+     * 修改所在部门的父级部门状态
+     *
+     * @param tWarehouse 部门
+     */
+    public void updateDeptStatus(TWarehouse tWarehouse);
+
+
+    public int updatefTotalgross(TWarehouse tWarehouse);
+
+
+    /**
+     * 查询库区
+     *
+     * @param fId 库区ID
+     * @return 库区
+     */
+    public TWarehouse selectTWarehousById(Long fId);
 }

+ 0 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITCorpsService.java

@@ -1,7 +1,6 @@
 package com.ruoyi.basicData.service;
 
 import com.ruoyi.basicData.domain.TCorps;
-import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.model.LoginUser;
 

+ 7 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITWarehouseAreaService.java

@@ -2,6 +2,7 @@ package com.ruoyi.basicData.service;
 
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 
 import java.util.List;
 
@@ -59,4 +60,10 @@ public interface ITWarehouseAreaService {
      * @return 结果
      */
     public int deleteTWarehouseAreaById(Long fId);
+
+    /**
+     *  检验是否可添加库区
+     * @return
+     */
+    public String checkUFTWarehouseUnique(TWarehouseArea tWarehouseArea);
 }

+ 35 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/ITWarehouseService.java

@@ -1,8 +1,10 @@
 package com.ruoyi.basicData.service;
 
-import com.ruoyi.basicData.domain.TWarehouse;
+
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.TreeSelect;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 import com.ruoyi.common.core.domain.model.LoginUser;
 
 import java.util.List;
@@ -48,6 +50,8 @@ public interface ITWarehouseService {
      */
     public AjaxResult updateTWarehouse(TWarehouse tWarehouse);
 
+    public int updateTWarehouses(TWarehouse tWarehouse);
+
     /**
      * 批量删除仓库
      *
@@ -94,4 +98,34 @@ public interface ITWarehouseService {
      */
     public String checkUTWarehouseAreaFNnameUnique(TWarehouseArea tWarehouseAreas);
 
+    /**
+     * 根据ID查询所有子部门(正常状态)
+     *
+     * @param fId fID
+     * @return 子部门数
+     */
+    public int selectNormalChildrenDeptById(Long fId);
+
+    /**
+     * 构建前端所需要下拉树结构
+     *
+     * @param tWarehouses 部门列表
+     * @return 下拉树结构列表
+     */
+    public List<TreeSelect> buildDeptTreeSelect(List<TWarehouse> tWarehouses);
+
+    /**
+     * 构建前端所需要树结构
+     *
+     * @param depts 部门列表
+     * @return 树结构列表
+     */
+    public List<TWarehouse> buildDeptTree(List<TWarehouse> depts);
+
+    /**
+     *  检验是否可添加库区
+     * @return
+     */
+    public String checkUFAreUnique(TWarehouse tWarehouse);
+
 }

+ 0 - 2
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TCorpsServiceImpl.java

@@ -4,11 +4,9 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.basicData.domain.TCorps;
 import com.ruoyi.basicData.domain.TCustomerContact;
-import com.ruoyi.basicData.domain.TWarehouse;
 import com.ruoyi.basicData.mapper.TCorpsMapper;
 import com.ruoyi.basicData.mapper.TCustomerContactMapper;
 import com.ruoyi.basicData.service.ITCorpsService;
-import com.ruoyi.common.annotation.RepeatSubmit;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.model.LoginUser;

+ 53 - 2
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseAreaServiceImpl.java

@@ -2,9 +2,13 @@ package com.ruoyi.basicData.service.impl;
 
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import com.ruoyi.basicData.mapper.TWarehouseAreaMapper;
+import com.ruoyi.basicData.mapper.TWarehouseMapper;
 import com.ruoyi.basicData.service.ITWarehouseAreaService;
+import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
 import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems;
 import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
@@ -14,6 +18,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -30,6 +35,8 @@ public class TWarehouseAreaServiceImpl implements ITWarehouseAreaService {
     @Autowired
     private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;
 
+    @Autowired
+    private TWarehouseMapper tWarehouseMapper;
 
     /**
      * 查询库区
@@ -60,9 +67,17 @@ public class TWarehouseAreaServiceImpl implements ITWarehouseAreaService {
      * @return 结果
      */
     @Override
+    @Transactional
     public int insertTWarehouseArea(TWarehouseArea tWarehouseArea) {
         tWarehouseArea.setCreateTime(DateUtils.getNowDate());
-        return tWarehouseAreaMapper.insertTWarehouseArea(tWarehouseArea);
+        tWarehouseAreaMapper.insertTWarehouseArea(tWarehouseArea);
+        // 修改仓库库容
+        int i = updateWarehousefTotalgross(tWarehouseArea.getfWarehouseid());
+        if (i <= 0) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return 0;
+        }
+        return 1;
     }
 
     /**
@@ -72,9 +87,18 @@ public class TWarehouseAreaServiceImpl implements ITWarehouseAreaService {
      * @return 结果
      */
     @Override
+    @Transactional
     public int updateTWarehouseArea(TWarehouseArea tWarehouseArea) {
         tWarehouseArea.setUpdateTime(DateUtils.getNowDate());
-        return tWarehouseAreaMapper.updateTWarehouseArea(tWarehouseArea);
+        tWarehouseAreaMapper.updateTWarehouseArea(tWarehouseArea);
+        // 修改仓库库容
+        int i = updateWarehousefTotalgross(tWarehouseArea.getfWarehouseid());
+        if (i <= 0) {
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return 0;
+        }
+        return 1;
+
     }
 
     /**
@@ -109,4 +133,31 @@ public class TWarehouseAreaServiceImpl implements ITWarehouseAreaService {
     public int deleteTWarehouseAreaById(Long fId) {
         return tWarehouseAreaMapper.deleteTWarehouseAreaById(fId);
     }
+
+    @Override
+    public String checkUFTWarehouseUnique(TWarehouseArea tWarehouseArea) {
+        TWarehouse tWarehouse = tWarehouseMapper.selectTWarehousById(tWarehouseArea.getfWarehouseid());
+        if (StringUtils.isNotNull(tWarehouse) ) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
+
+    /**
+     *  修改仓库库容
+     * @param fWarehouseid
+     * @return
+     */
+    public  int updateWarehousefTotalgross(Long fWarehouseid){
+        // 查询仓库
+        TWarehouse tWarehouse =tWarehouseMapper.selectTWarehouseById(fWarehouseid);
+        String newfWarehouseid =tWarehouse.getAncestors().substring(tWarehouse.getAncestors().lastIndexOf(",")+1);
+        // 所有库容
+        BigDecimal fTotalgross = tWarehouseAreaMapper.selectTWarehouseArea(fWarehouseid);
+        // 修改仓库扩容
+        TWarehouse tWarehouseNew = new TWarehouse();
+        tWarehouseNew.setfId(Long.valueOf(newfWarehouseid));
+        tWarehouseNew.setfTotalgross(fTotalgross);
+        return  tWarehouseMapper.updatefTotalgross(tWarehouseNew);
+    }
 }

+ 141 - 5
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseServiceImpl.java

@@ -2,14 +2,16 @@ package com.ruoyi.basicData.service.impl;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.basicData.domain.TWarehouse;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 import com.ruoyi.basicData.domain.TWarehouseArea;
 import com.ruoyi.basicData.mapper.TWarehouseAreaMapper;
 import com.ruoyi.basicData.mapper.TWarehouseMapper;
 import com.ruoyi.basicData.service.ITWarehouseService;
 import com.ruoyi.common.constant.UserConstants;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.TreeSelect;
 import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.exception.CustomException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
@@ -19,10 +21,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 仓库Service业务层处理
@@ -90,6 +90,12 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
     @Transactional
     public int insertTWarehouse(TWarehouse tWarehouse) {
         tWarehouse.setCreateTime(DateUtils.getNowDate());
+        TWarehouse info = tWarehouseMapper.selectTWarehouseById(tWarehouse.getParentId());
+        // 如果父节点不为正常状态,则不允许新增子节点
+        if (!UserConstants.DEPT_NORMAL.equals(info.getfStatus())) {
+            throw new CustomException("部门停用,不允许新增");
+        }
+        tWarehouse.setAncestors(info.getAncestors() + "," + tWarehouse.getParentId());
         return tWarehouseMapper.insertTWarehouse(tWarehouse);
     }
 
@@ -172,6 +178,53 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
         return AjaxResult.success();
     }
 
+    @Override
+    public int updateTWarehouses(TWarehouse tWarehouse) {
+        TWarehouse newParentTWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getParentId());
+        TWarehouse oldTWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getfId());
+        if (StringUtils.isNotNull(newParentTWarehouse) && StringUtils.isNotNull(oldTWarehouse)) {
+            String newAncestors = newParentTWarehouse.getAncestors() + "," + newParentTWarehouse.getfId();
+            String oldAncestors = oldTWarehouse.getAncestors();
+            tWarehouse.setAncestors(newAncestors);
+            updateDeptChildren(tWarehouse.getfId(), newAncestors, oldAncestors);
+        }
+        int result = tWarehouseMapper.updateTWarehouse(tWarehouse);
+        if (UserConstants.DEPT_NORMAL.equals(tWarehouse.getfStatus())) {
+            // 如果该部门是启用状态,则启用该部门的所有上级部门
+            updateParentDeptStatus(tWarehouse);
+        }
+        return result;
+    }
+
+    /**
+     * 修改子元素关系
+     *
+     * @param deptId       被修改的部门ID
+     * @param newAncestors 新的父ID集合
+     * @param oldAncestors 旧的父ID集合
+     */
+    public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
+        List<TWarehouse> children = tWarehouseMapper.selectChildrenDeptById(deptId);
+        for (TWarehouse child : children) {
+            child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
+        }
+        if (children.size() > 0) {
+            tWarehouseMapper.updateDeptChildren(children);
+        }
+    }
+
+    /**
+     * 修改该部门的父级部门状态
+     *
+     * @param tWarehouse 当前部门
+     */
+    private void updateParentDeptStatus(TWarehouse tWarehouse) {
+        String updateBy = tWarehouse.getUpdateBy();
+        tWarehouse = tWarehouseMapper.selectTWarehouseById(tWarehouse.getfId());
+        tWarehouse.setUpdateBy(updateBy);
+        tWarehouseMapper.updateDeptStatus(tWarehouse);
+    }
+
     /**
      * 批量删除仓库
      *
@@ -255,4 +308,87 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
         return UserConstants.UNIQUE;
     }
 
+    @Override
+    public int selectNormalChildrenDeptById(Long fId) {
+        return tWarehouseMapper.selectNormalChildrenDeptById(fId);
+    }
+
+    @Override
+    public List<TreeSelect> buildDeptTreeSelect(List<TWarehouse> tWarehouses) {
+        List<TWarehouse> deptTrees = buildDeptTree(tWarehouses);
+        return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
+    }
+
+    /**
+     * 构建前端所需要树结构
+     *
+     * @param depts 部门列表
+     * @return 树结构列表
+     */
+    @Override
+    public List<TWarehouse> buildDeptTree(List<TWarehouse> depts) {
+        List<TWarehouse> returnList = new ArrayList<TWarehouse>();
+        List<Long> tempList = new ArrayList<Long>();
+        for (TWarehouse dept : depts) {
+            tempList.add(dept.getfId());
+        }
+        for (Iterator<TWarehouse> iterator = depts.iterator(); iterator.hasNext(); ) {
+            TWarehouse dept = (TWarehouse) iterator.next();
+            // 如果是顶级节点, 遍历该父节点的所有子节点
+            if (!tempList.contains(dept.getParentId())) {
+                recursionFn(depts, dept);
+                returnList.add(dept);
+            }
+        }
+        if (returnList.isEmpty()) {
+            returnList = depts;
+        }
+        return returnList;
+    }
+
+    @Override
+    public String checkUFAreUnique(TWarehouse tWarehouse) {
+        TWarehouseArea tWarehouseArea = tWarehouseAreaMapper.selectTWarehouseAreaByWarehouseId(tWarehouse.getParentId());
+        if (StringUtils.isNotNull(tWarehouseArea) ) {
+            return UserConstants.NOT_UNIQUE;
+        }
+        return UserConstants.UNIQUE;
+    }
+
+    /**
+     * 递归列表
+     */
+    private void recursionFn(List<TWarehouse> list, TWarehouse t) {
+        // 得到子节点列表
+        List<TWarehouse> childList = getChildList(list, t);
+        t.setChildren(childList);
+        for (TWarehouse tChild : childList) {
+            if (hasChild(list, tChild)) {
+                recursionFn(list, tChild);
+            }
+        }
+    }
+
+    /**
+     * 得到子节点列表
+     */
+    private List<TWarehouse> getChildList(List<TWarehouse> list, TWarehouse t) {
+        List<TWarehouse> tlist = new ArrayList<TWarehouse>();
+        Iterator<TWarehouse> it = list.iterator();
+        while (it.hasNext()) {
+            TWarehouse n = (TWarehouse) it.next();
+            if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getfId().longValue()) {
+                tlist.add(n);
+            }
+        }
+        return tlist;
+    }
+
+    /**
+     * 判断是否有子节点
+     */
+    private boolean hasChild(List<TWarehouse> list, TWarehouse t) {
+        return getChildList(list, t).size() > 0 ? true : false;
+    }
+
 }

+ 2 - 1
ruoyi-warehouse/src/main/java/com/ruoyi/reportManagement/service/impl/TWhgenlegServiceImpl.java

@@ -1,7 +1,8 @@
 package com.ruoyi.reportManagement.service.impl;
 
 
-import com.ruoyi.basicData.domain.TWarehouse;
+
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 import com.ruoyi.basicData.mapper.TWarehouseMapper;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.reportManagement.domain.TWhgenleg;

+ 1 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/warehouseBusiness/service/impl/TWarehouseBillsServiceImpl.java

@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.interceptor.TransactionAspectSupport;
+import com.ruoyi.common.core.domain.entity.TWarehouse;
 
 import java.math.BigDecimal;
 import java.util.*;

+ 29 - 9
ruoyi-warehouse/src/main/resources/mapper/basicData/TWarehouseAreaMapper.xml

@@ -9,6 +9,7 @@
         <result property="fWarehouseid" column="f_warehouseid"/>
         <result property="fNo" column="f_no"/>
         <result property="fName" column="f_name"/>
+        <result property="fTotalgross"    column="f_totalgross"    />
         <result property="fAddr" column="f_addr"/>
         <result property="fStatus" column="f_status"/>
         <result property="delFlag" column="del_flag"/>
@@ -20,18 +21,21 @@
     </resultMap>
 
     <sql id="selectTWarehouseAreaVo">
-        select f_id, f_warehouseid, f_no, f_name, f_addr, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_warehouse_area
+        select f_id, f_warehouseid, f_no, f_name, f_totalgross ,f_addr, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_warehouse_area
     </sql>
 
     <select id="selectTWarehouseAreaList" parameterType="TWarehouseArea" resultMap="TWarehouseAreaResult">
-        <include refid="selectTWarehouseAreaVo"/>
-        <where>
-            <if test="fWarehouseid != null ">and f_warehouseid = #{fWarehouseid}</if>
-            <if test="fNo != null  and fNo != ''">and f_no = #{fNo}</if>
-            <if test="fName != null  and fName != ''">and f_name like concat('%', #{fName}, '%')</if>
-            <if test="fAddr != null  and fAddr != ''">and f_addr = #{fAddr}</if>
-            <if test="fStatus != null  and fStatus != ''">and f_status = #{fStatus}</if>
-        </where>
+        select a.f_id, a.f_warehouseid, a.f_no, a.f_name,a.f_totalgross, a.f_addr, a.f_status, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.remark from t_warehouse_area a
+        left join t_warehouse w on w.f_id = a.f_warehouseid
+        where a.del_flag = '0'
+        <if test="fNo != null  and fNo != ''">and a.f_no = #{fNo}</if>
+        <if test="fName != null  and fName != ''">and a.f_name like concat('%', #{fName}, '%')</if>
+        <if test="fStatus != null  and fStatus != ''">and a.f_status = #{fStatus}</if>
+        <if test="fWarehouseid != null and fWarehouseid != 0">
+            AND (a.f_warehouseid = #{fWarehouseid} OR a.f_warehouseid IN ( SELECT t.f_id FROM t_warehouse t WHERE find_in_set(#{fWarehouseid}, ancestors) ))
+        </if>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
     </select>
 
     <select id="selectTWarehouseAreaById" parameterType="Long" resultMap="TWarehouseAreaResult">
@@ -45,6 +49,7 @@
             <if test="fWarehouseid != null">f_warehouseid,</if>
             <if test="fNo != null and fNo != ''">f_no,</if>
             <if test="fName != null and fName != ''">f_name,</if>
+            <if test="fTotalgross != null">f_totalgross,</if>
             <if test="fAddr != null and fAddr != ''">f_addr,</if>
             <if test="fStatus != null">f_status,</if>
             <if test="delFlag != null">del_flag,</if>
@@ -58,6 +63,7 @@
             <if test="fWarehouseid != null">#{fWarehouseid},</if>
             <if test="fNo != null and fNo != ''">#{fNo},</if>
             <if test="fName != null and fName != ''">#{fName},</if>
+            <if test="fTotalgross != null">#{fTotalgross},</if>
             <if test="fAddr != null and fAddr != ''">#{fAddr},</if>
             <if test="fStatus != null">#{fStatus},</if>
             <if test="delFlag != null">#{delFlag},</if>
@@ -75,6 +81,7 @@
             <if test="fWarehouseid != null">f_warehouseid = #{fWarehouseid},</if>
             <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
             <if test="fName != null and fName != ''">f_name = #{fName},</if>
+            <if test="fTotalgross != null">f_totalgross = #{fTotalgross},</if>
             <if test="fAddr != null and fAddr != ''">f_addr = #{fAddr},</if>
             <if test="fStatus != null">f_status = #{fStatus},</if>
             <if test="delFlag != null">del_flag = #{delFlag},</if>
@@ -110,4 +117,17 @@
         select f_id,f_name from t_warehouse_area where f_name = #{fNname}  and f_warehouseid = #{fWarehouseid} limit 1
     </select>
 
+    <select id="selectTWarehouseAreaByWarehouseId" resultMap="TWarehouseAreaResult">
+        select f_id  from t_warehouse_area  where f_warehouseid = #{fId} limit 1
+    </select>
+
+    <select id="selectTWarehouseArea" resultType="java.math.BigDecimal">
+        SELECT
+            sum( f_totalgross ) AS fTotalgross
+        FROM
+            t_warehouse_area
+        WHERE
+            f_warehouseid = #{fId}
+    </select>
+
 </mapper>

+ 58 - 1
ruoyi-warehouse/src/main/resources/mapper/basicData/TWarehouseMapper.xml

@@ -6,6 +6,9 @@
 
     <resultMap type="TWarehouse" id="TWarehouseResult">
         <result property="fId"    column="f_id"    />
+        <result property="parentId" column="parent_id"/>
+        <result property="ancestors" column="ancestors"/>
+        <result property="orderNum" column="order_num"/>
         <result property="fNo"    column="f_no"    />
         <result property="fName"    column="f_name"    />
         <result property="fAddr"    column="f_addr"    />
@@ -23,7 +26,7 @@
     </resultMap>
 
     <sql id="selectTWarehouseVo">
-        select f_id, f_no, f_name, f_addr, f_totalgross,f_contacts, f_tel, f_charg, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_warehouse
+        select f_id, parent_id, ancestors,  order_num, f_no, f_name, f_addr, f_totalgross,f_contacts, f_tel, f_charg, f_status, del_flag, create_by, create_time, update_by, update_time, remark from t_warehouse
     </sql>
 
     <select id="selectTWarehouseList" parameterType="TWarehouse" resultMap="TWarehouseResult">
@@ -38,6 +41,9 @@
             <if test="fCharg != null "> and f_charg = #{fCharg}</if>
             <if test="fStatus != null  and fStatus != ''"> and f_status = #{fStatus}</if>
         </where>
+        <!-- 数据范围过滤 -->
+        ${params.dataScope}
+        order by parent_id, order_num
     </select>
 
     <select id="selectTWarehouseById" parameterType="Long" resultMap="TWarehouseResult">
@@ -48,6 +54,9 @@
     <insert id="insertTWarehouse" parameterType="TWarehouse" useGeneratedKeys="true" keyProperty="fId">
         insert into t_warehouse
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="parentId != null and parentId != 0">parent_id,</if>
+            <if test="ancestors != null and ancestors != ''">ancestors,</if>
+            <if test="orderNum != null and orderNum != ''">order_num,</if>
             <if test="fNo != null and fNo != ''">f_no,</if>
             <if test="fName != null and fName != ''">f_name,</if>
             <if test="fAddr != null and fAddr != ''">f_addr,</if>
@@ -64,6 +73,9 @@
             <if test="remark != null">remark,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="parentId != null and parentId != 0">#{parentId},</if>
+            <if test="ancestors != null and ancestors != ''">#{ancestors},</if>
+            <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
             <if test="fNo != null and fNo != ''">#{fNo},</if>
             <if test="fName != null and fName != ''">#{fName},</if>
             <if test="fAddr != null and fAddr != ''">#{fAddr},</if>
@@ -84,6 +96,9 @@
     <update id="updateTWarehouse" parameterType="TWarehouse">
         update t_warehouse
         <trim prefix="SET" suffixOverrides=",">
+            <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
+            <if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
+            <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
             <if test="fNo != null and fNo != ''">f_no = #{fNo},</if>
             <if test="fName != null and fName != ''">f_name = #{fName},</if>
             <if test="fAddr != null and fAddr != ''">f_addr = #{fAddr},</if>
@@ -125,4 +140,46 @@
         select f_id,f_addr from t_warehouse where f_addr = #{fAddr} limit 1
     </select>
 
+    <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
+        select count(*) from t_warehouse where f_status = 0 and del_flag = '0' and find_in_set(#{fId}, ancestors)
+    </select>
+
+    <select id="selectChildrenDeptById" parameterType="Long" resultMap="TWarehouseResult">
+        select * from t_warehouse where find_in_set(#{fId}, ancestors)
+    </select>
+    <select id="selectTWarehousById" resultMap="TWarehouseResult">
+        select f_id  from t_warehouse  where parent_id = #{fId} limit 1
+    </select>
+
+    <update id="updateDeptChildren" parameterType="java.util.List">
+        update t_warehouse set ancestors =
+        <foreach collection="depts" item="item" index="index"
+                 separator=" " open="case f_id" close="end">
+            when #{item.fId} then #{item.ancestors}
+        </foreach>
+        where f_id in
+        <foreach collection="depts" item="item" index="index"
+                 separator="," open="(" close=")">
+            #{item.fId}
+        </foreach>
+    </update>
+
+    <update id="updateDeptStatus" parameterType="TWarehouse">
+        update t_warehouse
+        <set>
+            <if test="fStatus != null and fStatus != ''">f_status = #{fStatus},</if>
+            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
+            update_time = sysdate()
+        </set>
+        where f_id in (${ancestors})
+    </update>
+    <update id="updatefTotalgross">
+        update t_warehouse
+        <set>
+            <if test="fTotalgross != null and fTotalgross != ''">f_totalgross =  #{fTotalgross},</if>
+            update_time = sysdate()
+        </set>
+        where f_id =  #{fId}
+    </update>
+
 </mapper>