Browse Source

添加栋舍基础

523096025 2 năm trước cách đây
mục cha
commit
fecc09c4ba

+ 18 - 0
huimv-admin/src/main/java/com/huimv/admin/common/utils/ResultUtil.java

@@ -35,6 +35,24 @@ public class ResultUtil {
             return new Result(10001, "添加失败",false);
         }
     }
+    public static Result updateResult(Integer rows){
+        if(rows > 0){
+            return new Result(10000, "修改成功",true);
+        }else{
+            return new Result(10001, "修改失败",false);
+        }
+    }
+    public static Result deleteResult(Integer rows){
+        if(rows > 0){
+            return new Result(10000, "删除成功",true);
+        }else{
+            return new Result(10001, "删除失败",false);
+        }
+    }
+
+    public static Result exist(){
+       return new Result(10001, "该数据已存在",false);
+    }
     public static Result isNull(){
         return new Result(ResultCode.DATA_NULL);
     }

+ 35 - 4
huimv-admin/src/main/java/com/huimv/admin/controller/BasePigpenController.java

@@ -2,6 +2,7 @@ package com.huimv.admin.controller;
 
 
 import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.common.utils.ResultUtil;
 import com.huimv.admin.entity.BasePigpen;
 import com.huimv.admin.entity.dto.BasePigpenDto;
 import com.huimv.admin.service.IBasePigpenService;
@@ -30,6 +31,36 @@ public class BasePigpenController {
         return basePigpenService.addPigpen(basePigpenDto);
     }
 
