浏览代码

[CODE]: 仓库信息添加从表信息、从表删除查询

maxianghua 4 年之前
父节点
当前提交
5f4e91c21f

+ 21 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/basicData/TWarehouseController.java

@@ -5,9 +5,13 @@ import com.ruoyi.basicData.service.ITWarehouseService;
 import com.ruoyi.common.annotation.Log;
 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.poi.ExcelUtil;
+import com.ruoyi.common.utils.spring.SpringUtils;
+import com.ruoyi.framework.web.service.TokenService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -55,17 +59,29 @@ 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.selectTWarehouseById(fId));
+        return AjaxResult.success(tWarehouseService.selectTWarehouseById1(fId));
     }
 
     /**
      * 新增仓库
      */
-    @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
+   /* @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
     @Log(title = "仓库", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TWarehouse tWarehouse) {
         return toAjax(tWarehouseService.insertTWarehouse(tWarehouse));
+    }*/
+
+    /**
+     * 新增仓库
+     */
+    @PreAuthorize("@ss.hasPermi('basicdata:warehouse:add')")
+    @Log(title = "仓库", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestParam("tWarehouse") String tWarehouse, @RequestParam("tWarehouseArea") String tWarehouseArea) {
+        // 获取当前的用户
+        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
+        return tWarehouseService.insertTWarehouse1(tWarehouse, tWarehouseArea, loginUser);
     }
 
     /**
@@ -87,4 +103,7 @@ public class TWarehouseController extends BaseController {
     public AjaxResult remove(@PathVariable Long[] fIds) {
         return toAjax(tWarehouseService.deleteTWarehouseByIds(fIds));
     }
+
+
+
 }

+ 2 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/mapper/TWarehouseAreaMapper.java

@@ -51,6 +51,8 @@ public interface TWarehouseAreaMapper {
      */
     public int deleteTWarehouseAreaById(Long fId);
 
+    public int deleteTWarehouseAreaByTWarehoused(Long fId);
+
     /**
      * 批量删除库区
      *

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

@@ -1,8 +1,11 @@
 package com.ruoyi.basicData.service;
 
 import com.ruoyi.basicData.domain.TWarehouse;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.model.LoginUser;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 仓库Service接口
@@ -18,6 +21,7 @@ public interface ITWarehouseService {
      * @return 仓库
      */
     public TWarehouse selectTWarehouseById(Long fId);
+    public Map<String, Object> selectTWarehouseById1(Long fId);
 
     /**
      * 查询仓库列表
@@ -34,7 +38,7 @@ public interface ITWarehouseService {
      * @return 结果
      */
     public int insertTWarehouse(TWarehouse tWarehouse);
-
+    public AjaxResult insertTWarehouse1(String tWarehouse, String tWarehouseArea, LoginUser loginUser);
     /**
      * 修改仓库
      *

+ 68 - 0
ruoyi-warehouse/src/main/java/com/ruoyi/basicData/service/impl/TWarehouseServiceImpl.java

@@ -1,13 +1,27 @@
 package com.ruoyi.basicData.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.ruoyi.basicData.domain.TCorps;
+import com.ruoyi.basicData.domain.TCustomerContact;
 import com.ruoyi.basicData.domain.TWarehouse;
+import com.ruoyi.basicData.domain.TWarehouseArea;
+import com.ruoyi.basicData.mapper.TCustomerContactMapper;
+import com.ruoyi.basicData.mapper.TWarehouseAreaMapper;
 import com.ruoyi.basicData.mapper.TWarehouseMapper;
 import com.ruoyi.basicData.service.ITWarehouseService;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 仓库Service业务层处理
@@ -20,6 +34,9 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
     @Autowired
     private TWarehouseMapper tWarehouseMapper;
 
+    @Autowired
+    private TWarehouseAreaMapper tWarehouseAreaMapper;
+
     /**
      * 查询仓库
      *
@@ -31,6 +48,22 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
         return tWarehouseMapper.selectTWarehouseById(fId);
     }
 
+    @Override
+    public Map<String, Object> selectTWarehouseById1(Long fId) {
+        Map<String, Object> map = new HashMap<>();
+        TWarehouse tWarehouse = tWarehouseMapper.selectTWarehouseById(fId);
+        if (StringUtils.isNotNull(tWarehouse)) {
+            map.put("tWarehouse", tWarehouse);
+        }
+        TWarehouseArea tWarehouseArea=  new TWarehouseArea();
+        tWarehouseArea.setfWarehouseid(fId);
+        List<TWarehouseArea> tWarehouseAreaList =tWarehouseAreaMapper.selectTWarehouseAreaList(tWarehouseArea);
+        if (StringUtils.isNotEmpty(tWarehouseAreaList)) {
+            map.put("tWarehouseArea", tWarehouseAreaList);
+        }
+        return map;
+    }
+
     /**
      * 查询仓库列表
      *
@@ -54,6 +87,41 @@ public class TWarehouseServiceImpl implements ITWarehouseService {
         return tWarehouseMapper.insertTWarehouse(tWarehouse);
     }
 
+    @Override
+    public AjaxResult insertTWarehouse1(String tWarehouse, String tWarehouseArea, LoginUser loginUser) {
+        if (StringUtils.isEmpty(tWarehouse)) {
+            return AjaxResult.error("提交失败:仓库信息为空");
+        }
+        if ( StringUtils.isEmpty(tWarehouseArea) ) {
+            return AjaxResult.error("提交失败:库区为空");
+        }
+        Long fPid = null;
+        TWarehouse tWarehouses = JSONArray.parseObject(tWarehouse, TWarehouse.class);
+        JSONArray jsonArray = JSONArray.parseArray(tWarehouseArea);
+        List<TWarehouseArea> tWarehouseAreaList = JSONObject.parseArray(jsonArray.toJSONString(), TWarehouseArea.class);
+        tWarehouses.setfStatus("0");
+        if (StringUtils.isNull(tWarehouses.getfId())) {
+            tWarehouses.setCreateBy(loginUser.getUser().getUserName());
+            tWarehouses.setCreateTime(new Date());
+            tWarehouseMapper.insertTWarehouse(tWarehouses);
+            fPid=tWarehouses.getfId();
+        } else {
+            fPid=tWarehouses.getfId();
+            tWarehouses.setUpdateBy(loginUser.getUser().getUserName());
+            tWarehouses.setUpdateTime(new Date());
+            tWarehouseMapper.updateTWarehouse(tWarehouses);
+            tWarehouseAreaMapper.deleteTWarehouseAreaByTWarehoused(fPid);
+        }
+        for (TWarehouseArea cc : tWarehouseAreaList) {
+            cc.setfWarehouseid(fPid);
+            cc.setfStatus("0");
+            cc.setCreateBy(loginUser.getUser().getUserName());
+            cc.setCreateTime(new Date());
+            tWarehouseAreaMapper.insertTWarehouseArea(cc);
+        }
+        return AjaxResult.success();
+    }
+
     /**
      * 修改仓库
      *

+ 4 - 0
ruoyi-warehouse/src/main/resources/mapper/basicData/TWarehouseAreaMapper.xml

@@ -91,6 +91,10 @@
         delete from t_warehouse_area where f_id = #{fId}
     </delete>
 
+    <delete id="deleteTWarehouseAreaByTWarehoused" parameterType="Long">
+        delete from t_warehouse_area where f_warehouseid = #{fId}
+    </delete>
+
     <delete id="deleteTWarehouseAreaByIds" parameterType="String">
         delete from t_warehouse_area where f_id in
         <foreach item="fId" collection="array" open="(" separator="," close=")">