fix (farm): 集成测试
- 基地规划 , 基地名称不可重复 , 新增,修改 加入面积验证逻辑
This commit is contained in:
@@ -11,6 +11,7 @@ public interface ErrorCodeConstants {
|
|||||||
|
|
||||||
// ========== 基地管理 1-050-000-000 ==========
|
// ========== 基地管理 1-050-000-000 ==========
|
||||||
ErrorCode BASE_INFO_NOT_EXISTS = new ErrorCode(1_050_000_000, "基地不存在");
|
ErrorCode BASE_INFO_NOT_EXISTS = new ErrorCode(1_050_000_000, "基地不存在");
|
||||||
|
ErrorCode BASE_NAME_ERROR = new ErrorCode(1_050_000_001, "基地名称重复");
|
||||||
|
|
||||||
// ========== 公司信息 1-050-001-000 ==========
|
// ========== 公司信息 1-050-001-000 ==========
|
||||||
ErrorCode COMPANY_INFO_NOT_EXISTS = new ErrorCode(1_050_001_000, "公司信息不存在");
|
ErrorCode COMPANY_INFO_NOT_EXISTS = new ErrorCode(1_050_001_000, "公司信息不存在");
|
||||||
@@ -122,7 +123,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode PLOT_AREA_ERRORS = new ErrorCode(1_050_036_000, "地块面积总和大于基地面积");
|
ErrorCode PLOT_AREA_ERRORS = new ErrorCode(1_050_036_000, "地块面积总和大于基地面积");
|
||||||
ErrorCode PLOT_AREA_EXISTS_ERRORS = new ErrorCode(1_050_036_001, "该基地存在地块,不可删除");
|
ErrorCode PLOT_AREA_EXISTS_ERRORS = new ErrorCode(1_050_036_001, "该基地存在地块,不可删除");
|
||||||
ErrorCode BEING_PLOT_AREA_EXISTS_ERRORS = new ErrorCode(1_050_036_002, "该基地存在在种地块,不可删除");
|
ErrorCode BEING_PLOT_AREA_EXISTS_ERRORS = new ErrorCode(1_050_036_002, "该基地存在在种地块,不可删除");
|
||||||
ErrorCode BASE_PLOT_AREA_ERRORS = new ErrorCode(1_050_036_003, "该基地面积小于地块面积总和,不可删除");
|
ErrorCode BASE_PLOT_AREA_ERRORS = new ErrorCode(1_050_036_003, "该基地面积小于地块面积总和,不可修改");
|
||||||
|
|
||||||
ErrorCode INDICATOR_NAME_NOT_EXISTS = new ErrorCode(1_050_037_000, "指标名称不存在");
|
ErrorCode INDICATOR_NAME_NOT_EXISTS = new ErrorCode(1_050_037_000, "指标名称不存在");
|
||||||
|
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
|||||||
@Override
|
@Override
|
||||||
public String createBaseInfo(BaseInfoSaveReqVO createReqVO) {
|
public String createBaseInfo(BaseInfoSaveReqVO createReqVO) {
|
||||||
LoginUser user = getLoginUser();
|
LoginUser user = getLoginUser();
|
||||||
|
validateBaseArea(createReqVO.getName());
|
||||||
// 插入
|
// 插入
|
||||||
BaseInfoDO baseInfo = BeanUtils.toBean(createReqVO, BaseInfoDO.class);
|
BaseInfoDO baseInfo = BeanUtils.toBean(createReqVO, BaseInfoDO.class);
|
||||||
baseInfo.setId(IdUtil.fastUUID());
|
baseInfo.setId(IdUtil.fastUUID());
|
||||||
@@ -110,15 +111,16 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
|||||||
public void deleteBaseInfo(String id) {
|
public void deleteBaseInfo(String id) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
validateBaseInfoExists(id);
|
validateBaseInfoExists(id);
|
||||||
// 校验: 存在在种地块时 不允许删除
|
// 存在地块,不可删除
|
||||||
boolean flag = productionPlanService.validateIncompletePlansBId("base_id", id);
|
|
||||||
if (!flag) {
|
|
||||||
throw exception(BEING_PLOT_AREA_EXISTS_ERRORS);
|
|
||||||
}
|
|
||||||
boolean flag2 = plotInfoService.validatePlotExistByBaseId(id);
|
boolean flag2 = plotInfoService.validatePlotExistByBaseId(id);
|
||||||
if (!flag2) {
|
if (!flag2) {
|
||||||
throw exception(PLOT_AREA_EXISTS_ERRORS);
|
throw exception(PLOT_AREA_EXISTS_ERRORS);
|
||||||
}
|
}
|
||||||
|
// 校验: 存在在种地块时 不允许删除
|
||||||
|
// boolean flag = productionPlanService.validateIncompletePlansBId("base_id", id);
|
||||||
|
// if (!flag) {
|
||||||
|
// throw exception(BEING_PLOT_AREA_EXISTS_ERRORS);
|
||||||
|
// }
|
||||||
// 删除
|
// 删除
|
||||||
baseInfoMapper.deleteById(id);
|
baseInfoMapper.deleteById(id);
|
||||||
plotInfoService.deleteByBaseId(id);
|
plotInfoService.deleteByBaseId(id);
|
||||||
@@ -136,13 +138,20 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateBaseArea(String baseName) {
|
||||||
|
BaseInfoDO one = baseInfoMapper.selectOne("name", baseName);
|
||||||
|
if (ObjectUtils.isNotEmpty(one)) {
|
||||||
|
throw exception(BASE_NAME_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改后的基地面积 不可小于 其地块面积总和
|
* 修改后的基地面积 不可小于 其地块面积总和
|
||||||
* @param id
|
* @param id
|
||||||
* @param updateBaseArea
|
* @param updateBaseArea
|
||||||
*/
|
*/
|
||||||
private void validateBaseArea(String id,BigDecimal updateBaseArea) {
|
private void validateBaseArea(String id,BigDecimal updateBaseArea) {
|
||||||
if (!plotInfoService.validateTotalPlotArea(id,updateBaseArea)) {
|
if (plotInfoService.validateTotalPlotArea(id,updateBaseArea)) {
|
||||||
throw exception(BASE_PLOT_AREA_ERRORS);
|
throw exception(BASE_PLOT_AREA_ERRORS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,7 +245,7 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
|||||||
// 基地总数
|
// 基地总数
|
||||||
Integer baseCount = baseInfoMapper.getBaseCount(tenantId);
|
Integer baseCount = baseInfoMapper.getBaseCount(tenantId);
|
||||||
// 在种作物总数
|
// 在种作物总数
|
||||||
Integer cropCount = speciesLibraryMapper.getSpeciesCount(tenantId, "");
|
Integer cropCount = productionPlanService.getGrowingCropCountByTenantId(String.valueOf(tenantId));
|
||||||
// 基地总面积
|
// 基地总面积
|
||||||
BigDecimal areaCount = new BigDecimal("0.00");
|
BigDecimal areaCount = new BigDecimal("0.00");
|
||||||
if (baseCount > 0) {
|
if (baseCount > 0) {
|
||||||
|
|||||||
@@ -515,9 +515,6 @@ public class CropFarmingCenterServiceImpl implements CropFarmingCenterService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BasePlanOverviewRespVO getBaseOverview(String baseId) {
|
public BasePlanOverviewRespVO getBaseOverview(String baseId) {
|
||||||
if (StringUtils.isEmpty(baseId)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
LoginUser user = getLoginUser();
|
LoginUser user = getLoginUser();
|
||||||
Long tenantId = user.getTenantId();
|
Long tenantId = user.getTenantId();
|
||||||
BigDecimal totalArea = baseInfoMapper.getTotalBaseArea(baseId, tenantId);
|
BigDecimal totalArea = baseInfoMapper.getTotalBaseArea(baseId, tenantId);
|
||||||
|
|||||||
@@ -155,28 +155,25 @@ public class PlotInfoServiceImpl implements PlotInfoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateCurrentPlotArea(String baseId, String plotId, BigDecimal currentPlotArea) {
|
private boolean validateCurrentPlotArea(String baseId, String plotId, BigDecimal currentPlotArea) {
|
||||||
BaseInfoDO baseObj = baseInfoMapper.selectOne("id", baseId);
|
|
||||||
BigDecimal baseArea = baseObj.getArea();
|
|
||||||
|
|
||||||
List<PlotInfoDO> plotInfoDOS = plotInfoMapper.selectList("base_id", baseId);
|
List<PlotInfoDO> plotInfoDOS = plotInfoMapper.selectList("base_id", baseId);
|
||||||
if (plotInfoDOS == null || plotInfoDOS.isEmpty()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigDecimal plotTotalArea = plotInfoDOS.stream()
|
|
||||||
.map(PlotInfoDO::getPlotArea)
|
|
||||||
.filter(area -> area != null) // 重要:过滤null值
|
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
|
|
||||||
BigDecimal currentTotalArea = null;
|
BigDecimal currentTotalArea = null;
|
||||||
if (plotId == null) {
|
if (plotInfoDOS == null || plotInfoDOS.isEmpty()) {
|
||||||
currentTotalArea = plotTotalArea.add(currentPlotArea);
|
currentTotalArea = currentPlotArea;
|
||||||
}else{
|
}else{
|
||||||
PlotInfoDO one = plotInfoMapper.selectOne("id", plotId);
|
BigDecimal plotTotalArea = plotInfoDOS.stream().map(PlotInfoDO::getPlotArea).filter(area -> area != null).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal sourcePlotArea = one.getPlotArea();
|
if (null == plotId) {
|
||||||
currentTotalArea = plotTotalArea.subtract(sourcePlotArea).add(currentPlotArea);
|
currentTotalArea = plotTotalArea.add(currentPlotArea);
|
||||||
|
}else{
|
||||||
|
PlotInfoDO one = plotInfoMapper.selectOne("id", plotId);
|
||||||
|
currentTotalArea = plotTotalArea.subtract(one.getPlotArea()).add(currentPlotArea);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 计算基地面积
|
||||||
|
BaseInfoDO baseObj = baseInfoMapper.selectOne("id", baseId);
|
||||||
|
BigDecimal baseArea = baseObj.getArea();
|
||||||
|
// 比对
|
||||||
return currentTotalArea.compareTo(baseArea) > 0;
|
return currentTotalArea.compareTo(baseArea) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,8 +187,8 @@ public class PlotInfoServiceImpl implements PlotInfoService {
|
|||||||
.map(PlotInfoDO::getPlotArea)
|
.map(PlotInfoDO::getPlotArea)
|
||||||
.filter(area -> area != null) // 重要:过滤null值
|
.filter(area -> area != null) // 重要:过滤null值
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
boolean b = plotTotalArea.compareTo(baseArea) > 0;
|
||||||
return plotTotalArea.compareTo(baseArea) > 0;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,13 @@ public interface ProductionPlanService {
|
|||||||
*/
|
*/
|
||||||
int getGrowingCropCount(String baseId);
|
int getGrowingCropCount(String baseId);
|
||||||
int getGrowingCropCount(String baseId,String plotId);
|
int getGrowingCropCount(String baseId,String plotId);
|
||||||
|
int getGrowingCropCountByTenantId(String tenantId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在种计划
|
||||||
|
* @param baseId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
int getGrowingPlanCount(String baseId);
|
int getGrowingPlanCount(String baseId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -216,11 +216,12 @@ public class ProductionPlanServiceImpl implements ProductionPlanService {
|
|||||||
public boolean validateIncompletePlansBId(String field,String baseId) {
|
public boolean validateIncompletePlansBId(String field,String baseId) {
|
||||||
List<ProductionPlanDO> planList = productionPlanMapper.selectList(field, baseId);
|
List<ProductionPlanDO> planList = productionPlanMapper.selectList(field, baseId);
|
||||||
Set<Integer> planStatusSet = planList.stream()
|
Set<Integer> planStatusSet = planList.stream()
|
||||||
.filter(e -> !ObjectUtils.notEqual(e.getPlanStatus(), PLAN_STATUS_3))
|
.filter(e -> ObjectUtils.notEqual(e.getPlanStatus(), PLAN_STATUS_3))
|
||||||
.map(ProductionPlanDO::getPlanStatus)
|
.map(ProductionPlanDO::getPlanStatus)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
// 存在未完成状态的计划 不可删除
|
// 存在未完成状态的计划 不可删除
|
||||||
return planStatusSet.size() <= 0;
|
boolean b = planStatusSet.size() <= 0;
|
||||||
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -259,6 +260,20 @@ public class ProductionPlanServiceImpl implements ProductionPlanService {
|
|||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getGrowingCropCountByTenantId(String tenantId) {
|
||||||
|
QueryWrapper<ProductionPlanDO> qw = new QueryWrapper<>();
|
||||||
|
qw.eq("tenant_id", tenantId);
|
||||||
|
List<ProductionPlanDO> planList = productionPlanMapper.selectList(qw);
|
||||||
|
return (int) planList.stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(plan -> Objects.equals(plan.getPlanStatus(), PLAN_STATUS_2))
|
||||||
|
.map(ProductionPlanDO::getPlantSpeciesCode)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.distinct()
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getGrowingPlanCount(String baseId) {
|
public int getGrowingPlanCount(String baseId) {
|
||||||
List<ProductionPlanDO> planList = productionPlanMapper.selectList("base_id", baseId);
|
List<ProductionPlanDO> planList = productionPlanMapper.selectList("base_id", baseId);
|
||||||
|
|||||||
Reference in New Issue
Block a user