+    @PostMapping( "/addUnit")
+    public Result addUnit(@RequestBody BasePigpen basePigpen) {
+        BasePigpen byId = basePigpenService.getById(basePigpen.getParentId());
+        String parentIds = byId.getOther2() + "," + basePigpen.getParentId();
+        basePigpen.setFType(3);
+        basePigpen.setOther2(parentIds);
+        if ( basePigpenService.save(basePigpen)){
+            return ResultUtil.addResult(1);
+        }
+        return ResultUtil.addResult(0);
+    }
+
+    @PostMapping( "/updatePigpen")
+    public Result updatePigpen(@RequestBody BasePigpen basePigpen) {
+         return  basePigpenService.updatePigpen(basePigpen);
+    }
+
+    @PostMapping( "/updateUnit")
+    public Result updateUnit(@RequestBody BasePigpen basePigpen) {
+        if ( basePigpenService.updateById(basePigpen)){
+            return ResultUtil.addResult(1);
+        }
+        return ResultUtil.addResult(0);
+    }
+
+    @PostMapping( "/deletePigpen")
+    public Result deletePigpen(@RequestBody Map<String,Integer> map) {
+        return  basePigpenService.deletePigpen(map);
+    }
+
     @RequestMapping(value = "/list",method = RequestMethod.POST)
     public Result list(@RequestBody Map<String, Object> paramsMap) {
         System.out.println("paramsMap>>"+paramsMap.toString());
@@ -41,10 +72,10 @@ public class BasePigpenController {
         if (paramsMap.get("stageCode") != null) {
             stageCode = paramsMap.get("stageCode")+"";
         }
-        String pigpenName = "";
-        if (paramsMap.get("pigpenName") != null) {
-            pigpenName = paramsMap.get("pigpenName")+"";
+        String buildName = "";
+        if (paramsMap.get("buildName") != null) {
+            buildName = paramsMap.get("buildName")+"";
         }
-        return basePigpenService.list(farmCode,pigpenName,stageCode);
+        return basePigpenService.list(farmCode,buildName,stageCode);
     }
 }

+ 7 - 1
huimv-admin/src/main/java/com/huimv/admin/service/IBasePigpenService.java

@@ -5,6 +5,8 @@ import com.huimv.admin.entity.BasePigpen;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.huimv.admin.entity.dto.BasePigpenDto;
 
+import java.util.Map;
+
 /**
  * <p>
  *  服务类
@@ -15,7 +17,11 @@ import com.huimv.admin.entity.dto.BasePigpenDto;
  */
 public interface IBasePigpenService extends IService<BasePigpen> {
 
-    Result list(String farmCode, String pigpenName, String stageCode);
+    Result list(String farmCode, String buildName, String stageCode);
 
     Result addPigpen(BasePigpenDto basePigpenDto);
+
+    Result updatePigpen(BasePigpen basePigpen);
+
+    Result deletePigpen(Map<String, Integer> map);
 }

+ 41 - 6
huimv-admin/src/main/java/com/huimv/admin/service/impl/BasePigpenServiceImpl.java

@@ -39,28 +39,63 @@ public class BasePigpenServiceImpl extends ServiceImpl<BasePigpenMapper, BasePig
     @Override
     @Transactional
     public Result addPigpen(BasePigpenDto basePigpenDto) {
+        Integer  num = basePigpenMapper.selectCount(new QueryWrapper<BasePigpen>().eq("build_name", basePigpenDto.getBuildName()));
+        if (num  > 0){
+            return ResultUtil.exist();
+        }
         BasePigpen basePigpen = new BasePigpen();
-        BeanUtil.copyProperties(basePigpen,basePigpenDto);
+        BeanUtil.copyProperties(basePigpenDto,basePigpen);
         basePigpen.setParentId(0);
         basePigpen.setFType(1);
+        basePigpen.setOther2("0");
+        Integer id = basePigpen.getId();
+        String buildName = basePigpen.getBuildName();
         int insert = basePigpenMapper.insert(basePigpen);
         Integer floorNum = basePigpenDto.getFloorNum();
         for (Integer integer = 1; integer <= floorNum; integer++) {
             BasePigpen basePigpen1 = new BasePigpen();
             basePigpen1.setFType(2);
-            basePigpen1.setParentId(insert);
-            basePigpen1.setBuildName(Convert.numberToChinese(integer,false));
+            basePigpen1.setParentId(id);
+            basePigpen1.setBuildName(buildName+Convert.numberToChinese(integer,false) +"层");
+            basePigpen1.setOther1(Convert.numberToChinese(integer,false) +"层");
+            basePigpen1.setOther2("0,"+id);
             basePigpen1.setFarmId(basePigpen.getFarmId());
             basePigpen1.setStageCode(basePigpen.getStageCode());
+            basePigpenMapper.insert(basePigpen1);
         }
-
         return ResultUtil.addResult(insert);
     }
 
     @Override
-    public Result list(String farmCode, String pigpenName, String stageCode) {
+    @Transactional
+    public Result updatePigpen(BasePigpen basePigpen) {
+        basePigpenMapper.updateById(basePigpen);
+        Integer id = basePigpen.getId();
+        List<BasePigpen> parentId = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().eq("parent_id", id));
+        String buildName = basePigpen.getBuildName();
+        if (StringUtils.isNotBlank(buildName)){
+            for (BasePigpen pigpen : parentId) {
+                String other1 = pigpen.getOther1();
+                pigpen.setBuildName(buildName+other1);
+                basePigpenMapper.updateById(pigpen);
+            }
+        }
+        return ResultUtil.updateResult(1);
+    }
+
+    @Override
+    public Result deletePigpen(Map<String, Integer> map) {
+        Integer integer = map.get("id");
+        List<BasePigpen> other2 = basePigpenMapper.selectList(new QueryWrapper<BasePigpen>().like("other2", integer));
+        basePigpenMapper.deleteBatchIds(other2);
+        basePigpenMapper.deleteById(integer);
+        return ResultUtil.deleteResult(1);
+    }
+
+    @Override
+    public Result list(String farmCode, String buildName, String stageCode) {
         QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
-        queryWrapper.like(StringUtils.isNotBlank(pigpenName),"pigpen_name", pigpenName);
+        queryWrapper.like(StringUtils.isNotBlank(buildName),"build_name", buildName);
         queryWrapper.like(StringUtils.isNotBlank(stageCode),"stage_code", stageCode);
         queryWrapper.eq(StringUtils.isNotBlank(farmCode),"farm_code", farmCode);
         //创建排序

+ 8 - 8
huimv-admin/src/main/resources/application-dev.yml

@@ -21,15 +21,15 @@ spring:
 #    virtual-host: /
 
   #redis
-  redis:
-    host: 122.112.224.199
-    port: 6379
-    password: hm123456
+#  redis:
+#    host: 122.112.224.199
+#    port: 6379
+#    password: hm123456
 #  Nacos 配置
-  cloud:
-    nacos:
-      discovery:
-        server-addr: 192.168.1.68:8848 #配置nacos地址
+#  cloud:
+#    nacos:
+#      discovery:
+#        server-addr: 192.168.1.68:8848 #配置nacos地址