fix (farm): 首页

- 首页相应json格式,根据前端需求调整
This commit is contained in:
达富斌
2025-09-09 18:05:27 +08:00
parent a3cfca23ba
commit 8c003ab871
4 changed files with 72 additions and 45 deletions

View File

@@ -29,20 +29,20 @@ public class HomeController {
@Resource @Resource
private HomeService homeService; private HomeService homeService;
// @Operation(summary = "农场首页")
// @GetMapping("")
// @Parameter(name = "baseId", description = "基地ID")
// public CommonResult<HomeInfo> getBaseInfo(@RequestParam("baseId") String baseId) {
// return success(homeService.getHomeInfo(baseId));
// }
@Operation(summary = "农场首页") @Operation(summary = "农场首页")
@GetMapping("") @GetMapping("")
@Parameter(name = "baseId", description = "基地ID") @Parameter(name = "baseId", description = "基地ID")
public CommonResult<List<HomeInfo>> getBaseInfo(@RequestParam("baseId") String baseId) { public CommonResult<HomeInfo> getBaseInfo(@RequestParam("baseId") String baseId) {
return success(homeService.getHomeInfoList(baseId)); return success(homeService.getHomeInfo(baseId));
} }
// @Operation(summary = "农场首页")
// @GetMapping("")
// @Parameter(name = "baseId", description = "基地ID")
// public CommonResult<List<HomeInfo>> getBaseInfo(@RequestParam("baseId") String baseId) {
// return success(homeService.getHomeInfoList(baseId));
// }
@Operation(summary = "农场首页-基地名称列表") @Operation(summary = "农场首页-基地名称列表")
@GetMapping("/baseNames") @GetMapping("/baseNames")
public CommonResult<List<BaseNameVO>> getBaseNameList() { public CommonResult<List<BaseNameVO>> getBaseNameList() {

View File

@@ -20,19 +20,29 @@ public class HomeInfo {
@Schema(description = "基地统计信息概述") @Schema(description = "基地统计信息概述")
private BaseOverviewInfo baseOverviewInfo; private BaseOverviewInfo baseOverviewInfo;
@Schema(description = "基地弹框信息")
private List<PlotPopupFrame> plotPopupFrames;
@Schema(description = "地块集合")
private List<PlotInfo> plotInfos;
@Schema(description = "计划集合")
private List<PlanInfo> planInfos;
@Schema(description = "统计信息") @Schema(description = "统计信息")
private StatisticalInfo statisticalInfo; private StatisticalInfo statisticalInfo;
@Schema(description = "基地信息")
private List<BaseInfo> baseList;
public HomeInfo(BaseOverviewInfo baseOverviewInfo) { public HomeInfo(BaseOverviewInfo baseOverviewInfo) {
this.baseOverviewInfo = baseOverviewInfo; this.baseOverviewInfo = baseOverviewInfo;
} }
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class BaseInfo {
@Schema(description = "基地ID")
private String baseId;
@Schema(description = "基地名称")
private String baseName;
@Schema(description = "基地坐标")
private String point;
@Schema(description = "地块集合")
private List<PlotInfo> plotInfos;
}
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@@ -71,11 +81,11 @@ public class HomeInfo {
@Schema(description = "总面积") @Schema(description = "总面积")
private Integer cropCount; private Integer cropCount;
@Schema(description = "在种作物数量") @Schema(description = "在种作物数量")
private Double totalArea; private Integer totalArea;
@Schema(description = "在职员工人数") @Schema(description = "在职员工人数")
private Integer personnelCount; private Integer personnelCount;
public BaseOverviewInfo(String baseId, Integer baseCount, Integer cropCount, Double totalArea, Integer personnelCount) { public BaseOverviewInfo(String baseId, Integer baseCount, Integer cropCount, Integer totalArea, Integer personnelCount) {
this.baseId = baseId; this.baseId = baseId;
this.baseCount = baseCount; this.baseCount = baseCount;
this.cropCount = cropCount; this.cropCount = cropCount;
@@ -118,6 +128,8 @@ public class HomeInfo {
private String plotColor; private String plotColor;
@Schema(description = "地块或作物集合") @Schema(description = "地块或作物集合")
private PlotOrCropInfo plotOrCropInfo; private PlotOrCropInfo plotOrCropInfo;
@Schema(description = "基地弹框信息")
private List<PlotPopupFrame> plotPopupFrames;
} }

View File

@@ -215,7 +215,8 @@ public class BaseInfoServiceImpl implements BaseInfoService {
List<BaseInfoDO> pageResult = this.getList(new BaseInfoPageReqVO()); List<BaseInfoDO> pageResult = this.getList(new BaseInfoPageReqVO());
List<BaseInfoRespVO> baseList = BeanUtils.toBean(pageResult, BaseInfoRespVO.class); List<BaseInfoRespVO> baseList = BeanUtils.toBean(pageResult, BaseInfoRespVO.class);
this.packageBaseInfo(tenantId, baseList, employeeMap); this.packageBaseInfo(tenantId, baseList, employeeMap);
// 基地面积 取整
baseList.forEach(e -> e.setArea(BigDecimalUtil.roundedViaMath(e.getArea())));
return new TenantInfoRespVO(tenantInfo, baseList); return new TenantInfoRespVO(tenantInfo, baseList);
} }

View File

@@ -15,8 +15,10 @@ import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementServi
import cn.iocoder.yudao.module.farm.service.personnelmanagement.PersonnelManagementService; import cn.iocoder.yudao.module.farm.service.personnelmanagement.PersonnelManagementService;
import cn.iocoder.yudao.module.farm.service.plotinfo.PlotInfoService; import cn.iocoder.yudao.module.farm.service.plotinfo.PlotInfoService;
import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService; import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService;
import cn.iocoder.yudao.module.farm.utils.BigDecimalUtil;
import cn.iocoder.yudao.module.farm.utils.LeafletjsUtil; import cn.iocoder.yudao.module.farm.utils.LeafletjsUtil;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@@ -63,34 +65,40 @@ public class HomeServiceImpl implements HomeService {
@Override @Override
public HomeInfo getHomeInfo(String baseId) { public HomeInfo getHomeInfo(String baseId) {
if (baseId.trim().isEmpty()) {
BaseOverviewInfo baseOverviewInfo = this.getCompanyInfo();
return new HomeInfo(baseOverviewInfo);
}
// 员工集合 <id,name> // 员工集合 <id,name>
Map<String, String> employeeNameMap = personnelManagementService.getEmployeeNameMap(); Map<String, String> employeeNameMap = personnelManagementService.getEmployeeNameMap();
BaseInfoDO baseObj = baseInfoService.getBaseInfo(baseId);
BaseOverviewInfo baseOverviewInfo = this.getBaseOverviewInfo(baseObj, employeeNameMap); BaseOverviewInfo baseOverviewInfo = new BaseOverviewInfo();
List<PlotPopupFrame> plotPopupFrames = this.getPlotPopupFrame(baseObj, employeeNameMap); StatisticalInfo statisticalInfo = new StatisticalInfo();
List<PlotInfo> plotInfos = this.getPlotInfoList(baseId, employeeNameMap); if (StringUtils.isEmpty(baseId)) {
// List<PlanInfo> planInfos = this.getPlanInfoList(baseId, "", null); baseOverviewInfo = this.getCompanyInfo();
List<PlanInfo> planInfos = getPlans(plotInfos); statisticalInfo = this.getStatisticalInfo(baseId);
StatisticalInfo statisticalInfo = this.getStatisticalInfo(baseId); } else {
return new HomeInfo(baseOverviewInfo, plotPopupFrames, plotInfos, planInfos, statisticalInfo); BaseInfoDO baseObj = baseInfoService.getBaseInfo(baseId);
baseOverviewInfo = this.getBaseOverviewInfo(baseObj, employeeNameMap);
statisticalInfo = this.getStatisticalInfo(baseId);
}
List<HomeInfo.BaseInfo> baseList = new ArrayList<>();
for (BaseInfoDO baseInfoDO : baseInfoService.getBaseInfosById(baseId)) {
baseList.add(this.getBaseInfo(baseInfoDO,employeeNameMap));
}
return new HomeInfo(baseOverviewInfo, statisticalInfo,baseList);
} }
private List<PlanInfo> getPlans(List<PlotInfo> plotInfos) { private BaseInfo getBaseInfo(BaseInfoDO baseObj,Map<String, String> employeeNameMap) {
List<PlanInfo> res = new ArrayList<>(); String baseId = baseObj.getId();
for (PlotInfo plotInfo : plotInfos) { String baseName = baseObj.getName();
res.addAll(plotInfo.getPlotOrCropInfo().getPlanInfos()); String point = baseObj.getPoint();
} List<PlotInfo> plotInfos = this.getPlotInfoList(baseObj, employeeNameMap);
return res; return new BaseInfo(baseId,baseName,point,plotInfos);
} }
private StatisticalInfo getStatisticalInfo(String baseId) { private StatisticalInfo getStatisticalInfo(String baseId) {
if (StringUtils.isEmpty(baseId)) {
return new StatisticalInfo(0,0,0);
}
Integer taskCount = productionPlanService.getTodayTaskCount(baseId); Integer taskCount = productionPlanService.getTodayTaskCount(baseId);
Integer warningCount = 0; // TODO: 2025/9/1 告警数量 Integer warningCount = 0; // TODO: 2025/9/1 告警数量
Integer iotCount = 0; // TODO: 2025/9/1 物联设备数量 Integer iotCount = 0; // TODO: 2025/9/1 物联设备数量
@@ -107,10 +115,11 @@ public class HomeServiceImpl implements HomeService {
plotRatio = growingPlotCount + "/" + plotInfos.size(); plotRatio = growingPlotCount + "/" + plotInfos.size();
} }
BaseOverviewInfo res = new BaseOverviewInfo(); // 统计基地信息
BaseOverviewInfo res = this.getCompanyInfo();
res.setBaseId(baseObj.getId()); res.setBaseId(baseObj.getId());
res.setBaseName(baseObj.getName()); res.setBaseName(baseObj.getName());
res.setBaseArea(baseObj.getArea()); res.setBaseArea(BigDecimalUtil.roundedViaMath(baseObj.getArea()));
res.setManager(employeeName); res.setManager(employeeName);
res.setPoint(baseObj.getPoint()); res.setPoint(baseObj.getPoint());
res.setPointName(""); // TODO: 2025/8/31 需要前端传入,才能获取 res.setPointName(""); // TODO: 2025/8/31 需要前端传入,才能获取
@@ -132,23 +141,27 @@ public class HomeServiceImpl implements HomeService {
return targetList; return targetList;
} }
private List<PlotInfo> getPlotInfoList(String baseId,Map<String, String> employeeNameMap) { private List<PlotInfo> getPlotInfoList(BaseInfoDO baseObj,Map<String, String> employeeNameMap) {
List<PlotInfo> targetList = new ArrayList<>(); List<PlotInfo> targetList = new ArrayList<>();
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId); List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseObj.getId());
for (PlotInfoDO e : plotList) { for (PlotInfoDO e : plotList) {
String employeeName = personnelManagementService.getEmployeeNameMap(employeeNameMap, e.getEmployeeId()); String employeeName = personnelManagementService.getEmployeeNameMap(employeeNameMap, e.getEmployeeId());
// 地块详情 (包含计划信息)
PlotOrCropInfo plotOrCropInfo = this.getPlotOrCropInfoList(e,"地块详情",employeeName); PlotOrCropInfo plotOrCropInfo = this.getPlotOrCropInfoList(e,"地块详情",employeeName);
// 地块浮框信息
List<PlotPopupFrame> plotPopupFrame = this.getPlotPopupFrame(baseObj, employeeNameMap);
PlotInfo t = new PlotInfo(); PlotInfo t = new PlotInfo();
t.setBaseId(e.getBaseId()); t.setBaseId(e.getBaseId());
t.setBaseName(e.getBaseName()); t.setBaseName(baseObj.getName());
t.setPlotId(e.getPlotId()); t.setPlotId(e.getPlotId());
t.setPlotName(e.getPlotName()); t.setPlotName(e.getPlotName());
t.setPlotArea(e.getPlotArea()); t.setPlotArea(BigDecimalUtil.roundedViaMath(e.getPlotArea()));
t.setManager(employeeName); t.setManager(employeeName);
t.setPoint(e.getPoint()); t.setPoint(e.getPoint());
t.setPlotColor(e.getPlotColor()); t.setPlotColor(e.getPlotColor());
t.setPlotOrCropInfo(plotOrCropInfo); t.setPlotOrCropInfo(plotOrCropInfo);
t.setPlotPopupFrames(plotPopupFrame);
targetList.add(t); targetList.add(t);
} }
return targetList; return targetList;
@@ -246,7 +259,8 @@ public class HomeServiceImpl implements HomeService {
LoginUser user = getLoginUser(); LoginUser user = getLoginUser();
int baseCount = baseInfoService.getBaseCount(user.getTenantId()); // 基地数量 int baseCount = baseInfoService.getBaseCount(user.getTenantId()); // 基地数量
int cropCount = cropFarmingCenterService.getCropCount(user.getTenantId()); // 作物数量 int cropCount = cropFarmingCenterService.getCropCount(user.getTenantId()); // 作物数量
Double totalArea = cropFarmingCenterService.getTotalArea(user.getTenantId()); // 总面积 Double temp = cropFarmingCenterService.getTotalArea(user.getTenantId()); // 总面积
int totalArea = (int) Math.round(temp);
int personnelCount = personnelManagementService.personnelCount(user.getTenantId()); // 在职人员 int personnelCount = personnelManagementService.personnelCount(user.getTenantId()); // 在职人员
return new BaseOverviewInfo("",baseCount,cropCount,totalArea,personnelCount); return new BaseOverviewInfo("",baseCount,cropCount,totalArea,personnelCount);
} }