From c93aa27d0eb083c38bc7162051947ea50f76678f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=BE=BE=E5=AF=8C=E6=96=8C?= Date: Wed, 12 Nov 2025 21:45:36 +0800 Subject: [PATCH] =?UTF-8?q?fix=20(farm):=20=E9=A6=96=E9=A1=B5,=E5=9F=BA?= =?UTF-8?q?=E5=9C=B0/=E5=9C=B0=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 首页加载地块信息慢bug,使用redis缓存解决 - 地块户主信息,增加租赁费字段 ,包含导出/入 --- .../baseinfo/PlotInfoController.java | 14 +- .../service/baseinfo/BaseInfoServiceImpl.java | 5 +- .../farm/service/home/HomeServiceImpl.java | 13 +- .../service/plotinfo/PlotInfoService.java | 23 -- .../service/plotinfo/PlotInfoServiceImpl.java | 253 +-------------- .../service/plotinfo/PlotLesseeService.java | 45 +++ .../plotinfo/PlotLesseeServiceImpl.java | 289 +++++++++++++++++- 7 files changed, 360 insertions(+), 282 deletions(-) diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/baseinfo/PlotInfoController.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/baseinfo/PlotInfoController.java index 7b34a414..668bc52b 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/baseinfo/PlotInfoController.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/baseinfo/PlotInfoController.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo; import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo.vo.*; +import cn.iocoder.yudao.module.farm.service.plotinfo.PlotLesseeService; import io.swagger.v3.oas.annotations.Parameters; import org.springframework.web.bind.annotation.*; import jakarta.validation.Valid; @@ -24,7 +25,6 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.IMPORT; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.module.farm.enums.CommonConstants.PLOT_TYPE_NAME_MAP; @@ -44,6 +44,8 @@ public class PlotInfoController { @Resource private PlotInfoService plotInfoService; + @Resource + private PlotLesseeService plotLesseeService; @PostMapping("/create") @Operation(summary = "创建地块") @@ -78,8 +80,8 @@ public class PlotInfoController { @Operation(summary = "获得地块") @Parameter(name = "id", description = "编号", required = true) public CommonResult getPlotInfo(@RequestParam("id") String id) { - PlotLesseeInfoRespVO plotInfo = plotInfoService.getPlotLesseeInfo(id); - return success(plotInfo); + PlotInfoDO plotInfo = plotInfoService.getPlotInfo(id); + return success(plotLesseeService.exportPlotLesseeInfoExcel(id,plotInfo)); } @GetMapping("/page") @@ -101,7 +103,6 @@ public class PlotInfoController { HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = plotInfoService.getPlotInfoPage(pageReqVO).getList(); - // 导出 Excel ExcelUtils.write(response, "地块.xls", "数据", PlotInfoRespVO.class, BeanUtils.toBean(list, PlotInfoRespVO.class)); } @@ -110,8 +111,7 @@ public class PlotInfoController { @Operation(summary = "导出户主 Excel") @ApiAccessLog(operateType = EXPORT) public void exportPlotLesseeInfoExcel(HttpServletResponse response) throws IOException { - List list = plotInfoService.getPlotLesseeInfo(); - // 导出 Excel + List list = plotLesseeService.exportPlotLesseeInfoExcel(); ExcelUtils.write(response, "户主.xls", "数据", PlotLesseeForExportExcelRespVO.class, list); } @@ -122,7 +122,7 @@ public class PlotInfoController { }) public CommonResult importPlotLesseeInfoExcel(@RequestParam("file") MultipartFile file) throws IOException { List list = ExcelUtils.read(file, PlotLesseeForImportExcelRespVO.class); - PlotLesseeImportRespVO res = plotInfoService.setPlotLesseeInfo(list); + PlotLesseeImportRespVO res = plotLesseeService.importPlotLesseeInfoExcel(list); return success(res); } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/baseinfo/BaseInfoServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/baseinfo/BaseInfoServiceImpl.java index 6a0473f3..4fe7af53 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/baseinfo/BaseInfoServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/baseinfo/BaseInfoServiceImpl.java @@ -28,6 +28,7 @@ import cn.iocoder.yudao.module.farm.service.companyinfo.CompanyInfoService; import cn.iocoder.yudao.module.farm.service.deviceinfo.DeviceInfoService; 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.PlotLesseeService; import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService; import cn.iocoder.yudao.module.farm.service.specieslibrary.SpeciesLibraryService; import cn.iocoder.yudao.module.farm.utils.BigDecimalUtil; @@ -79,6 +80,8 @@ public class BaseInfoServiceImpl implements BaseInfoService { private CompanyInfoService companyInfoService; @Resource private DeviceInfoService deviceInfoService; + @Resource + private PlotLesseeService plotLesseeService; @SneakyThrows @Override @@ -319,7 +322,7 @@ public class BaseInfoServiceImpl implements BaseInfoService { // 网箱 List gridInfos = this.packageGridInfo(aDo.getPlotId()); // 户主 - List lesseeList = plotInfoService.getPlotLesseeList2(aDo.getId()); + List lesseeList = plotLesseeService.getPlotLesseeList(aDo.getId()); String plotManager = employeeMap.getOrDefault(aDo.getEmployeeId(), "系统"); // String typeName = PLOT_TYPE_NAME_MAP.get(Integer.valueOf(aDo.getType())); BaseInfoRespVO.PlotInfo target = new BaseInfoRespVO.PlotInfo( diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/home/HomeServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/home/HomeServiceImpl.java index 319127b6..99e0afd9 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/home/HomeServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/home/HomeServiceImpl.java @@ -20,6 +20,7 @@ import cn.iocoder.yudao.module.farm.service.farmingrecord.FarmingRecordService; import cn.iocoder.yudao.module.farm.service.modelmanagement.ModelManagementService; 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.PlotLesseeService; import cn.iocoder.yudao.module.farm.service.productionplan.ProductionPlanService; import cn.iocoder.yudao.module.farm.service.specieslibrary.SpeciesLibraryService; import cn.iocoder.yudao.module.farm.utils.BigDecimalUtil; @@ -53,8 +54,9 @@ public class HomeServiceImpl implements HomeService { private final SpeciesLibraryService speciesLibraryService; private final FarmingRecordService farmingRecordService; private final DeviceInfoService deviceService; + private final PlotLesseeService plotLesseeService; - public HomeServiceImpl(BaseInfoService baseInfoService, PlotInfoService plotInfoService, ProductionPlanService productionPlanService, CropFarmingCenterService cropFarmingCenterService, PersonnelManagementService personnelManagementService, ModelManagementService modelManagementService, SpeciesLibraryService speciesLibraryService, FarmingRecordService farmingRecordService, DeviceInfoService deviceService) { + public HomeServiceImpl(BaseInfoService baseInfoService, PlotInfoService plotInfoService, ProductionPlanService productionPlanService, CropFarmingCenterService cropFarmingCenterService, PersonnelManagementService personnelManagementService, ModelManagementService modelManagementService, SpeciesLibraryService speciesLibraryService, FarmingRecordService farmingRecordService, DeviceInfoService deviceService, PlotLesseeService plotLesseeService) { this.baseInfoService = baseInfoService; this.plotInfoService = plotInfoService; this.productionPlanService = productionPlanService; @@ -64,6 +66,7 @@ public class HomeServiceImpl implements HomeService { this.speciesLibraryService = speciesLibraryService; this.farmingRecordService = farmingRecordService; this.deviceService = deviceService; + this.plotLesseeService = plotLesseeService; } @Override @@ -194,7 +197,7 @@ public class HomeServiceImpl implements HomeService { // 地块浮框信息 List plotPopupFrame = this.getPlotPopupFrame(e.getId(), employeeNameMap); // 户主流转信息 - List lesseeList = plotInfoService.getPlotLesseeList(e.getId()); + List lesseeList = plotLesseeService.getPlotLesseeHistoryList(e.getId()); PlotInfo t = new PlotInfo(); t.setBaseId(e.getBaseId()); @@ -387,14 +390,12 @@ public class HomeServiceImpl implements HomeService { } private List getLs(String plotId) { - List res = plotInfoService.getPlotLesseeList(plotId); - return res; + return plotLesseeService.getPlotLesseeHistoryList(plotId); } private List getDs(String plotId,String tenantId) { - List res = deviceService.deviceList(plotId,tenantId); - return res; + return deviceService.deviceList(plotId,tenantId); } private BaseOverviewInfo getCompanyInfo() { diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java index 2ea90db8..60fedfc0 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoService.java @@ -49,21 +49,6 @@ public interface PlotInfoService { */ PlotInfoDO getPlotInfo(String id); - /** - * 地块&租户信息 - * @param id - * @return - */ - PlotLesseeInfoRespVO getPlotLesseeInfo(String id); - - /** - * 导出户主信息 - * @return - */ - List getPlotLesseeInfo(); - - PlotLesseeImportRespVO setPlotLesseeInfo(List req); - /** * 通过基地ID获取地块集合 * @param baseId @@ -120,12 +105,4 @@ public interface PlotInfoService { Long countPlotByTenantId(String tenantId); - /** - * 获取地块下 有多户主信息 - * @param plotId - * @return - */ - List getPlotLesseeList(String plotId); - - List getPlotLesseeList2(String plotId); } \ No newline at end of file diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java index 641d364e..0138500a 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotInfoServiceImpl.java @@ -46,20 +46,15 @@ public class PlotInfoServiceImpl implements PlotInfoService { private final BaseInfoMapper baseInfoMapper; private final PlotInfoMapper plotInfoMapper; - private final PlotLesseeMapper plotLesseeMapper; + private final PlotLesseeService plotLesseeService; private final ProductionPlanService productionPlanService; private final PersonnelManagementService personnelManagementService; private final PlotInfoCacheService pCatchService; - public PlotInfoServiceImpl( - BaseInfoMapper baseInfoMapper, - PlotInfoMapper plotInfoMapper, - PlotLesseeMapper plotLesseeMapper, - ProductionPlanService productionPlanService, - PersonnelManagementService personnelManagementService, PlotInfoCacheService pCatchService) { + public PlotInfoServiceImpl(BaseInfoMapper baseInfoMapper, PlotInfoMapper plotInfoMapper, PlotLesseeService plotLesseeService, ProductionPlanService productionPlanService, PersonnelManagementService personnelManagementService, PlotInfoCacheService pCatchService) { this.baseInfoMapper = baseInfoMapper; this.plotInfoMapper = plotInfoMapper; - this.plotLesseeMapper = plotLesseeMapper; + this.plotLesseeService = plotLesseeService; this.productionPlanService = productionPlanService; this.personnelManagementService = personnelManagementService; this.pCatchService = pCatchService; @@ -69,8 +64,10 @@ public class PlotInfoServiceImpl implements PlotInfoService { @Override public String createPlotInfo(PlotInfoSaveReqVO createReqVO) { LoginUser user = getLoginUser(); + // 校验地块面积 validatePlotArea(createReqVO.getBaseId(),null,createReqVO.getPlotArea()); + // 插入 PlotInfoDO plotInfo = BeanUtils.toBean(createReqVO, PlotInfoDO.class); plotInfo.setId(IdUtil.fastUUID()); @@ -78,11 +75,8 @@ public class PlotInfoServiceImpl implements PlotInfoService { plotInfo.setTenantId(String.valueOf(user.getTenantId())); plotInfoMapper.insert(plotInfo); - if (createReqVO.getPlotLeaseStatus() == 1) { - PlotLesseeSaveReqVO plotLesseeSaveReqVO = createReqVO.getPlotLessee(); - PlotLesseeDO plotLesseeDO = BeanUtils.toBean(plotLesseeSaveReqVO, PlotLesseeDO.class); - insertLessee(plotLesseeDO, createReqVO.getBaseId(), plotInfo.getId(), plotInfo.getPlotName()); - } + // 插入户主信息 + plotLesseeService.insertPlotLessee(createReqVO, createReqVO.getBaseId(), plotInfo.getId(), plotInfo.getPlotName()); // 缓存处理 pCatchService.createOrUpdatePlotInfo(plotInfo); @@ -91,51 +85,22 @@ public class PlotInfoServiceImpl implements PlotInfoService { return plotInfo.getId(); } - private void insertLessee(PlotLesseeDO plotLesseeDO,String baseId,String plotId,String plotName) { - LoginUser user = getLoginUser(); - - plotLesseeDO.setId(IdUtil.fastUUID()); - plotLesseeDO.setTenantId(String.valueOf(user.getTenantId())); - plotLesseeDO.setLeaseStatus(CommonConstants.YES_CODE); - plotLesseeDO.setBaseId(baseId); - plotLesseeDO.setPlotId(plotId); - plotLesseeDO.setPlotName(plotName); - plotLesseeMapper.insert(plotLesseeDO); - } - @Transactional @Override public void updatePlotInfo(PlotInfoSaveReqVO updateReqVO) { updateReqVO.setPlotId(updateReqVO.getCode()); // 校验存在 validatePlotInfoExists(updateReqVO.getId()); + // 校验地块面积 validatePlotArea(updateReqVO.getBaseId(), updateReqVO.getId(), updateReqVO.getPlotArea()); + // 更新 PlotInfoDO plotInfo = BeanUtils.toBean(updateReqVO, PlotInfoDO.class); plotInfoMapper.updateById(plotInfo); - if (updateReqVO.getPlotLeaseStatus() == 0) { - return; - } - - // 重置所有租赁状态为: 未租 - List doList = plotLesseeMapper.selectList("plot_id", updateReqVO.getId()); - doList.forEach(e -> e.setLeaseStatus(CommonConstants.NO_CODE)); - plotLesseeMapper.updateBatch(doList); - Set collect = doList.stream().map(e-> e.getLeaseIdCard()).collect(Collectors.toSet()); - - // 指定当前的租户状态为: 已租 - PlotLesseeSaveReqVO plotLesseeSaveReqVO = updateReqVO.getPlotLessee(); - String idCard = plotLesseeSaveReqVO.getLeaseIdCard(); - PlotLesseeDO plotLesseeDO = BeanUtils.toBean(plotLesseeSaveReqVO, PlotLesseeDO.class); - if (collect.contains(idCard)) { - plotLesseeDO.setLeaseStatus(CommonConstants.YES_CODE); - plotLesseeMapper.updateById(plotLesseeDO); - } else { - insertLessee(plotLesseeDO, updateReqVO.getBaseId(), plotInfo.getId(), plotInfo.getPlotName()); - } - + // 更新租户信息 + plotLesseeService.updatePlotLessee(updateReqVO); } @Override @@ -185,181 +150,6 @@ public class PlotInfoServiceImpl implements PlotInfoService { return plotInfoDO; } - @Override - public PlotLesseeInfoRespVO getPlotLesseeInfo(String id) { - LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); - x.eq(PlotLesseeDO::getTenantId, getLoginUser().getTenantId().toString()); - x.eq(PlotLesseeDO::getDeleted, CommonConstants.NO_CODE); - x.eq(PlotLesseeDO::getLeaseStatus, CommonConstants.YES_CODE); - x.eq(PlotLesseeDO::getPlotId, id); - PlotLesseeDO plotLesseeDO = plotLesseeMapper.selectOne(x); - - PlotLesseeDetailsRespVO subLesseeInfo = new PlotLesseeDetailsRespVO(); - if (ObjectUtils.isNotEmpty(plotLesseeDO)) { - subLesseeInfo = BeanUtils.toBean(plotLesseeDO, PlotLesseeDetailsRespVO.class); - } - - PlotInfoDO plotInfoDO = this.getPlotInfo(id); - PlotLesseeInfoRespVO plotLesseeDetailsRespVO = BeanUtils.toBean(plotInfoDO, PlotLesseeInfoRespVO.class); - plotLesseeDetailsRespVO.setTypeName(PLOT_TYPE_NAME_MAP.get(plotLesseeDetailsRespVO.getType())); - plotLesseeDetailsRespVO.setPlotLessee(subLesseeInfo); - plotLesseeDetailsRespVO.setPlotLeaseStatusName(LEASE_STATUS_MAP.get(plotLesseeDetailsRespVO.getPlotLeaseStatus())); - plotLesseeDetailsRespVO.setCode(plotInfoDO.getPlotId()); - plotLesseeDetailsRespVO.setUpdateStateForCode(NO_CODE); - return plotLesseeDetailsRespVO; - } - - @Override - public List getPlotLesseeInfo() { - - List bList = baseInfoMapper.selectList(); - Map baseNameMap = bList.stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getName, (v1, v2) -> v1)); - Map baseCodeMap = bList.stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getCode, (v1, v2) -> v1)); - - List pList = plotInfoMapper.selectList(); - Map plotCodeMap = pList.stream().collect(Collectors.toMap(PlotInfoDO::getId, PlotInfoDO::getPlotId, (v1, v2) -> v1)); - - LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); - x.eq(PlotLesseeDO::getLeaseStatus, YES_CODE); - List lList = plotLesseeMapper.selectList(x); - Map lesObjMap = lList.stream().collect(Collectors.toMap(PlotLesseeDO::getPlotId, e -> e, (v1, v2) -> v1)); - - List plotInfoDOS = plotInfoMapper.selectList(); - return plotInfoDOS.stream().map(p -> { - PlotLesseeForExportExcelRespVO target = new PlotLesseeForExportExcelRespVO( - baseCodeMap.get(p.getBaseId()), baseNameMap.get(p.getBaseId()), - plotCodeMap.get(p.getId()), p.getPlotName(), NO_NAME); - - if (p.getPlotLeaseStatus() == 1 && lesObjMap.containsKey(p.getId())) { - // 已租状态,计算租赁剩余天数 - PlotLesseeDO l = lesObjMap.get(p.getId()); - target.setLeaseName(l.getLeaseName()); - target.setLeaseIdCard(l.getLeaseIdCard()); - target.setLeasePhone(l.getLeasePhone()); - target.setLeaseStartDate(l.getLeaseStartDate()); - target.setLeaseEndDate(l.getLeaseEndDate()); - target.setLeaseRental(l.getLeaseRental().setScale(2, RoundingMode.HALF_UP)); - target.setExpirationDays(getDaysUntilLeaseEnd(l.getLeaseEndDate())); - } - return target; - }).toList(); - - } - - public long getDaysUntilLeaseEnd(LocalDate leaseEndDate) { - LocalDate today = LocalDate.now(); - return ChronoUnit.DAYS.between(today, leaseEndDate); - } - - @Override - public PlotLesseeImportRespVO setPlotLesseeInfo(List req) { - - Map baseNameMap = baseInfoMapper.selectList().stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getName, (v1, v2) -> v1)); - Map plotNameMap = plotInfoMapper.selectList().stream().collect(Collectors.toMap(PlotInfoDO::getPlotName, PlotInfoDO::getId, (v1, v2) -> v1)); - - PlotLesseeImportRespVO res = new PlotLesseeImportRespVO(); - res.setTotal(req.size()); - - List targetList = req.stream().filter(vo -> YES_NAME.equals(vo.getIsModified())).collect(Collectors.toList()); - - int successCount = 0; - int failuresCount = 0; - int unmodifiedCount = req.size() - targetList.size(); - List row = new ArrayList<>(); - for (PlotLesseeForImportExcelRespVO pl : targetList) { - - PlotInfoDO p = plotInfoMapper.selectOne(PlotInfoDO::getPlotName, pl.getPlotName()); - if (ObjectUtils.isEmpty(p)) { - failuresCount++; - row.add(new PlotLesseeImportRespVO.Row(pl.getPlotCode(), pl.getPlotName())); - continue; - } - - PlotLesseeDO sourcePObj = plotLesseeMapper.selectOne( - PlotLesseeDO::getPlotName, pl.getPlotName(), - PlotLesseeDO::getLeaseStatus, YES_CODE); - - if (ObjectUtils.isEmpty(sourcePObj)) { - // 首次添加租户信息, 说明从未添加过户主信息, 直接录入即可 - this.pInsert(p,pl,baseNameMap); - successCount++; - continue; - } - - if (this.isEmpty(pl)) { - p.setPlotLeaseStatus(NO_CODE); - plotInfoMapper.updateById(p); - - sourcePObj.setLeaseStatus(NO_CODE); - plotLesseeMapper.updateById(sourcePObj); - continue; - } - - if (this.compareObj(sourcePObj,pl)) { - // 1. 更新原地块户主信息 - sourcePObj.setLeaseStatus(NO_CODE); - plotLesseeMapper.updateById(sourcePObj); - - this.pInsert(p,pl,baseNameMap); - successCount++; - }else{ - unmodifiedCount++; - } - - } - - res.setSuccessCount(successCount); - res.setFailuresCount(failuresCount); - res.setUnmodifiedCount(unmodifiedCount); - res.setFailuresList(row); - return res; - } - - private void pInsert(PlotInfoDO p,PlotLesseeForImportExcelRespVO pl,Map baseNameMap) { - PlotLesseeDO target = new PlotLesseeDO(); - target.setLeaseName(pl.getLeaseName()); - target.setLeaseIdCard(pl.getLeaseIdCard()); - target.setLeasePhone(pl.getLeasePhone()); - target.setLeaseStartDate(pl.getLeaseStartDate()); - target.setLeaseEndDate(pl.getLeaseEndDate()); - - target.setId(IdUtil.fastUUID()); - target.setTenantId(String.valueOf(getLoginUser().getTenantId())); - target.setLeaseStatus(CommonConstants.YES_CODE); - - target.setBaseId(p.getBaseId()); - target.setBaseName(baseNameMap.get(p.getBaseId())); - target.setPlotId(p.getId()); - target.setPlotName(p.getPlotName()); - plotLesseeMapper.insert(target); - - p.setPlotLeaseStatus(YES_CODE); - plotInfoMapper.updateById(p); - } - - /** - * 对比结果不一致返回: true (至少有一个字段不同) - * 对比结果一致返回: false (所有字段都相同) - * @param s - * @param t - * @return - */ - private boolean compareObj(PlotLesseeDO s, PlotLesseeForImportExcelRespVO t) { - return ObjectUtils.notEqual(s.getLeaseName(), t.getLeaseName()) || - ObjectUtils.notEqual(s.getLeaseIdCard(), t.getLeaseIdCard()) || - ObjectUtils.notEqual(s.getLeasePhone(), t.getLeasePhone()) || - !s.getLeaseStartDate().isEqual(t.getLeaseStartDate()) || - !s.getLeaseEndDate().isEqual(t.getLeaseEndDate()); - } - - private boolean isEmpty(PlotLesseeForImportExcelRespVO t) { - return Objects.equals(t.getLeaseName(), null) || - Objects.equals(t.getLeaseIdCard(), null) || - Objects.equals(t.getLeasePhone(), null) || - Objects.equals(t.getLeaseStartDate(), null) || - Objects.equals(t.getLeaseEndDate(), null); - } - @Override public List getPlotInfos(String baseId) { // 员工集合 @@ -491,25 +281,4 @@ public class PlotInfoServiceImpl implements PlotInfoService { return plotInfoMapper.selectCount(wrapperX); } - @Override - public List getPlotLesseeList(String plotId) { - LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); - x.eq(PlotLesseeDO::getDeleted, CommonConstants.NO_CODE); - x.eq(PlotLesseeDO::getLeaseStatus, CommonConstants.NO_CODE); - x.eq(PlotLesseeDO::getPlotId, plotId); - List list = plotLesseeMapper.selectList(x); - - return BeanUtils.toBean(list, PlotLesseeDetailsRespVO.class); - } - - @Override - public List getPlotLesseeList2(String plotId) { - LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); - x.eq(PlotLesseeDO::getDeleted, CommonConstants.NO_CODE); - x.eq(PlotLesseeDO::getLeaseStatus, YES_CODE); - x.eq(PlotLesseeDO::getPlotId, plotId); - List list = plotLesseeMapper.selectList(x); - - return BeanUtils.toBean(list, PlotLesseeDetailsRespVO.class); - } } \ No newline at end of file diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeService.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeService.java index da1b86c8..d5a06049 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeService.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeService.java @@ -1,9 +1,54 @@ package cn.iocoder.yudao.module.farm.service.plotinfo; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO; + +import java.util.List; + /** * @description: 租赁信息 * @author: binda * @data: 2025/10/15 13:57 */ public interface PlotLesseeService { + + /** + * 插入数据 + * + * @param createReqVO + */ + void insertPlotLessee(PlotInfoSaveReqVO createReqVO, String baseId, String plotId, String plotName); + + /** + * 修改数据 + */ + void updatePlotLessee(PlotInfoSaveReqVO updateReqVO); + + /** + * 导入 + * @param req + * @return + */ + PlotLesseeImportRespVO importPlotLesseeInfoExcel(List req); + + /** + * 导出 + * @return + */ + List exportPlotLesseeInfoExcel(); + + /** + * 获取租户集合 + * @param plotId + * @return + */ + List getPlotLesseeList(String plotId); + List getPlotLesseeHistoryList(String plotId); + + /** + * 地块&租户信息 + * @param id + * @return + */ + PlotLesseeInfoRespVO exportPlotLesseeInfoExcel(String id, PlotInfoDO plotInfo); } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeServiceImpl.java index f7cd0e5a..823769b0 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/plotinfo/PlotLesseeServiceImpl.java @@ -1,9 +1,30 @@ package cn.iocoder.yudao.module.farm.service.plotinfo; +import cn.hutool.core.util.IdUtil; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.baseinfo.vo.*; +import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotInfoDO; +import cn.iocoder.yudao.module.farm.dal.dataobject.plotinfo.PlotLesseeDO; +import cn.iocoder.yudao.module.farm.dal.mysql.baseinfo.BaseInfoMapper; +import cn.iocoder.yudao.module.farm.dal.mysql.plotinfo.PlotInfoMapper; import cn.iocoder.yudao.module.farm.dal.mysql.plotinfo.PlotLesseeMapper; -import jakarta.annotation.Resource; +import cn.iocoder.yudao.module.farm.enums.CommonConstants; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.stereotype.Service; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; +import java.util.*; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser; +import static cn.iocoder.yudao.module.farm.enums.CommonConstants.*; +import static cn.iocoder.yudao.module.farm.enums.CommonConstants.NO_CODE; + /** * @description: 租赁信息 * @author: binda @@ -12,9 +33,271 @@ import org.springframework.stereotype.Service; @Service public class PlotLesseeServiceImpl implements PlotLesseeService { - @Resource - private PlotLesseeMapper plotLesseeMaper; + private final BaseInfoMapper baseInfoMapper; + private final PlotInfoMapper plotInfoMapper; + private final PlotLesseeMapper plotLesseeMapper; + public PlotLesseeServiceImpl(BaseInfoMapper baseInfoMapper, PlotInfoMapper plotInfoMapper, PlotLesseeMapper plotLesseeMapper) { + this.baseInfoMapper = baseInfoMapper; + this.plotInfoMapper = plotInfoMapper; + this.plotLesseeMapper = plotLesseeMapper; + } + + @Override + public void insertPlotLessee(PlotInfoSaveReqVO createReqVO,String baseId,String plotId,String plotName) { + + if (createReqVO.getPlotLeaseStatus() != 1) { + return; + } + + PlotLesseeSaveReqVO plotLesseeSaveReqVO = createReqVO.getPlotLessee(); + PlotLesseeDO plotLesseeDO = BeanUtils.toBean(plotLesseeSaveReqVO, PlotLesseeDO.class); + + this.insertPlotLessee(plotLesseeDO,baseId,plotId,plotName); + } + + @Override + public void updatePlotLessee(PlotInfoSaveReqVO updateReqVO) { + + if (updateReqVO.getPlotLeaseStatus() == 0) { + // 修改为 未租, 清空户主信息 + + List doList = plotLesseeMapper.selectList("plot_id", updateReqVO.getId()); + if (ObjectUtils.isNotEmpty(doList)) { + doList.forEach(e -> e.setLeaseStatus(CommonConstants.NO_CODE)); + plotLesseeMapper.updateBatch(doList); + } + + } else { + // 修改为 已租 + + // 2. 设置 历史户主信息的状态 leaseStatus = 0 + List doList = plotLesseeMapper.selectList("plot_id", updateReqVO.getId()); + if (ObjectUtils.isNotEmpty(doList)) { + doList.forEach(e -> e.setLeaseStatus(CommonConstants.NO_CODE)); + plotLesseeMapper.updateBatch(doList); + } + + // 1. 设置 当前户主信息的状态 leaseStatus = 1 + PlotLesseeSaveReqVO plotLesseeSaveReqVO = updateReqVO.getPlotLessee(); + PlotLesseeDO plotLesseeDO = BeanUtils.toBean(plotLesseeSaveReqVO, PlotLesseeDO.class); + PlotInfoDO plotInfo = BeanUtils.toBean(updateReqVO, PlotInfoDO.class); + this.insertPlotLessee(plotLesseeDO, updateReqVO.getBaseId(), plotInfo.getId(), plotInfo.getPlotName()); + } + + } + + @Override + public PlotLesseeImportRespVO importPlotLesseeInfoExcel(List req) { + Map baseNameMap = baseInfoMapper.selectList().stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getName, (v1, v2) -> v1)); + Map plotNameMap = plotInfoMapper.selectList().stream().collect(Collectors.toMap(PlotInfoDO::getPlotName, PlotInfoDO::getId, (v1, v2) -> v1)); + + PlotLesseeImportRespVO res = new PlotLesseeImportRespVO(); + res.setTotal(req.size()); + + List targetList = req.stream().filter(vo -> YES_NAME.equals(vo.getIsModified())).collect(Collectors.toList()); + + int successCount = 0; + int failuresCount = 0; + int unmodifiedCount = req.size() - targetList.size(); + List row = new ArrayList<>(); + for (PlotLesseeForImportExcelRespVO pl : targetList) { + PlotInfoDO p = plotInfoMapper.selectOne(PlotInfoDO::getPlotName, pl.getPlotName()); + if (ObjectUtils.isEmpty(p)) { + failuresCount++; + row.add(new PlotLesseeImportRespVO.Row(pl.getPlotCode(), pl.getPlotName())); + continue; + } + + PlotLesseeDO sourcePObj = plotLesseeMapper.selectOne( + PlotLesseeDO::getPlotName, pl.getPlotName(), + PlotLesseeDO::getLeaseStatus, YES_CODE); + + if (ObjectUtils.isEmpty(sourcePObj)) { + // 首次添加租户信息, 说明从未添加过户主信息, 直接录入即可 + this.pInsert(p,pl,baseNameMap); + successCount++; + continue; + } + + if (this.isEmpty(pl)) { + p.setPlotLeaseStatus(NO_CODE); + plotInfoMapper.updateById(p); + + sourcePObj.setLeaseStatus(NO_CODE); + plotLesseeMapper.updateById(sourcePObj); + continue; + } + + if (this.compareObj(sourcePObj,pl)) { + // 1. 更新原地块户主信息 + sourcePObj.setLeaseStatus(NO_CODE); + plotLesseeMapper.updateById(sourcePObj); + + this.pInsert(p,pl,baseNameMap); + successCount++; + }else{ + unmodifiedCount++; + } + } + + res.setSuccessCount(successCount); + res.setFailuresCount(failuresCount); + res.setUnmodifiedCount(unmodifiedCount); + res.setFailuresList(row); + return res; + } + + @Override + public List exportPlotLesseeInfoExcel() { + List bList = baseInfoMapper.selectList(); + Map baseNameMap = bList.stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getName, (v1, v2) -> v1)); + Map baseCodeMap = bList.stream().collect(Collectors.toMap(BaseInfoDO::getId, BaseInfoDO::getCode, (v1, v2) -> v1)); + + List pList = plotInfoMapper.selectList(); + Map plotCodeMap = pList.stream().collect(Collectors.toMap(PlotInfoDO::getId, PlotInfoDO::getPlotId, (v1, v2) -> v1)); + + LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); + x.eq(PlotLesseeDO::getLeaseStatus, YES_CODE); + List lList = plotLesseeMapper.selectList(x); + Map lesObjMap = lList.stream().collect(Collectors.toMap(PlotLesseeDO::getPlotId, e -> e, (v1, v2) -> v1)); + + List plotInfoDOS = plotInfoMapper.selectList(); + + + return plotInfoDOS.stream().map(p -> { + PlotLesseeForExportExcelRespVO target = new PlotLesseeForExportExcelRespVO( + baseCodeMap.get(p.getBaseId()), baseNameMap.get(p.getBaseId()), + plotCodeMap.get(p.getId()), p.getPlotName(), NO_NAME); + + if (p.getPlotLeaseStatus() == 1 && lesObjMap.containsKey(p.getId())) { + // 已租状态,计算租赁剩余天数 + PlotLesseeDO l = lesObjMap.get(p.getId()); + target.setLeaseName(l.getLeaseName()); + target.setLeaseIdCard(l.getLeaseIdCard()); + target.setLeasePhone(l.getLeasePhone()); + target.setLeaseStartDate(l.getLeaseStartDate()); + target.setLeaseEndDate(l.getLeaseEndDate()); + target.setLeaseRental(l.getLeaseRental().setScale(2, RoundingMode.HALF_UP)); + target.setExpirationDays(getDaysUntilLeaseEnd(l.getLeaseEndDate())); + } + return target; + }).toList(); + } + + @Override + public List getPlotLesseeList(String plotId) { + LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); + x.eq(PlotLesseeDO::getDeleted, NO_CODE); + x.eq(PlotLesseeDO::getLeaseStatus, YES_CODE); + x.eq(PlotLesseeDO::getPlotId, plotId); + List list = plotLesseeMapper.selectList(x); + + return BeanUtils.toBean(list, PlotLesseeDetailsRespVO.class); + } + + @Override + public List getPlotLesseeHistoryList(String plotId) { + LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); + x.eq(PlotLesseeDO::getDeleted, NO_CODE); + x.eq(PlotLesseeDO::getLeaseStatus, NO_CODE); + x.eq(PlotLesseeDO::getPlotId, plotId); + List list = plotLesseeMapper.selectList(x); + + return BeanUtils.toBean(list, PlotLesseeDetailsRespVO.class); + } + + @Override + public PlotLesseeInfoRespVO exportPlotLesseeInfoExcel(String id, PlotInfoDO plotInfo) { + LambdaQueryWrapperX x = new LambdaQueryWrapperX<>(); + x.eq(PlotLesseeDO::getTenantId, getLoginUser().getTenantId().toString()); + x.eq(PlotLesseeDO::getDeleted, CommonConstants.NO_CODE); + x.eq(PlotLesseeDO::getLeaseStatus, CommonConstants.YES_CODE); + x.eq(PlotLesseeDO::getPlotId, id); + PlotLesseeDO plotLesseeDO = plotLesseeMapper.selectOne(x); + + PlotLesseeDetailsRespVO subLesseeInfo = new PlotLesseeDetailsRespVO(); + if (ObjectUtils.isNotEmpty(plotLesseeDO)) { + subLesseeInfo = BeanUtils.toBean(plotLesseeDO, PlotLesseeDetailsRespVO.class); + } + + PlotLesseeInfoRespVO plotLesseeDetailsRespVO = BeanUtils.toBean(plotInfo, PlotLesseeInfoRespVO.class); + plotLesseeDetailsRespVO.setTypeName(PLOT_TYPE_NAME_MAP.get(plotLesseeDetailsRespVO.getType())); + plotLesseeDetailsRespVO.setPlotLessee(subLesseeInfo); + plotLesseeDetailsRespVO.setPlotLeaseStatusName(LEASE_STATUS_MAP.get(plotLesseeDetailsRespVO.getPlotLeaseStatus())); + plotLesseeDetailsRespVO.setCode(plotInfo.getPlotId()); + plotLesseeDetailsRespVO.setUpdateStateForCode(NO_CODE); + return plotLesseeDetailsRespVO; + } + + + + + // ==================== 私有方法 ==================== + + private void insertPlotLessee(PlotLesseeDO plotLesseeDO,String baseId,String plotId,String plotName) { + LoginUser user = getLoginUser(); + + plotLesseeDO.setId(IdUtil.fastUUID()); + plotLesseeDO.setTenantId(String.valueOf(user.getTenantId())); + plotLesseeDO.setLeaseStatus(CommonConstants.YES_CODE); + plotLesseeDO.setBaseId(baseId); + plotLesseeDO.setPlotId(plotId); + plotLesseeDO.setPlotName(plotName); + plotLesseeMapper.insert(plotLesseeDO); + } + + private long getDaysUntilLeaseEnd(LocalDate leaseEndDate) { + LocalDate today = LocalDate.now(); + return ChronoUnit.DAYS.between(today, leaseEndDate); + } + + private void pInsert(PlotInfoDO p, PlotLesseeForImportExcelRespVO pl, Map baseNameMap) { + PlotLesseeDO target = new PlotLesseeDO(); + target.setLeaseName(pl.getLeaseName()); + target.setLeaseIdCard(pl.getLeaseIdCard()); + target.setLeasePhone(pl.getLeasePhone()); + target.setLeaseStartDate(pl.getLeaseStartDate()); + target.setLeaseEndDate(pl.getLeaseEndDate()); + + target.setId(IdUtil.fastUUID()); + target.setTenantId(String.valueOf(getLoginUser().getTenantId())); + target.setLeaseStatus(CommonConstants.YES_CODE); + + target.setBaseId(p.getBaseId()); + target.setBaseName(baseNameMap.get(p.getBaseId())); + target.setPlotId(p.getId()); + target.setPlotName(p.getPlotName()); + plotLesseeMapper.insert(target); + + p.setPlotLeaseStatus(YES_CODE); + plotInfoMapper.updateById(p); + } + + /** + * 对比结果不一致返回: true (至少有一个字段不同) + * 对比结果一致返回: false (所有字段都相同) + * @param s + * @param t + * @return + */ + private boolean compareObj(PlotLesseeDO s, PlotLesseeForImportExcelRespVO t) { + return ObjectUtils.notEqual(s.getLeaseName(), t.getLeaseName()) || + ObjectUtils.notEqual(s.getLeaseIdCard(), t.getLeaseIdCard()) || + ObjectUtils.notEqual(s.getLeasePhone(), t.getLeasePhone()) || + ObjectUtils.notEqual(s.getLeaseRental(), t.getLeaseRental()) || + !s.getLeaseStartDate().isEqual(t.getLeaseStartDate()) || + !s.getLeaseEndDate().isEqual(t.getLeaseEndDate()); + } + + private boolean isEmpty(PlotLesseeForImportExcelRespVO t) { + return Objects.equals(t.getLeaseName(), null) || + Objects.equals(t.getLeaseIdCard(), null) || + Objects.equals(t.getLeasePhone(), null) || + Objects.equals(t.getLeaseRental(), null) || + Objects.equals(t.getLeaseStartDate(), null) || + Objects.equals(t.getLeaseEndDate(), null); + } }