pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectGroupMapper.java
@@ -25,4 +25,11 @@ int updateByPrimaryKey(IrProjectGroup record); /** * 解绑项目与轮罐组关联 * @param projectId * @return */ Integer unbindGroup(Long projectId); } pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoIr/IrProjectMapper.java
@@ -3,6 +3,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.dy.pipIrrGlobal.pojoIr.IrProject; import com.dy.pipIrrGlobal.voIr.VoProject; import com.dy.pipIrrGlobal.voIr.VoProjectDetail; import com.dy.pipIrrGlobal.voIr.VoProjectOne; import com.dy.pipIrrGlobal.voIr.VoProjectSimple; import org.apache.ibatis.annotations.Mapper; @@ -79,4 +80,11 @@ * @return */ List<VoProjectSimple> getSimpleProjects(Map<?, ?> params); /** * 根据项目Id获取项目详情,编辑项目信息使用 * @param projectId * @return */ VoProjectDetail getProjectDetail(Long projectId); } pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/voIr/VoProjectDetail.java
New file @@ -0,0 +1,27 @@ package com.dy.pipIrrGlobal.voIr; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Data; /** * @author ZhuBaoMin * @date 2025-03-28 8:49 * @LastEditTime 2025-03-28 8:49 * @Description 灌溉项目详情视图对象 */ @Data @JsonPropertyOrder({"projectName", "irrigateGroups"}) public class VoProjectDetail { public static final long serialVersionUID = 202503280850001L; /** * 项目名称 */ private String projectName; /** * 灌溉组列表 */ private String irrigateGroups; } pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectGroupMapper.xml
@@ -88,4 +88,9 @@ sort = #{sort,jdbcType=INTEGER} where id = #{id,jdbcType=BIGINT} </update> <!--解绑项目与轮罐组关联--> <delete id="unbindGroup"> delete from ir_project_group where project_id=#{projectId} </delete> </mapper> pipIrr-platform/pipIrr-global/src/main/resources/mapper/IrProjectMapper.xml
@@ -308,4 +308,22 @@ </if> </trim> </select> <!--根据项目Id获取项目详情,编辑项目信息使用--> <select id="getProjectDetail" resultType="com.dy.pipIrrGlobal.voIr.VoProjectDetail"> SELECT projectName, GROUP_CONCAT(groupId) AS irrigateGroups FROM ( SELECT pro.project_name AS projectName, grp.id AS groupId FROM ir_project pro INNER JOIN ir_project_group pg ON pg.project_id = pro.id INNER JOIN ir_irrigate_group grp ON grp.id = pg.group_id WHERE pro.id = #{projectId} ) project GROUP BY projectName </select> </mapper> pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/PipIrrIrrigateApplication.java
@@ -9,7 +9,7 @@ import org.springframework.context.annotation.FilterType; @SpringBootApplication @EnableAspectJAutoProxy @EnableAspectJAutoProxy(exposeProxy = true) @EnableMultiDataSource @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.pipIrrIrrigate"}, excludeFilters = { pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectCtrl.java
@@ -7,10 +7,11 @@ import com.dy.common.webUtil.ResultCodeMsg; import com.dy.pipIrrGlobal.pojoIr.IrProject; import com.dy.pipIrrGlobal.voIr.VoProject; import com.dy.pipIrrGlobal.voIr.VoProjectDetail; import com.dy.pipIrrGlobal.voIr.VoProjectOne; import com.dy.pipIrrGlobal.voIr.VoProjectSimple; import com.dy.pipIrrGlobal.voSe.VoActiveCard; import com.dy.pipIrrIrrigate.project.dto.irrigateProject; import com.dy.pipIrrIrrigate.project.dto.IrrigateProject; import com.dy.pipIrrIrrigate.result.IrrigateResultCode; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -26,7 +27,10 @@ import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import java.util.*; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; /** * @author :WuZeYu @@ -77,45 +81,7 @@ } /** * 添加项目,新版本,使用这个 * @param po 项目实体对象 * @param bindingResult * @return 添加是否成功 */ @PostMapping(path = "addIrrigateProject", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> addIrrigateProject(@RequestBody @Valid irrigateProject po, BindingResult bindingResult) { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } String projectName = po.getProjectName(); String irrigateGroups = po.getIrrigateGroups(); Long operatorId = po.getOperatorId(); IrProject irProject = new IrProject(); irProject.setProjectName(projectName); irProject.setProjectState((byte)1); irProject.setOperator(operatorId); irProject.setOperateTime(new Date()); irProject.setDeleted((byte)0); Long projectId = projectSv.addIrrigateProject(irProject); if(projectId == null) { return BaseResponseUtils.buildErrorMsg("创建灌溉项目失败"); } //String[] irrigateGroupArr = irrigateGroups.split(","); //for(Long irrigateGroupId : irrigateGroupArr) { // //} return BaseResponseUtils.buildSuccess(true); } /** * 逻辑删除项目 * 逻辑删除项目,旧版本,原则上废弃 * @param map * @return */ @@ -177,7 +143,7 @@ } /** * 修改项目信息 * 修改项目信息,旧版本,原则上废弃 * @param po * @param bindingResult * @return @@ -211,7 +177,7 @@ } /** * 修改项目状态 * 修改项目状态,无用接口,原则上废弃 * @param po * @param * @return @@ -242,8 +208,7 @@ } /** * 获取一个项目数据 * * 获取一个项目数据,旧版本,原则上废弃 * @return 获取一个项目数据 */ @Operation(summary = "获取一个项目数据", description = "获取一个项目数据") @@ -291,6 +256,108 @@ } /** * 添加项目,新版本,使用这个 * @param po 项目实体对象 * @param bindingResult * @return 添加是否成功 */ @PostMapping(path = "addIrrigateProject", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> addIrrigateProject(@RequestBody @Valid IrrigateProject po, BindingResult bindingResult) { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } Map map_result = projectSv.addIrrigateProject(po); if(map_result.get("success").equals(false)) { return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); } return BaseResponseUtils.buildSuccess() ; //String projectName = po.getProjectName(); //String irrigateGroups = po.getIrrigateGroups(); //Long operatorId = po.getOperatorId(); // //IrProject irProject = new IrProject(); //irProject.setProjectName(projectName); //irProject.setProjectState((byte)1); //irProject.setOperator(operatorId); //irProject.setOperateTime(new Date()); //irProject.setDeleted((byte)0); //Long projectId = projectSv.addIrrigateProject(irProject); //if(projectId == null) { // return BaseResponseUtils.buildErrorMsg("创建灌溉项目失败"); //} // //String[] irrigateGroupArr = irrigateGroups.split(","); //Integer sort = 1; //for(String irrigateGroupId : irrigateGroupArr) { // String trimmed = irrigateGroupId.trim(); // if(trimmed.isEmpty()) { // continue; // } // try { // Long irrigateGroupIdLong = Long.parseLong(trimmed); // IrProjectGroup irProjectGroup = new IrProjectGroup(); // irProjectGroup.setProjectId(projectId); // irProjectGroup.setGroupId(irrigateGroupIdLong); // irProjectGroup.setSort(sort++); // projectSv.projectBindGroup(irProjectGroup); // // } catch (NumberFormatException e) { // return BaseResponseUtils.buildErrorMsg("灌溉组ID格式错误"); // } //} } /** * 删除项目,新版本,使用这个 * @param projectId * @return */ @PostMapping(path = "deleteIrrigateProject") @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> deleteIrrigateProject(@RequestParam(required = false) Long projectId) { if(projectId == null) { return BaseResponseUtils.buildErrorMsg("项目ID不能为空"); } Map map_result = projectSv.deleteIrrigateProject(projectId); if(map_result.get("success").equals(false)) { return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); } return BaseResponseUtils.buildSuccess() ; } /** * 修改项目,新版本,使用这个 * @param po * @param bindingResult * @return */ @PostMapping(path = "updateIrrigateProject", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() public BaseResponse<Boolean> updateIrrigateProject(@RequestBody @Valid IrrigateProject po, BindingResult bindingResult){ if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } if(po.getProjectId() == null) { return BaseResponseUtils.buildErrorMsg("项目ID不能为空"); } Map map_result = projectSv.updateIrrigateProject(po); if(map_result.get("success").equals(false)) { return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); } return BaseResponseUtils.buildSuccess() ; } /** * 分页查询项目,新版本,目前使用 * @param qo * @return @@ -307,4 +374,22 @@ } } /** * 根据项目Id获取项目详情,编辑项目信息使用 * @param projectId * @return */ @GetMapping(path = "getProject") @SsoAop() public BaseResponse<VoProjectDetail> getProject(@RequestParam Long projectId) { if(projectId == null) { return BaseResponseUtils.buildErrorMsg("项目ID不能为空"); } Map map_result = projectSv.getProjectDetail(projectId); if(map_result.get("success").equals(false)) { return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString()); } return BaseResponseUtils.buildSuccess(map_result.get("content")) ; } } pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/ProjectSv.java
@@ -2,17 +2,24 @@ import com.dy.common.webUtil.QueryResultVo; import com.dy.pipIrrGlobal.daoIr.IrProjectGroupMapper; import com.dy.pipIrrGlobal.daoIr.IrProjectMapper; import com.dy.pipIrrGlobal.pojoIr.IrProject; import com.dy.pipIrrGlobal.pojoIr.IrProjectGroup; import com.dy.pipIrrGlobal.voIr.VoProject; import com.dy.pipIrrGlobal.voIr.VoProjectDetail; import com.dy.pipIrrGlobal.voIr.VoProjectOne; import com.dy.pipIrrGlobal.voIr.VoProjectSimple; import com.dy.pipIrrIrrigate.project.dto.IrrigateProject; import lombok.extern.slf4j.Slf4j; import org.apache.dubbo.common.utils.PojoUtils; import org.springframework.aop.framework.AopContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -27,6 +34,9 @@ public class ProjectSv { @Autowired private IrProjectMapper irProjectMapper; @Autowired private IrProjectGroupMapper irProjectGroupMapper; /** * 添加项目,旧版本,原则上废弃 @@ -66,14 +76,117 @@ * @param po * @return */ public Long addIrrigateProject(IrProject po) { irProjectMapper.insert(po); return po.getId(); @Transactional(rollbackFor = Exception.class) public Map addIrrigateProject(IrrigateProject po) { String projectName = po.getProjectName(); String irrigateGroups = po.getIrrigateGroups(); Long operatorId = po.getOperatorId(); IrProject irProject = new IrProject(); irProject.setProjectName(projectName); irProject.setProjectState((byte)1); irProject.setOperator(operatorId); irProject.setOperateTime(new Date()); irProject.setDeleted((byte)0); irProjectMapper.insert(irProject); Long projectId = irProject.getId(); if(projectId == null) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "创建灌溉项目失败"); map.put("content", null); return map; } String[] irrigateGroupArr = irrigateGroups.split(","); Integer sort = 1; for(String irrigateGroupId : irrigateGroupArr) { String trimmed = irrigateGroupId.trim(); if(trimmed.isEmpty()) { continue; } try { Long irrigateGroupIdLong = Long.parseLong(trimmed); IrProjectGroup irProjectGroup = new IrProjectGroup(); irProjectGroup.setProjectId(projectId); irProjectGroup.setGroupId(irrigateGroupIdLong); irProjectGroup.setSort(sort++); irProjectGroupMapper.insert(irProjectGroup); } catch (NumberFormatException e) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "灌溉组ID格式错误"); map.put("content", null); return map; } } Map map = new HashMap<>(); map.put("success", true); map.put("msg", "添加灌溉项目成功"); map.put("content", null); return map; } /** * 删除项目 * * 删除灌溉项目,目前使用 * @param projectId * @return */ @Transactional(rollbackFor = Exception.class) public Map deleteIrrigateProject(Long projectId) { try { irProjectGroupMapper.unbindGroup(projectId); irProjectMapper.deleteByPrimaryKey(projectId); Map map = new HashMap<>(); map.put("success", true); map.put("msg", "灌溉项目删除成功"); map.put("content", null); return map; } catch (Exception e) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "灌溉项目删除失败"); map.put("content", null); return map; } } /** * 修改灌溉项目,目前使用 * @param po * @return */ @Transactional(rollbackFor = Exception.class) public Map updateIrrigateProject(IrrigateProject po) { Long projectId = po.getProjectId(); Map map_deleteProject = ((ProjectSv) AopContext.currentProxy()).deleteIrrigateProject(projectId); if(map_deleteProject.get("success").equals(false)) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", map_deleteProject.get("msg").toString()); map.put("content", null); return map; } Map map_addProject = ((ProjectSv) AopContext.currentProxy()).addIrrigateProject(po); if(map_addProject.get("success").equals(false)) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", map_addProject.get("msg").toString()); map.put("content", null); return map; } Map map = new HashMap<>(); map.put("success", true); map.put("msg", "修改灌溉项目成功"); map.put("content", null); return map; } /** * 删除项目,旧版本,原则上废弃 * @param id */ public Integer deleteProject(Long id) { @@ -173,4 +286,26 @@ rsVo.obj = irProjectMapper.getSimpleProjects(params); return rsVo; } /** * 根据项目Id获取项目详情,编辑项目信息使用 * @param projectId * @return */ public Map getProjectDetail(Long projectId) { try { VoProjectDetail voProjectDetail = irProjectMapper.getProjectDetail(projectId); Map map = new HashMap<>(); map.put("success", true); map.put("msg", "获取项目详情成功"); map.put("content", voProjectDetail); return map; } catch (Exception e) { Map map = new HashMap<>(); map.put("success", false); map.put("msg", "获取项目详情失败"); map.put("content", null); return map; } } } pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/dto/IrrigateProject.java
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/project/dto/irrigateProject.java @@ -12,10 +12,15 @@ */ @Data public class irrigateProject { public class IrrigateProject { public static final long serialVersionUID = 202503271510001L; /** * 项目ID,修改项目信息时需要传入 */ private Long projectId; /** * 项目名称 */ @NotBlank(message = "项目名称不能为空")