|
@@ -7,10 +7,14 @@ import com.huimv.admin.common.utils.Result;
|
|
import com.huimv.admin.common.utils.ResultUtil;
|
|
import com.huimv.admin.common.utils.ResultUtil;
|
|
import com.huimv.admin.entity.BasePigpen;
|
|
import com.huimv.admin.entity.BasePigpen;
|
|
import com.huimv.admin.entity.dto.BasePigpenDto;
|
|
import com.huimv.admin.entity.dto.BasePigpenDto;
|
|
|
|
+import com.huimv.admin.mapper.BasePigpenMapper;
|
|
import com.huimv.admin.service.IBasePigpenService;
|
|
import com.huimv.admin.service.IBasePigpenService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -28,25 +32,39 @@ public class BasePigpenController {
|
|
@Autowired
|
|
@Autowired
|
|
private IBasePigpenService basePigpenService;
|
|
private IBasePigpenService basePigpenService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private BasePigpenMapper basePigpenMapper;
|
|
|
|
+
|
|
@PostMapping( "/addPigpen")
|
|
@PostMapping( "/addPigpen")
|
|
public Result addPigpen(@RequestBody BasePigpenDto basePigpenDto) {
|
|
public Result addPigpen(@RequestBody BasePigpenDto basePigpenDto) {
|
|
return basePigpenService.addPigpen(basePigpenDto);
|
|
return basePigpenService.addPigpen(basePigpenDto);
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping( "/addUnit")
|
|
@PostMapping( "/addUnit")
|
|
- public Result addUnit(@RequestBody BasePigpen basePigpen) {
|
|
|
|
- QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.eq("farm_id", basePigpen.getFarmId()).eq("f_type", 3).eq("build_name", basePigpen.getBuildName());
|
|
|
|
- BasePigpen pigpen = basePigpenService.getOne(queryWrapper);
|
|
|
|
- if (ObjectUtil.isNotEmpty(pigpen)) {
|
|
|
|
- return ResultUtil.addResult(0);
|
|
|
|
|
|
+ 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 = 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);
|
|
}
|
|
}
|
|
- BasePigpen byId = basePigpenService.getById(basePigpen.getParentId());
|
|
|
|
- String parentIds = byId.getOther2() + "," + basePigpen.getParentId();
|
|
|
|
- basePigpen.setFType(3);
|
|
|
|
- basePigpen.setOther2(parentIds);
|
|
|
|
- basePigpen.setOther3("0");
|
|
|
|
- if ( basePigpenService.save(basePigpen)){
|
|
|
|
|
|
+
|
|
|
|
+ if ( basePigpenService.saveBatch(basePigpenList)){
|
|
return ResultUtil.addResult(1);
|
|
return ResultUtil.addResult(1);
|
|
}
|
|
}
|
|
return ResultUtil.addResult(0);
|
|
return ResultUtil.addResult(0);
|