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
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 = "农场首页")
@GetMapping("")
@Parameter(name = "baseId", description = "基地ID")
public CommonResult<List<HomeInfo>> getBaseInfo(@RequestParam("baseId") String baseId) {
return success(homeService.getHomeInfoList(baseId));
public CommonResult<HomeInfo> getBaseInfo(@RequestParam("baseId") String 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 = "农场首页-基地名称列表")
@GetMapping("/baseNames")
public CommonResult<List<BaseNameVO>> getBaseNameList() {

View File

@@ -20,19 +20,29 @@ public class HomeInfo {
@Schema(description = "基地统计信息概述")
private BaseOverviewInfo baseOverviewInfo;
@Schema(description = "基地弹框信息")
private List<PlotPopupFrame> plotPopupFrames;
@Schema(description = "地块集合")
private List<PlotInfo> plotInfos;
@Schema(description = "计划集合")
private List<PlanInfo> planInfos;
@Schema(description = "统计信息")
private StatisticalInfo statisticalInfo;
@Schema(description = "基地信息")
private List<BaseInfo> baseList;
public HomeInfo(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
@AllArgsConstructor
@NoArgsConstructor
@@ -71,11 +81,11 @@ public class HomeInfo {
@Schema(description = "总面积")
private Integer cropCount;
@Schema(description = "在种作物数量")
private Double totalArea;
private Integer totalArea;
@Schema(description = "在职员工人数")
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.baseCount = baseCount;
this.cropCount = cropCount;
@@ -118,6 +128,8 @@ public class HomeInfo {
private String plotColor;
@Schema(description = "地块或作物集合")
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<BaseInfoRespVO> baseList = BeanUtils.toBean(pageResult, BaseInfoRespVO.class);
this.packageBaseInfo(tenantId, baseList, employeeMap);
// 基地面积 取整
baseList.forEach(e -> e.setArea(BigDecimalUtil.roundedViaMath(e.getArea())));
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.plotinfo.PlotInfoService;
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 org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -63,34 +65,40 @@ public class HomeServiceImpl implements HomeService {
@Override
public HomeInfo getHomeInfo(String baseId) {
if (baseId.trim().isEmpty()) {
BaseOverviewInfo baseOverviewInfo = this.getCompanyInfo();
return new HomeInfo(baseOverviewInfo);
}
// 员工集合 <id,name>
Map<String, String> employeeNameMap = personnelManagementService.getEmployeeNameMap();
BaseOverviewInfo baseOverviewInfo = new BaseOverviewInfo();
StatisticalInfo statisticalInfo = new StatisticalInfo();
if (StringUtils.isEmpty(baseId)) {
baseOverviewInfo = this.getCompanyInfo();
statisticalInfo = this.getStatisticalInfo(baseId);
} else {
BaseInfoDO baseObj = baseInfoService.getBaseInfo(baseId);
BaseOverviewInfo baseOverviewInfo = this.getBaseOverviewInfo(baseObj, employeeNameMap);
List<PlotPopupFrame> plotPopupFrames = this.getPlotPopupFrame(baseObj, employeeNameMap);
List<PlotInfo> plotInfos = this.getPlotInfoList(baseId, employeeNameMap);
// List<PlanInfo> planInfos = this.getPlanInfoList(baseId, "", null);
List<PlanInfo> planInfos = getPlans(plotInfos);
StatisticalInfo statisticalInfo = this.getStatisticalInfo(baseId);
return new HomeInfo(baseOverviewInfo, plotPopupFrames, plotInfos, planInfos, statisticalInfo);
baseOverviewInfo = this.getBaseOverviewInfo(baseObj, employeeNameMap);
statisticalInfo = this.getStatisticalInfo(baseId);
}
private List<PlanInfo> getPlans(List<PlotInfo> plotInfos) {
List<PlanInfo> res = new ArrayList<>();
for (PlotInfo plotInfo : plotInfos) {
res.addAll(plotInfo.getPlotOrCropInfo().getPlanInfos());
List<HomeInfo.BaseInfo> baseList = new ArrayList<>();
for (BaseInfoDO baseInfoDO : baseInfoService.getBaseInfosById(baseId)) {
baseList.add(this.getBaseInfo(baseInfoDO,employeeNameMap));
}
return res;
return new HomeInfo(baseOverviewInfo, statisticalInfo,baseList);
}
private BaseInfo getBaseInfo(BaseInfoDO baseObj,Map<String, String> employeeNameMap) {
String baseId = baseObj.getId();
String baseName = baseObj.getName();
String point = baseObj.getPoint();
List<PlotInfo> plotInfos = this.getPlotInfoList(baseObj, employeeNameMap);
return new BaseInfo(baseId,baseName,point,plotInfos);
}
private StatisticalInfo getStatisticalInfo(String baseId) {
if (StringUtils.isEmpty(baseId)) {
return new StatisticalInfo(0,0,0);
}
Integer taskCount = productionPlanService.getTodayTaskCount(baseId);
Integer warningCount = 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();
}
BaseOverviewInfo res = new BaseOverviewInfo();
// 统计基地信息
BaseOverviewInfo res = this.getCompanyInfo();
res.setBaseId(baseObj.getId());
res.setBaseName(baseObj.getName());
res.setBaseArea(baseObj.getArea());
res.setBaseArea(BigDecimalUtil.roundedViaMath(baseObj.getArea()));
res.setManager(employeeName);
res.setPoint(baseObj.getPoint());
res.setPointName(""); // TODO: 2025/8/31 需要前端传入,才能获取
@@ -132,23 +141,27 @@ public class HomeServiceImpl implements HomeService {
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<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId);
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseObj.getId());
for (PlotInfoDO e : plotList) {
String employeeName = personnelManagementService.getEmployeeNameMap(employeeNameMap, e.getEmployeeId());
// 地块详情 (包含计划信息)
PlotOrCropInfo plotOrCropInfo = this.getPlotOrCropInfoList(e,"地块详情",employeeName);
// 地块浮框信息
List<PlotPopupFrame> plotPopupFrame = this.getPlotPopupFrame(baseObj, employeeNameMap);
PlotInfo t = new PlotInfo();
t.setBaseId(e.getBaseId());
t.setBaseName(e.getBaseName());
t.setBaseName(baseObj.getName());
t.setPlotId(e.getPlotId());
t.setPlotName(e.getPlotName());
t.setPlotArea(e.getPlotArea());
t.setPlotArea(BigDecimalUtil.roundedViaMath(e.getPlotArea()));
t.setManager(employeeName);
t.setPoint(e.getPoint());
t.setPlotColor(e.getPlotColor());
t.setPlotOrCropInfo(plotOrCropInfo);
t.setPlotPopupFrames(plotPopupFrame);
targetList.add(t);
}
return targetList;
@@ -246,7 +259,8 @@ public class HomeServiceImpl implements HomeService {
LoginUser user = getLoginUser();
int baseCount = baseInfoService.getBaseCount(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()); // 在职人员
return new BaseOverviewInfo("",baseCount,cropCount,totalArea,personnelCount);
}