farm模块-字典优化

This commit is contained in:
顾君禹
2025-09-02 15:34:12 +08:00
parent c49ae4dc93
commit e76630a4a1
27 changed files with 530 additions and 115 deletions

View File

@@ -13,7 +13,7 @@ public class DisasterDataSaveReqVO {
@Schema(description = "灾害名称", example = "赵六")
private String name;
@Schema(description = "灾害类型1=环境,2=病害,3=虫害,4=草害")
private String category;
private Integer category;
@Schema(description = "灾害类型 1:普通; 2:气象灾害")
private Integer type;
@Schema(description = "灾害描述")

View File

@@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenancePageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceTreeRespVO;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.Valid;
@@ -44,7 +45,6 @@ public class FarmingNameMaintenanceController {
@PostMapping("/create")
@Operation(summary = "创建农事名称维护")
public CommonResult<String> createFarmingNameMaintenance(@Valid @RequestBody FarmingNameMaintenanceSaveReqVO createReqVO) {
return success(farmingNameMaintenanceService.createFarmingNameMaintenance(createReqVO));
}
@@ -87,9 +87,15 @@ public class FarmingNameMaintenanceController {
return success(BeanUtils.toBean(pageResult, FarmingNameMaintenanceRespVO.class));
}
@GetMapping("/tree")
@Operation(summary = "获得农事名称维护树形结构")
public CommonResult<List<FarmingNameMaintenanceTreeRespVO>> getFarmingNameMaintenanceTree() {
List<FarmingNameMaintenanceTreeRespVO> tree = farmingNameMaintenanceService.getFarmingNameMaintenanceTree();
return success(tree);
}
@GetMapping("/export-excel")
@Operation(summary = "导出农事名称维护 Excel")
@ApiAccessLog(operateType = EXPORT)
public void exportFarmingNameMaintenanceExcel(@Valid FarmingNameMaintenancePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {

View File

@@ -1,37 +1,30 @@
package cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.FarmingTypeMaintenancePageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.FarmingTypeMaintenanceRespVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingtypemaintenance.vo.FarmingTypeMaintenanceSaveReqVO;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.Valid;
import jakarta.validation.Valid;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingtypemaintenance.FarmingTypeMaintenanceDO;
import cn.iocoder.yudao.module.farm.service.farmingtypemaintenance.FarmingTypeMaintenanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 农事类型维护")
@RestController
@@ -44,14 +37,12 @@ public class FarmingTypeMaintenanceController {
@PostMapping("/create")
@Operation(summary = "创建农事类型维护")
public CommonResult<String> createFarmingTypeMaintenance(@Valid @RequestBody FarmingTypeMaintenanceSaveReqVO createReqVO) {
return success(farmingTypeMaintenanceService.createFarmingTypeMaintenance(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新农事类型维护")
public CommonResult<Boolean> updateFarmingTypeMaintenance(@Valid @RequestBody FarmingTypeMaintenanceSaveReqVO updateReqVO) {
farmingTypeMaintenanceService.updateFarmingTypeMaintenance(updateReqVO);
return success(true);
@@ -60,7 +51,6 @@ public class FarmingTypeMaintenanceController {
@DeleteMapping("/delete")
@Operation(summary = "删除农事类型维护")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<Boolean> deleteFarmingTypeMaintenance(@RequestParam("id") String id) {
farmingTypeMaintenanceService.deleteFarmingTypeMaintenance(id);
return success(true);
@@ -69,7 +59,6 @@ public class FarmingTypeMaintenanceController {
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除农事类型维护")
public CommonResult<Boolean> deleteFarmingTypeMaintenanceList(@RequestParam("ids") List<String> ids) {
farmingTypeMaintenanceService.deleteFarmingTypeMaintenanceListByIds(ids);
return success(true);
@@ -78,15 +67,20 @@ public class FarmingTypeMaintenanceController {
@GetMapping("/get")
@Operation(summary = "获得农事类型维护")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<FarmingTypeMaintenanceRespVO> getFarmingTypeMaintenance(@RequestParam("id") String id) {
FarmingTypeMaintenanceDO farmingTypeMaintenance = farmingTypeMaintenanceService.getFarmingTypeMaintenance(id);
return success(BeanUtils.toBean(farmingTypeMaintenance, FarmingTypeMaintenanceRespVO.class));
}
@GetMapping("/list")
@Operation(summary = "农事类型列表")
public CommonResult<List<FarmingTypeMaintenanceRespVO>> getFarmingTypeMaintenanceList() {
List<FarmingTypeMaintenanceDO> pageResult = farmingTypeMaintenanceService.getFarmingTypeMaintenanceList();
return success(BeanUtils.toBean(pageResult, FarmingTypeMaintenanceRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得农事类型维护分页")
public CommonResult<PageResult<FarmingTypeMaintenanceRespVO>> getFarmingTypeMaintenancePage(@Valid FarmingTypeMaintenancePageReqVO pageReqVO) {
PageResult<FarmingTypeMaintenanceDO> pageResult = farmingTypeMaintenanceService.getFarmingTypeMaintenancePage(pageReqVO);
return success(BeanUtils.toBean(pageResult, FarmingTypeMaintenanceRespVO.class));
@@ -94,7 +88,6 @@ public class FarmingTypeMaintenanceController {
@GetMapping("/export-excel")
@Operation(summary = "导出农事类型维护 Excel")
@ApiAccessLog(operateType = EXPORT)
public void exportFarmingTypeMaintenanceExcel(@Valid FarmingTypeMaintenancePageReqVO pageReqVO,
HttpServletResponse response) throws IOException {

View File

@@ -44,14 +44,12 @@ public class InputLibraryController {
@PostMapping("/create")
@Operation(summary = "创建投入品库维护")
public CommonResult<String> createInputLibrary(@Valid @RequestBody InputLibrarySaveReqVO createReqVO) {
return success(inputLibraryService.createInputLibrary(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新投入品库维护")
public CommonResult<Boolean> updateInputLibrary(@Valid @RequestBody InputLibrarySaveReqVO updateReqVO) {
inputLibraryService.updateInputLibrary(updateReqVO);
return success(true);
@@ -60,7 +58,6 @@ public class InputLibraryController {
@DeleteMapping("/delete")
@Operation(summary = "删除投入品库维护")
@Parameter(name = "id", description = "编号", required = true)
public CommonResult<Boolean> deleteInputLibrary(@RequestParam("id") String id) {
inputLibraryService.deleteInputLibrary(id);
return success(true);
@@ -69,7 +66,6 @@ public class InputLibraryController {
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除投入品库维护")
public CommonResult<Boolean> deleteInputLibraryList(@RequestParam("ids") List<String> ids) {
inputLibraryService.deleteInputLibraryListByIds(ids);
return success(true);
@@ -78,7 +74,6 @@ public class InputLibraryController {
@GetMapping("/get")
@Operation(summary = "获得投入品库维护")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
public CommonResult<InputLibraryRespVO> getInputLibrary(@RequestParam("id") String id) {
InputLibraryDO inputLibrary = inputLibraryService.getInputLibrary(id);
return success(BeanUtils.toBean(inputLibrary, InputLibraryRespVO.class));
@@ -86,7 +81,6 @@ public class InputLibraryController {
@GetMapping("/page")
@Operation(summary = "获得投入品库维护分页")
public CommonResult<PageResult<InputLibraryRespVO>> getInputLibraryPage(@Valid InputLibraryPageReqVO pageReqVO) {
PageResult<InputLibraryDO> pageResult = inputLibraryService.getInputLibraryPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, InputLibraryRespVO.class));
@@ -94,7 +88,6 @@ public class InputLibraryController {
@GetMapping("/export-excel")
@Operation(summary = "导出投入品库维护 Excel")
@ApiAccessLog(operateType = EXPORT)
public void exportInputLibraryExcel(@Valid InputLibraryPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {

View File

@@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
public class InputLibraryPageReqVO extends PageParam {
@Schema(description = "投入品类型", example = "2")
private String assetType;
private Integer assetType;
@Schema(description = "投入品名称", example = "王五")
private String assetName;
@@ -24,10 +24,10 @@ public class InputLibraryPageReqVO extends PageParam {
private BigDecimal dose;
@Schema(description = "单位")
private String unit;
private Integer unit;
@Schema(description = "单件")
private String packageUnit;
private Integer packageUnit;
@Schema(description = "单价", example = "23806")
private BigDecimal price;
@@ -39,7 +39,7 @@ public class InputLibraryPageReqVO extends PageParam {
private String manufacturer;
@Schema(description = "药物类型", example = "2")
private String drugType;
private Integer drugType;
@Schema(description = "有效成分")
private String activePrinciple;

View File

@@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.farm.controller.admin.inputlibrary.vo;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
@@ -19,7 +20,8 @@ public class InputLibraryRespVO {
@Schema(description = "投入品类型", example = "2")
@ExcelProperty("投入品类型")
private String assetType;
@DictFormat("asset_type")
private Integer assetType;
@Schema(description = "投入品名称-编号")
@ExcelProperty("投入品名称")
@@ -35,13 +37,15 @@ public class InputLibraryRespVO {
@Schema(description = "单位")
@ExcelProperty("单位")
private String unit;
@DictFormat("asset_unit")
private Integer unit;
private String unitName;
@Schema(description = "单件")
@ExcelProperty("单件")
private String packageUnit;
@DictFormat("asset_price")
private Integer packageUnit;
private String packageUnitName;
@@ -59,7 +63,8 @@ public class InputLibraryRespVO {
@Schema(description = "药物类型", example = "2")
@ExcelProperty("药物类型")
private String drugType;
@DictFormat("drug_type")
private Integer drugType;
@Schema(description = "有效成分")
@ExcelProperty("有效成分")

View File

@@ -13,7 +13,7 @@ public class InputLibrarySaveReqVO {
private String id;
@Schema(description = "投入品类型", example = "2")
private String assetType;
private Integer assetType;
@Schema(description = "投入品名称", example = "王五")
private String assetName;
@@ -22,10 +22,10 @@ public class InputLibrarySaveReqVO {
private BigDecimal dose;
@Schema(description = "单位")
private String unit;
private Integer unit;
@Schema(description = "单件")
private String packageUnit;
private Integer packageUnit;
@Schema(description = "单价", example = "23806")
private BigDecimal price;
@@ -37,7 +37,7 @@ public class InputLibrarySaveReqVO {
private String manufacturer;
@Schema(description = "药物类型", example = "2")
private String drugType;
private Integer drugType;
@Schema(description = "有效成分")
private String activePrinciple;

View File

@@ -14,7 +14,8 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "管理后台 - 模型管理分页 Request VO")
@Data
public class ModelManagementPageReqVO extends PageParam {
@Schema(description = "模型名称", example = "芋艿")
private String name;
@Schema(description = "模型名称", example = "芋艿")
private String modelName;

View File

@@ -17,7 +17,7 @@ public class ModelPestDiseaseWeedPageReqVO extends PageParam {
private String cycleId;
@Schema(description = "病虫草害类型", example = "2")
private String type;
private Integer type;
@Schema(description = "病虫草害名称", example = "芋艿")
private String name;

View File

@@ -22,7 +22,7 @@ public class ModelPestDiseaseWeedRespVO {
@Schema(description = "病虫草害类型", example = "2")
@ExcelProperty("病虫草害类型")
private String type;
private Integer type;
@Schema(description = "病虫草害名称", example = "芋艿")
@ExcelProperty("病虫草害名称")

View File

@@ -14,7 +14,7 @@ public class ModelPestDiseaseWeedSaveReqVO {
private String cycleId;
@Schema(description = "病虫草害类型", example = "2")
private String type;
private Integer type;
@Schema(description = "病虫草害名称", example = "芋艿")
private String name;

View File

@@ -93,4 +93,60 @@ public class FarmWebSocketController {
return success("测试消息推送成功");
}
@GetMapping("/status")
@Operation(summary = "检查WebSocket连接状态")
@PreAuthorize("@ss.hasPermission('farm:websocket:push')")
public CommonResult<String> checkWebSocketStatus() {
log.info("[checkWebSocketStatus][检查WebSocket连接状态]");
farmMessagePushService.checkWebSocketStatus();
return success("WebSocket状态检查完成,请查看日志");
}
@PostMapping("/push-to-tenant")
@Operation(summary = "向指定租户推送系统通知")
@PreAuthorize("@ss.hasPermission('farm:websocket:push')")
public CommonResult<String> pushToTenant(
@RequestParam @NotBlank(message = "标题不能为空") String title,
@RequestParam @NotBlank(message = "内容不能为空") String content,
@RequestParam @NotNull(message = "租户ID不能为空") Long tenantId) {
log.info("[pushToTenant][向租户推送系统通知][tenantId: {}][title: {}]", tenantId, title);
farmMessagePushService.pushSystemNotificationToTenant(title, content, tenantId);
return success("向租户推送系统通知成功");
}
@PostMapping("/push-all-tenants")
@Operation(summary = "向所有租户推送系统通知")
@PreAuthorize("@ss.hasPermission('farm:websocket:push')")
public CommonResult<String> pushToAllTenants(
@RequestParam @NotBlank(message = "标题不能为空") String title,
@RequestParam @NotBlank(message = "内容不能为空") String content) {
log.info("[pushToAllTenants][向所有租户推送系统通知][title: {}]", title);
// 向所有租户的所有用户类型推送消息
farmMessagePushService.pushSystemNotificationToAllTenants(title, content);
return success("向所有租户推送系统通知成功");
}
@PostMapping("/push-all-user-types")
@Operation(summary = "向所有用户类型推送系统通知")
@PreAuthorize("@ss.hasPermission('farm:websocket:push')")
public CommonResult<String> pushToAllUserTypes(
@RequestParam @NotBlank(message = "标题不能为空") String title,
@RequestParam @NotBlank(message = "内容不能为空") String content) {
log.info("[pushToAllUserTypes][向所有用户类型推送系统通知][title: {}]", title);
// 向所有用户类型推送消息
farmMessagePushService.pushSystemNotificationToAllTenants(title, content);
return success("向所有用户类型推送系统通知成功");
}
}

View File

@@ -2,9 +2,7 @@ package cn.iocoder.yudao.module.farm.dal.dataobject.disasterdata;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.farm.framework.util.ImageCollectionUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import java.util.List;
@@ -14,6 +12,8 @@ import java.util.List;
*
* @author 芋道源码
*/
@TableName("farm_disaster_data")
@KeySequence("farm_disaster_data_seq")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@@ -35,7 +35,7 @@ public class DisasterDataDO extends BaseDO {
/**
* 灾害类型 2=病害,1=虫害,3=草害
*/
private String category;
private int category;
private String categoryName;
/**
* 灾害类别 1:普通; 2:气象灾害

View File

@@ -1,8 +1,10 @@
package cn.iocoder.yudao.module.farm.dal.dataobject.inputlibrary;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import lombok.*;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
@@ -29,7 +31,8 @@ public class InputLibraryDO extends BaseDO {
/**
* 投入品类型
*/
private String assetType;
@DictFormat("asset_type")
private Integer assetType;
/**
* 投入品名称
*/
@@ -41,11 +44,13 @@ public class InputLibraryDO extends BaseDO {
/**
* 单位
*/
private String unit;
@DictFormat("asset_unit")
private Integer unit;
/**
* 单件
*/
private String packageUnit;
@DictFormat("asset_price")
private Integer packageUnit;
/**
* 单价
*/
@@ -61,7 +66,8 @@ public class InputLibraryDO extends BaseDO {
/**
* 药物类型
*/
private String drugType;
@DictFormat("drug_type")
private Integer drugType;
/**
* 有效成分
*/

View File

@@ -34,7 +34,7 @@ public class ModelPestDiseaseWeedDO extends BaseDO {
/**
* 病虫草害类型
*/
private String type;
private Integer type;
/**
* 病虫草害名称
*/

View File

@@ -31,6 +31,4 @@ public interface FarmingTypeMaintenanceMapper extends BaseMapperX<FarmingTypeMai
}
List<FarmingTypeMaintenanceDO> listForFarmingType();
Boolean update(@Param("req") FarmingTypeMaintenanceDO reqVO);
}

View File

@@ -22,6 +22,7 @@ public interface ModelManagementMapper extends BaseMapperX<ModelManagementDO> {
MPJLambdaWrapperX<ModelManagementDO> query = new MPJLambdaWrapperX<ModelManagementDO>()
.selectAll(ModelManagementDO.class)
.likeIfPresent(ModelManagementDO::getModelName, reqVO.getModelName())
.likeIfPresent(ModelManagementDO::getModelName, reqVO.getName())
.eqIfPresent(ModelManagementDO::getSpeciesId, reqVO.getSpeciesId())
.likeIfPresent(ModelManagementDO::getSpeciesName, reqVO.getSpeciesName())
.eqIfPresent(ModelManagementDO::getCycle, reqVO.getCycle())

View File

@@ -144,7 +144,7 @@ public class BaseInfoServiceImpl implements BaseInfoService {
for (PlotInfoDO aDo : plotInfoDOS) {
if (aDo.getBaseId().equals(key)) {
double remainingArea = productionPlanService.getPredictedArea(aDo.getBaseId());
childList.add(new BaseNameRespVO.PlotInfoVO(aDo.getPlotId(), aDo.getPlotName(), aDo.getPlotArea(),remainingArea));
childList.add(new BaseNameRespVO.PlotInfoVO(aDo.getPlotId(), aDo.getPlotName(), aDo.getPlotArea(), remainingArea));
}
}
obj.setChildren(childList);
@@ -174,7 +174,7 @@ 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);
this.packageBaseInfo(tenantId, baseList, employeeMap);
return new TenantInfoRespVO(tenantInfo, baseList);
}
@@ -183,23 +183,25 @@ public class BaseInfoServiceImpl implements BaseInfoService {
// 基地总数
Integer baseCount = baseInfoMapper.getBaseCount(tenantId);
// 在种作物总数
Integer cropCount = speciesLibraryMapper.getSpeciesCount(tenantId,"");
Integer cropCount = speciesLibraryMapper.getSpeciesCount(tenantId, "");
// 基地总面积
BigDecimal areaCount = new BigDecimal("0.00");
if (baseCount > 0) {
QueryWrapper<BaseInfoDO> wrapper = new QueryWrapper<>();
wrapper.eq("tenant_id", tenantId);
wrapper.select("SUM(area) as total_area");
Object result = baseInfoMapper.selectObjs(wrapper).stream().findFirst().orElse(BigDecimal.ZERO);
BigDecimal areaCount = (BigDecimal) result;
areaCount = (BigDecimal) result;
}
return new TenantInfoRespVO.TenantInfo(baseCount, cropCount, areaCount, employeeCount);
}
private void packageBaseInfo(long tenantId,List<BaseInfoRespVO> respVOS, Map<String, String> employeeMap) {
private void packageBaseInfo(long tenantId, List<BaseInfoRespVO> respVOS, Map<String, String> employeeMap) {
for (BaseInfoRespVO obj : respVOS) {
String baseId = obj.getId();
String baseName = obj.getName();
BigDecimal baseArea = obj.getArea();
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos( baseId);
List<PlotInfoDO> plotList = plotInfoService.getPlotInfos(baseId);
// 基地概述
BaseInfoRespVO.BaseInfo baseOverview = this.packageBaseOverview(tenantId, baseId, baseName, baseArea, plotList);

View File

@@ -81,14 +81,14 @@ public class DisasterDataServiceImpl implements DisasterDataService {
SysDictDO insertObj = new SysDictDO();
if (type == 1) {
// 一般灾害 父类编号
String category = obj.getCategory();
Integer category = obj.getCategory();
// 一般灾害
List<SysDictDO> list = sysDictMapper.groupByFieldCode(DICT_TYPE_CODE_1);
Map<String, String> parentMap = list.stream().collect(Collectors.toMap(SysDictDO::getField1Code, SysDictDO::getField1Name, (v1, v2) -> v1));
insertObj.setDictTypeCode(DICT_TYPE_CODE_1);
insertObj.setDictTypeName("一般灾害");
insertObj.setField1Code(category);
insertObj.setField1Code(category.toString());
insertObj.setField1Name(parentMap.get(category));
insertObj.setField2Code(StrHelperUtil.generate());
insertObj.setField2Name(name);
@@ -150,10 +150,10 @@ public class DisasterDataServiceImpl implements DisasterDataService {
SysDictDO aDo = sysDictMapper.getDictByFieldCode(query);
// 一般灾害 父类编号
String category = obj.getCategory();
Integer category = obj.getCategory();
SysDictDO updateObj = new SysDictDO();
updateObj.setId(aDo.getId());
updateObj.setField1Code(category);
updateObj.setField1Code(category.toString());
updateObj.setField1Name(parentMap.get(category));
updateObj.setField2Code(aDo.getField2Code());
updateObj.setField2Name(name);

View File

@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.farm.service.farmingnamemaintenance;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenancePageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceTreeRespVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingnamemaintenance.FarmingNameMaintenanceDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -61,4 +62,11 @@ public interface FarmingNameMaintenanceService {
*/
PageResult<FarmingNameMaintenanceDO> getFarmingNameMaintenancePage(FarmingNameMaintenancePageReqVO pageReqVO);
/**
* 获得农事名称维护树形结构
*
* @return 农事名称维护树形结构
*/
List<FarmingNameMaintenanceTreeRespVO> getFarmingNameMaintenanceTree();
}

View File

@@ -6,14 +6,19 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenancePageReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.farmingnamemaintenance.vo.FarmingNameMaintenanceTreeRespVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingnamemaintenance.FarmingNameMaintenanceDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.farmingtypemaintenance.FarmingTypeMaintenanceDO;
import cn.iocoder.yudao.module.farm.dal.mysql.farmingnamemaintenance.FarmingNameMaintenanceMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.farmingtypemaintenance.FarmingTypeMaintenanceMapper;
import cn.iocoder.yudao.module.farm.utils.StrHelperUtil;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
@@ -30,6 +35,8 @@ public class FarmingNameMaintenanceServiceImpl implements FarmingNameMaintenance
@Resource
private FarmingNameMaintenanceMapper farmingNameMaintenanceMapper;
@Resource
private FarmingTypeMaintenanceMapper farmingTypeMaintenanceMapper;
@Override
public String createFarmingNameMaintenance(FarmingNameMaintenanceSaveReqVO createReqVO) {
@@ -39,6 +46,10 @@ public class FarmingNameMaintenanceServiceImpl implements FarmingNameMaintenance
farmingNameMaintenance.setId(IdUtil.fastUUID());
farmingNameMaintenance.setTenantId(String.valueOf(user.getTenantId()));
farmingNameMaintenance.setFarmingCode(StrHelperUtil.generate());
farmingNameMaintenance.setFarmingTypeCode(createReqVO.getFarmingType());
FarmingTypeMaintenanceDO farmingTypeMaintenanceDO = farmingTypeMaintenanceMapper.selectById(createReqVO.getFarmingType());
farmingNameMaintenance.setFarmingTypeName(farmingTypeMaintenanceDO.getFarmingName());
farmingNameMaintenance.setCreateTime(LocalDateTime.now());
farmingNameMaintenanceMapper.insert(farmingNameMaintenance);
// 返回
@@ -68,7 +79,7 @@ public class FarmingNameMaintenanceServiceImpl implements FarmingNameMaintenance
farmingNameMaintenanceMapper.deleteByIds(ids);
}
private void validateFarmingNameMaintenanceExists(String id) {
private void validateFarmingNameMaintenanceExists(String id) {
if (farmingNameMaintenanceMapper.selectById(id) == null) {
throw exception(FARMING_NAME_MAINTENANCE_NOT_EXISTS);
}
@@ -84,4 +95,67 @@ private void validateFarmingNameMaintenanceExists(String id) {
return farmingNameMaintenanceMapper.selectPage(pageReqVO);
}
@Override
public List<FarmingNameMaintenanceTreeRespVO> getFarmingNameMaintenanceTree() {
List<FarmingTypeMaintenanceDO> allData = farmingTypeMaintenanceMapper.selectList(FarmingTypeMaintenanceDO::getUseStatus, 1);
if (allData == null || allData.isEmpty()) {
return new java.util.ArrayList<>();
}
// 按农事类型分组
Map<String, List<FarmingTypeMaintenanceDO>> groupedByType = allData.stream()
.collect(java.util.stream.Collectors.groupingBy(
FarmingTypeMaintenanceDO::getId,
java.util.stream.Collectors.toList()
));
// 构建树形结构
List<FarmingNameMaintenanceTreeRespVO> result = new java.util.ArrayList<>();
for (Map.Entry<String, List<FarmingTypeMaintenanceDO>> entry : groupedByType.entrySet()) {
String typeCode = entry.getKey();
List<FarmingTypeMaintenanceDO> typeData = entry.getValue();
if (typeData.isEmpty()) {
continue;
}
// 获取农事类型名称(从第一条记录获取)
String typeName = typeData.get(0).getFarmingName();
// 创建一级节点(农事类型)
FarmingNameMaintenanceTreeRespVO typeNode = FarmingNameMaintenanceTreeRespVO.builder()
.farmingTypeCode(typeCode)
.farmingTypeName(typeName)
.level(1)
.leaf(false)
.children(new java.util.ArrayList<>())
.build();
// 添加二级节点(农事名称)
List<FarmingNameMaintenanceDO> farmingNameMaintenanceDOS = farmingNameMaintenanceMapper.selectList(FarmingNameMaintenanceDO::getFarmingTypeCode, typeCode, FarmingNameMaintenanceDO::getUseStatus, 1);
for (FarmingNameMaintenanceDO nameData : farmingNameMaintenanceDOS) {
FarmingNameMaintenanceTreeRespVO nameNode = FarmingNameMaintenanceTreeRespVO.builder()
.farmingTypeCode(typeCode)
.farmingTypeName(typeName)
.farmingCode(nameData.getFarmingCode())
.farmingName(nameData.getFarmingName())
.useStatus(nameData.getUseStatus())
.createTime(nameData.getCreateTime())
.level(2)
.leaf(true)
.children(null)
.build();
typeNode.getChildren().add(nameNode);
}
result.add(typeNode);
}
return result;
}
}

View File

@@ -67,4 +67,7 @@ public interface FarmingTypeMaintenanceService {
List<FarmingTypeMaintenanceDO> getFarmingTypeList();
FarmingTypeMaintenanceDO getFarmingName(String farmingTypeCode);
List<FarmingTypeMaintenanceDO> getFarmingTypeMaintenanceList();
}

View File

@@ -54,7 +54,7 @@ public class FarmingTypeMaintenanceServiceImpl implements FarmingTypeMaintenance
validateFarmingTypeMaintenanceExists(updateReqVO.getId());
// 更新
FarmingTypeMaintenanceDO updateObj = BeanUtils.toBean(updateReqVO, FarmingTypeMaintenanceDO.class);
farmingTypeMaintenanceMapper.update(updateObj);
farmingTypeMaintenanceMapper.updateById(updateObj);
}
@Override
@@ -96,4 +96,9 @@ public class FarmingTypeMaintenanceServiceImpl implements FarmingTypeMaintenance
public FarmingTypeMaintenanceDO getFarmingName(String farmingTypeCode) {
return farmingTypeMaintenanceMapper.selectOne(FarmingTypeMaintenanceDO::getFarmingCode, farmingTypeCode);
}
@Override
public List<FarmingTypeMaintenanceDO> getFarmingTypeMaintenanceList() {
return farmingTypeMaintenanceMapper.selectList(FarmingTypeMaintenanceDO::getTenantId, getLoginUser().getTenantId(), FarmingTypeMaintenanceDO::getUseStatus, 1);
}
}

View File

@@ -69,13 +69,13 @@ public class InputLibraryServiceImpl implements InputLibraryService {
Map<String, String> parentMap = list.stream().collect(Collectors.toMap(SysDictDO::getField1Code, SysDictDO::getField1Name, (v1, v2) -> v1));
InputLibraryDO aDo = inputLibraryMapper.selectById(id);
String assetType = aDo.getAssetType();// 父类编号
Integer assetType = aDo.getAssetType();// 父类编号
String assetName = aDo.getAssetName();// 子类名称
SysDictDO insertObj = new SysDictDO();
insertObj.setDictTypeCode(DICT_TYPE_CODE_4);
insertObj.setDictTypeName("投入品");
insertObj.setField1Code(assetType);
insertObj.setField1Code(assetType.toString());
insertObj.setField1Name(parentMap.get(assetType));
insertObj.setField2Code(StrHelperUtil.generate());
insertObj.setField2Name(assetName);
@@ -103,7 +103,7 @@ public class InputLibraryServiceImpl implements InputLibraryService {
private void syncUpdateDict(String id) {
InputLibraryDO aDo = inputLibraryMapper.selectById(id);
String assetType = aDo.getAssetType();// 父类编号
Integer assetType = aDo.getAssetType();// 父类编号
String assetName = aDo.getAssetName();// 子类名称
List<SysDictDO> list = sysDictMapper.groupByFieldCode(DICT_TYPE_CODE_4);
@@ -116,7 +116,7 @@ public class InputLibraryServiceImpl implements InputLibraryService {
SysDictDO updateObj = new SysDictDO();
updateObj.setId(Integer.valueOf(id));
updateObj.setField1Code(assetType);
updateObj.setField1Code(assetType.toString());
updateObj.setField1Name(parentMap.get(assetType));
updateObj.setField2Code(obj.getField2Code());
updateObj.setField2Name(assetName);

View File

@@ -95,4 +95,41 @@ public interface FarmMessagePushService {
* @param plotId 地块ID
*/
void pushSystemNotification(String title, String content, String baseId, String plotId);
/**
* 检查WebSocket连接状态
*/
void checkWebSocketStatus();
/**
* 向指定租户的所有用户推送消息
*
* @param message 消息
* @param tenantId 租户ID
*/
void pushMessageToTenant(MessageCenterDO message, Long tenantId);
/**
* 向指定租户的所有用户推送系统通知
*
* @param title 标题
* @param content 内容
* @param tenantId 租户ID
*/
void pushSystemNotificationToTenant(String title, String content, Long tenantId);
/**
* 向所有租户的所有用户类型推送系统通知
*
* @param title 标题
* @param content 内容
*/
void pushSystemNotificationToAllTenants(String title, String content);
/**
* 向所有用户类型推送消息(不依赖租户)
*
* @param message 消息
*/
void pushMessageToAllUserTypes(MessageCenterDO message);
}

View File

@@ -4,6 +4,10 @@ import cn.hutool.core.util.IdUtil;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender;
import cn.iocoder.yudao.framework.websocket.core.session.WebSocketSessionManager;
import cn.iocoder.yudao.framework.websocket.core.util.WebSocketFrameworkUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
import cn.iocoder.yudao.module.farm.controller.admin.messagecenter.vo.MessageCenterSaveReqVO;
import cn.iocoder.yudao.module.farm.controller.admin.websocket.vo.FarmWebSocketMessageVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.messagecenter.MessageCenterDO;
@@ -13,8 +17,11 @@ import cn.iocoder.yudao.module.farm.service.messagecenter.MessageCenterService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.socket.WebSocketSession;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import java.time.LocalDateTime;
import java.util.Collection;
/**
* 农场消息推送 Service 实现类
@@ -31,6 +38,9 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
@Resource
private MessageCenterService messageCenterService;
@Resource
private WebSocketSessionManager webSocketSessionManager;
@Override
public void pushAlarmMessage(MessageCenterDO message) {
log.info("[pushAlarmMessage][推送报警消息][messageId: {}][title: {}]",
@@ -101,8 +111,35 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
// 转换为WebSocket消息格式
FarmWebSocketMessageVO wsMessage = convertToWebSocketMessage(message);
// 推送到指定用户
webSocketMessageSender.send(1, Long.valueOf(userId), "farm", JsonUtils.toJsonString(wsMessage));
// 推送到指定用户(所有用户类型)
pushMessageToUserAllTypes(wsMessage, Long.valueOf(userId));
}
/**
* 向指定用户的所有用户类型推送消息
*/
private void pushMessageToUserAllTypes(FarmWebSocketMessageVO wsMessage, Long userId) {
log.info("[pushMessageToUserAllTypes][开始向用户{}的所有用户类型推送消息][messageId: {}]",
userId, wsMessage.getMessageId());
// 用户类型:1=会员,2=管理员
int successCount = 0;
int totalCount = 3;
for (int userType = 1; userType <= 3; userType++) {
try {
webSocketMessageSender.send(userType, userId, "farm", JsonUtils.toJsonString(wsMessage));
successCount++;
log.info("[pushMessageToUserAllTypes][向用户类型{}的用户{}推送消息成功][messageId: {}][userType: {}]",
userType, userId, wsMessage.getMessageId(), getUserTypeName(userType));
} catch (Exception e) {
log.warn("[pushMessageToUserAllTypes][向用户类型{}的用户{}推送消息失败][messageId: {}][userType: {}]",
userType, userId, wsMessage.getMessageId(), getUserTypeName(userType), e);
}
}
log.info("[pushMessageToUserAllTypes][推送完成][userId: {}][messageId: {}][成功: {}/{}]",
userId, wsMessage.getMessageId(), successCount, totalCount);
}
@Override
@@ -112,8 +149,8 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
// 转换为WebSocket消息格式
FarmWebSocketMessageVO wsMessage = convertToWebSocketMessage(message);
// 广播消息
webSocketMessageSender.send(1, "farm", JsonUtils.toJsonString(wsMessage));
// 广播消息到所有用户类型
pushMessageToAllUserTypes(wsMessage, getCurrentTenantId());
}
@Override
@@ -181,6 +218,47 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
pushNormalMessage(message);
}
/**
* 检查WebSocket连接状态
*/
public void checkWebSocketStatus() {
try {
log.info("[checkWebSocketStatus][开始检查WebSocket连接状态]");
// 获取当前租户ID
Long currentTenantId = getCurrentTenantId();
log.info("[checkWebSocketStatus][当前租户ID: {}]", currentTenantId);
// 检查所有用户类型的session
int totalSessions = 0;
for (int userType = 1; userType <= 3; userType++) {
Collection<WebSocketSession> sessions = webSocketSessionManager.getSessionList(userType);
log.info("[checkWebSocketStatus][用户类型{}的session数量: {}]", userType, sessions.size());
totalSessions += sessions.size();
// 打印每个session的信息
for (WebSocketSession session : sessions) {
LoginUser loginUser = WebSocketFrameworkUtils.getLoginUser(session);
if (loginUser != null) {
log.info("[checkWebSocketStatus][用户信息][sessionId: {}][userId: {}][userType: {}][tenantId: {}]",
session.getId(), loginUser.getId(), loginUser.getUserType(), loginUser.getTenantId());
} else {
log.warn("[checkWebSocketStatus][用户信息为空][sessionId: {}]", session.getId());
}
}
}
log.info("[checkWebSocketStatus][总session数量: {}]", totalSessions);
if (totalSessions == 0) {
log.warn("[checkWebSocketStatus][没有找到WebSocket连接,但消息推送会继续执行]");
}
} catch (Exception e) {
log.error("[checkWebSocketStatus][检查WebSocket状态失败]", e);
}
}
/**
* 转换为WebSocket消息格式
*/
@@ -260,8 +338,13 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
*/
private void pushMessage(FarmWebSocketMessageVO wsMessage) {
try {
// 广播消息到所有在线用户
webSocketMessageSender.send(1, "farm", JsonUtils.toJsonString(wsMessage));
// 获取当前租户ID
Long currentTenantId = getCurrentTenantId();
log.info("[pushMessage][准备推送消息][messageId: {}][title: {}][tenantId: {}]",
wsMessage.getMessageId(), wsMessage.getTitle(), currentTenantId);
// 向租户下的所有用户类型推送消息
pushMessageToAllUserTypes(wsMessage, currentTenantId);
log.info("[pushMessage][消息推送成功][messageId: {}][title: {}]",
wsMessage.getMessageId(), wsMessage.getTitle());
@@ -270,4 +353,151 @@ public class FarmMessagePushServiceImpl implements FarmMessagePushService {
wsMessage.getMessageId(), wsMessage.getTitle(), e);
}
}
/**
* 向所有用户类型推送消息
*/
private void pushMessageToAllUserTypes(FarmWebSocketMessageVO wsMessage, Long tenantId) {
log.info("[pushMessageToAllUserTypes][开始向所有用户类型推送消息][messageId: {}][tenantId: {}]",
wsMessage.getMessageId(), tenantId);
// 用户类型:1=管理后台用户,2=用户APP用户,3=其他类型用户
int successCount = 0;
int totalCount = 3;
for (int userType = 1; userType <= 3; userType++) {
try {
// 向指定用户类型的所有用户推送消息
webSocketMessageSender.send(userType, "farm", JsonUtils.toJsonString(wsMessage));
successCount++;
log.info("[pushMessageToAllUserTypes][向用户类型{}推送消息成功][messageId: {}][userType: {}]",
userType, wsMessage.getMessageId(), getUserTypeName(userType));
} catch (Exception e) {
log.warn("[pushMessageToAllUserTypes][向用户类型{}推送消息失败][messageId: {}][userType: {}]",
userType, wsMessage.getMessageId(), getUserTypeName(userType), e);
}
}
log.info("[pushMessageToAllUserTypes][推送完成][messageId: {}][成功: {}/{}]",
wsMessage.getMessageId(), successCount, totalCount);
}
/**
* 获取用户类型名称
*/
private String getUserTypeName(int userType) {
switch (userType) {
case 1: return "管理后台用户";
case 2: return "用户APP用户";
case 3: return "其他类型用户";
default: return "未知用户类型(" + userType + ")";
}
}
@Override
public void pushMessageToTenant(MessageCenterDO message, Long tenantId) {
log.info("[pushMessageToTenant][向租户推送消息][tenantId: {}][title: {}]", tenantId, message.getTitle());
// 转换为WebSocket消息格式
FarmWebSocketMessageVO wsMessage = convertToWebSocketMessage(message);
// 向指定租户的所有用户类型推送消息
pushMessageToAllUserTypes(wsMessage, tenantId);
}
@Override
public void pushSystemNotificationToTenant(String title, String content, Long tenantId) {
log.info("[pushSystemNotificationToTenant][向租户推送系统通知][tenantId: {}][title: {}]", tenantId, title);
// 创建消息中心记录
MessageCenterDO message = createMessageCenterRecord(
MessageTypeEnum.MESSAGE.getType(),
title,
content,
null,
null,
null,
null
);
// 向指定租户推送消息
pushMessageToTenant(message, tenantId);
}
@Override
public void pushSystemNotificationToAllTenants(String title, String content) {
log.info("[pushSystemNotificationToAllTenants][向所有租户推送系统通知][title: {}]", title);
// 创建消息中心记录
MessageCenterDO message = createMessageCenterRecord(
MessageTypeEnum.MESSAGE.getType(),
title,
content,
null,
null,
null,
null
);
// 向所有用户类型推送消息(不依赖租户)
pushMessageToAllUserTypes(message);
}
@Override
public void pushMessageToAllUserTypes(MessageCenterDO message) {
log.info("[pushMessageToAllUserTypes][向所有用户类型推送消息][title: {}]", message.getTitle());
// 转换为WebSocket消息格式
FarmWebSocketMessageVO wsMessage = convertToWebSocketMessage(message);
// 直接向所有用户类型推送,不依赖租户
pushMessageToAllUserTypesDirectly(wsMessage);
}
/**
* 直接向所有用户类型推送消息(不依赖租户)
*/
private void pushMessageToAllUserTypesDirectly(FarmWebSocketMessageVO wsMessage) {
log.info("[pushMessageToAllUserTypesDirectly][开始向所有用户类型推送消息][messageId: {}]",
wsMessage.getMessageId());
// 用户类型:1=管理后台用户,2=用户APP用户,3=其他类型用户
int successCount = 0;
int totalCount = 3;
for (int userType = 1; userType <= 3; userType++) {
try {
// 向指定用户类型的所有用户推送消息
webSocketMessageSender.send(userType, "farm", JsonUtils.toJsonString(wsMessage));
successCount++;
log.info("[pushMessageToAllUserTypesDirectly][向用户类型{}推送消息成功][messageId: {}][userType: {}]",
userType, wsMessage.getMessageId(), getUserTypeName(userType));
} catch (Exception e) {
log.warn("[pushMessageToAllUserTypesDirectly][向用户类型{}推送消息失败][messageId: {}][userType: {}]",
userType, wsMessage.getMessageId(), getUserTypeName(userType), e);
}
}
log.info("[pushMessageToAllUserTypesDirectly][推送完成][messageId: {}][成功: {}/{}]",
wsMessage.getMessageId(), successCount, totalCount);
}
/**
* 获取当前租户ID
*/
private Long getCurrentTenantId() {
try {
// 从当前登录用户获取租户ID
LoginUser currentUser = SecurityFrameworkUtils.getLoginUser();
if (currentUser != null && currentUser.getTenantId() != null) {
return currentUser.getTenantId();
}
// 从租户上下文获取
return TenantContextHolder.getTenantId();
} catch (Exception e) {
log.warn("[getCurrentTenantId][获取租户ID失败]", e);
return null;
}
}
}

View File

@@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.specieslibrary.vo.SpeciesTh
import cn.iocoder.yudao.module.farm.controller.admin.twodict.vo.TwoDictTreeRespVO;
import cn.iocoder.yudao.module.farm.dal.dataobject.modelmanagement.ModelManagementDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.specieslibrary.SpeciesLibraryDO;
import cn.iocoder.yudao.module.farm.dal.dataobject.twodict.TwoDictDO;
import cn.iocoder.yudao.module.farm.dal.mysql.modelmanagement.ModelManagementMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.specieslibrary.SpeciesLibraryMapper;
import cn.iocoder.yudao.module.farm.dal.mysql.sysDict.SysDictDO;
@@ -70,11 +71,10 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
speciesLibrary.setId(id);
speciesLibrary.setTenantId(String.valueOf(user.getTenantId()));
speciesLibrary.setCreateTime(LocalDateTime.now());
SysDictThreeLvRespVO dictByField2Code = sysDictService.getDictByField2Code(speciesLibrary.getCategory());
speciesLibrary.setSpeciesName(dictByField2Code.getNames());
TwoDictDO dictDO = twoDictService.getTwoDict(Long.valueOf(speciesLibrary.getCategory()));
TwoDictDO twoDict = twoDictService.getTwoDict(dictDO.getParentId());
speciesLibrary.setSpeciesName(twoDict.getName() + "/" + dictDO.getName());
speciesLibraryMapper.insert(speciesLibrary);
// 同步
this.syncCreateDict(id);
// 返回
return speciesLibrary.getId();
}
@@ -107,15 +107,12 @@ public class SpeciesLibraryServiceImpl implements SpeciesLibraryService {
public void updateSpeciesLibrary(SpeciesLibrarySaveReqVO updateReqVO) {
// 校验存在
validateSpeciesLibraryExists(updateReqVO.getId());
// 名称重复验证
SpeciesLibraryDO obj = speciesLibraryMapper.selectOne("cultivar_name", updateReqVO.getCultivarName());
if (ObjectUtils.isNotEmpty(obj)) {
return;
}
// 更新
SpeciesLibraryDO updateObj = BeanUtils.toBean(updateReqVO, SpeciesLibraryDO.class);
SysDictThreeLvRespVO dictByField2Code = sysDictService.getDictByField2Code(updateObj.getCategory());
updateObj.setSpeciesName(dictByField2Code.getNames());
TwoDictDO dictDO = twoDictService.getTwoDict(Long.valueOf(updateReqVO.getCategory()));
TwoDictDO twoDict = twoDictService.getTwoDict(dictDO.getParentId());
updateObj.setSpeciesName(twoDict.getName() + "/" + dictDO.getName());
speciesLibraryMapper.updateById(updateObj);
// 同步
this.syncUpdateDict(updateObj.getId());