|
@@ -2,8 +2,10 @@ package com.huimv.env.admin.controller;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.huimv.env.common.entity.BasePigpen;
|
|
|
+import com.huimv.env.common.mapper.BasePigpenMapper;
|
|
|
import com.huimv.env.common.service.IBasePigpenService;
|
|
|
import com.huimv.env.common.utils.Result;
|
|
|
import com.huimv.env.common.utils.ResultUtil;
|
|
@@ -11,6 +13,8 @@ import com.huimv.env.common.entity.dto.BasePigpenDto;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -27,6 +31,8 @@ import java.util.Map;
|
|
|
public class BasePigpenController {
|
|
|
@Autowired
|
|
|
private IBasePigpenService basePigpenService;
|
|
|
+ @Autowired
|
|
|
+ private BasePigpenMapper basePigpenMapper;
|
|
|
|
|
|
@PostMapping( "/addPigpen")
|
|
|
public Result addPigpen(@RequestBody BasePigpenDto basePigpenDto) {
|
|
@@ -34,12 +40,32 @@ public class BasePigpenController {
|
|
|
}
|
|
|
|
|
|
@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)){
|
|
|
+ public Result addUnit(@RequestBody Map<String,String> map) {
|
|
|
+ String farmId = map.get("farmId");
|
|
|
+ String parentId = map.get("parentId");
|
|
|
+ int buildNum = Integer.valueOf(map.get("buildNum"));
|
|
|
+ String stageCode = map.get("stageCode");
|
|
|
+ BasePigpen parent = basePigpenService.getById(parentId);
|
|
|
+ String parentIds = parent.getOther2() + "," + parentId;
|
|
|
+ int maxBuildNum = 0;
|
|
|
+ if (ObjectUtil.isNotEmpty(basePigpenMapper.getMaxBuildNum(parentId))) {
|
|
|
+ maxBuildNum = basePigpenMapper.getMaxBuildNum(parentId);
|
|
|
+ }
|
|
|
+ List<BasePigpen> basePigpenList = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= buildNum; i++) {
|
|
|
+ int num = maxBuildNum+i;
|
|
|
+ BasePigpen basePigpen = new BasePigpen();
|
|
|
+ basePigpen.setBuildName(parent.getBuildName()+num+"单元");
|
|
|
+ basePigpen.setParentId(Integer.valueOf(parentId));
|
|
|
+ basePigpen.setFType(3);
|
|
|
+ basePigpen.setStageCode(Integer.valueOf(stageCode));
|
|
|
+ basePigpen.setFarmId(Integer.valueOf(farmId));
|
|
|
+ basePigpen.setOther1(String.valueOf(num));
|
|
|
+ basePigpen.setOther2(parentIds);
|
|
|
+ basePigpenList.add(basePigpen);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( basePigpenService.saveBatch(basePigpenList)){
|
|
|
return ResultUtil.addResult(1);
|
|
|
}
|
|
|
return ResultUtil.addResult(0);
|