diff --git a/bonus-admin/src/main/java/com/bonus/web/controller/enterprise/PerformanceController.java b/bonus-admin/src/main/java/com/bonus/web/controller/enterprise/PerformanceController.java new file mode 100644 index 0000000..e14b520 --- /dev/null +++ b/bonus-admin/src/main/java/com/bonus/web/controller/enterprise/PerformanceController.java @@ -0,0 +1,88 @@ +package com.bonus.web.controller.enterprise; + +import com.bonus.common.core.domain.AjaxResult; +import com.bonus.common.core.page.TableDataInfo; +import com.bonus.mainDataBase.domain.Performance; +import com.bonus.mainDataBase.service.PerformanceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 企业业绩控制器 + * 处理前端关于业绩的增删改查请求 + */ +@RestController +@RequestMapping("/performance") // 接口统一前缀 +public class PerformanceController { + + @Autowired + private PerformanceService performanceService; + + /** + * 查询业绩列表(带分页和条件筛选) + */ + @GetMapping("/list") + public TableDataInfo list(Performance performance) { + // 调用Service查询列表(实际项目中通常包含分页参数,由Service处理分页) + List list = performanceService.selectPerformanceList(performance); + // 封装分页结果(TableDataInfo为通用分页响应对象,包含总条数、列表数据等) + return new TableDataInfo(list, list.size()); + } + + /** + * 根据ID查询业绩详情 + */ + @GetMapping(value = "/{performanceId}") + public AjaxResult getInfo(@PathVariable("performanceId") Long performanceId) { + // 调用Service查询详情 + Performance performance = performanceService.selectPerformanceById(performanceId); + return AjaxResult.success(performance); // 封装成功响应,返回业绩数据 + } + + /** + * 新增业绩 + */ + @PostMapping(value = "/add") + public AjaxResult add(@Validated @RequestBody Performance performance) { + try { + // 调用Service新增,返回影响行数 + int rows = performanceService.insertPerformance(performance); + return rows > 0 ? AjaxResult.success("新增成功") : AjaxResult.error("新增失败"); + } catch (RuntimeException e) { + // 捕获业务异常(如项目名称重复),返回错误信息 + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 修改业绩 + */ + @PostMapping(value = "/edit") + public AjaxResult edit(@Validated @RequestBody Performance performance) { + try { + // 调用Service修改 + int rows = performanceService.updatePerformance(performance); + return rows > 0 ? AjaxResult.success("修改成功") : AjaxResult.error("修改失败"); + } catch (RuntimeException e) { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 删除业绩 + */ + @PostMapping("delete/{performanceId}") + public AjaxResult remove(@PathVariable Long performanceId) { + try { + int rows = performanceService.deletePerformanceById(performanceId); + return rows > 0 ? AjaxResult.success("删除成功") : AjaxResult.error("删除失败"); + } catch (RuntimeException e) { + return AjaxResult.error(e.getMessage()); + } + } + + +} diff --git a/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/domain/Performance.java b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/domain/Performance.java new file mode 100644 index 0000000..61f6507 --- /dev/null +++ b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/domain/Performance.java @@ -0,0 +1,125 @@ +package com.bonus.mainDataBase.domain; +import com.bonus.common.core.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +import java.util.Date; + +/** + * 企业业绩实体类 + * 对应表:tb_enterprise_performance + */ +@Data +public class Performance extends BaseEntity { + + private static final long serialVersionUID = 1L; + + /** + * 业绩id(主键) + */ + private Long performanceId; + + /** + * 企业id(关联企业表) + */ + private Long enterpriseId; + + /** + * 项目名称 + */ + private String proName; + + /** + * 合同签订时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date contractSigningTime; + + /** + * 合同金额 + */ + private String contractAmount; // 若需计算 + + /** + * 建设地点 + */ + private String constructionSite; + + /** + * 建设单位 + */ + private String constructionUnit; + + /** + * 建设单位联系方式 + */ + private String constructionPhone; + + /** + * 开工时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date startTime; + + /** + * 竣工时间 + */ + @JsonFormat(pattern = "yyyy-MM-dd") + private Date completionTime; + + /** + * 项目经理 + */ + private String projectManager; + + /** + * 项目类型(字典表配置) + */ + private String proType; + + /** + * 电压等级(字典表配置) + */ + private String voltageLevel; + + /** + * 项目概况 + */ + private String projectOverview; // 数据库为text类型,对应Java String + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 创建人id + */ + private Long createUserId; + + /** + * 创建人姓名 + */ + private String createUserName; + + /** + * 修改时间 + */ + private Date updateTime; + + /** + * 修改人id + */ + private Long updateUserId; + + /** + * 修改人姓名 + */ + private String updateUserName; + + /** + * 删除状态(0:未删除,1:删除) + */ + private String delFlag; +} + diff --git a/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/mapper/PerformanceMapper.java b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/mapper/PerformanceMapper.java new file mode 100644 index 0000000..a3d490a --- /dev/null +++ b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/mapper/PerformanceMapper.java @@ -0,0 +1,54 @@ +package com.bonus.mainDataBase.mapper; + +import com.bonus.mainDataBase.domain.Performance; + +import java.util.List; + +/** + * 企业业绩数据访问层接口 + * 对应表:tb_enterprise_performance + */ +public interface PerformanceMapper { + + /** + * 查询企业业绩列表(带条件筛选) + * @param enterprisePerformance 筛选条件(包含项目名称、企业ID等) + * @return 业绩列表 + */ + List selectperformanceList(Performance enterprisePerformance); + + /** + * 根据业绩ID查询详情 + * @param performanceId 业绩主键ID + * @return 企业业绩对象 + */ + Performance selectperformanceById(Long performanceId); + + /** + * 校验项目名称唯一性 + * @param enterprisePerformance 包含项目名称和业绩ID(编辑时用于排除自身) + * @return 存在数量(0:不存在,1:存在) + */ + int checkProNameUnique(Performance enterprisePerformance); + + /** + * 新增企业业绩 + * @param enterprisePerformance 企业业绩对象 + * @return 影响行数 + */ + int insertperformance(Performance enterprisePerformance); + + /** + * 编辑企业业绩 + * @param enterprisePerformance 企业业绩对象(包含更新字段和主键) + * @return 影响行数 + */ + int updateperformance(Performance enterprisePerformance); + + /** + * 逻辑删除企业业绩(更新del_flag为1) + * @param performanceId 业绩主键ID + * @return 影响行数 + */ + int deleteperformanceById(Long performanceId); +} diff --git a/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/PerformanceService.java b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/PerformanceService.java new file mode 100644 index 0000000..d2354b5 --- /dev/null +++ b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/PerformanceService.java @@ -0,0 +1,53 @@ +package com.bonus.mainDataBase.service; + +import com.bonus.mainDataBase.domain.Performance; + +import java.util.List; + +/** + * 企业业绩服务层接口 + */ +public interface PerformanceService { + + /** + * 查询企业业绩列表(带条件筛选) + * @param performance 筛选条件 + * @return 业绩列表 + */ + List selectPerformanceList(Performance performance); + + /** + * 根据ID查询业绩详情 + * @param performanceId 业绩ID + * @return 业绩对象 + */ + Performance selectPerformanceById(Long performanceId); + + /** + * 新增业绩 + * @param performance 业绩对象 + * @return 结果(1:成功,0:失败) + */ + int insertPerformance(Performance performance); + + /** + * 修改业绩 + * @param performance 业绩对象 + * @return 结果(1:成功,0:失败) + */ + int updatePerformance(Performance performance); + + /** + * 逻辑删除业绩 + * @param performanceId 业绩ID + * @return 结果(1:成功,0:失败) + */ + int deletePerformanceById(Long performanceId); + + /** + * 校验项目名称是否唯一 + * @param performance 业绩对象(含项目名称和ID) + * @return 结果(true:唯一,false:不唯一) + */ + boolean checkProNameUnique(Performance performance); +} diff --git a/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/impl/PerformanceServiceImpl.java b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/impl/PerformanceServiceImpl.java new file mode 100644 index 0000000..68016e7 --- /dev/null +++ b/bonus-mainDatabase/src/main/java/com/bonus/mainDataBase/service/impl/PerformanceServiceImpl.java @@ -0,0 +1,113 @@ +package com.bonus.mainDataBase.service.impl; + +import com.bonus.mainDataBase.domain.Performance; +import com.bonus.mainDataBase.mapper.PerformanceMapper; +import com.bonus.mainDataBase.service.PerformanceService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +/** + * 企业业绩服务层实现类 + */ +@Service +public class PerformanceServiceImpl implements PerformanceService { + + @Autowired + private PerformanceMapper performanceMapper; + + /** + * 查询业绩列表 + */ + @Override + public List selectPerformanceList(Performance performance) { + // 调用Mapper查询,返回结果 + return performanceMapper.selectperformanceList(performance); + } + + /** + * 根据ID查询业绩详情 + */ + @Override + public Performance selectPerformanceById(Long performanceId) { + // 校验ID是否为空 + if (performanceId == null || performanceId <= 0) { + throw new IllegalArgumentException("业绩ID不能为空或无效"); + } + return performanceMapper.selectperformanceById(performanceId); + } + + /** + * 新增业绩 + */ + @Override + @Transactional // 事务控制:确保新增操作要么全成,要么全失败 + public int insertPerformance(Performance performance) { + // 1. 校验项目名称唯一性 + if (!checkProNameUnique(performance)) { + throw new RuntimeException("项目名称已存在,请更换"); + } + + // 2. 补充默认值(如创建人、创建时间,若前端未传) + // 示例:若需自动填充创建人,可从上下文获取当前登录用户ID和名称 + // performance.setCreateUserId(getCurrentUserId()); + // performance.setCreateUserName(getCurrentUserName()); + + // 3. 调用Mapper执行新增 + return performanceMapper.insertperformance(performance); + } + + /** + * 修改业绩 + */ + @Override + @Transactional + public int updatePerformance(Performance performance) { + // 1. 校验ID是否存在 + Performance oldPerformance = selectPerformanceById(performance.getPerformanceId()); + if (oldPerformance == null) { + throw new RuntimeException("业绩信息不存在或已删除"); + } + + // 2. 校验项目名称唯一性(排除自身) + if (!checkProNameUnique(performance)) { + throw new RuntimeException("项目名称已存在,请更换"); + } + + // 3. 补充修改人信息(如从上下文获取) + // performance.setUpdateUserId(getCurrentUserId()); + // performance.setUpdateUserName(getCurrentUserName()); + + // 4. 调用Mapper执行更新 + return performanceMapper.updateperformance(performance); + } + + /** + * 逻辑删除业绩 + */ + @Override + @Transactional + public int deletePerformanceById(Long performanceId) { + // 1. 校验ID是否存在 + Performance performance = selectPerformanceById(performanceId); + if (performance == null) { + throw new RuntimeException("业绩信息不存在或已删除"); + } + + // 2. 调用Mapper执行逻辑删除 + return performanceMapper.deleteperformanceById(performanceId); + } + + /** + * 校验项目名称是否唯一 + */ + @Override + public boolean checkProNameUnique(Performance performance) { + // 调用Mapper查询同名记录数量 + int count = performanceMapper.checkProNameUnique(performance); + // count == 0 表示唯一 + return count == 0; + } +} diff --git a/bonus-mainDatabase/src/main/resources/mapper/PerformanceMapper.xml b/bonus-mainDatabase/src/main/resources/mapper/PerformanceMapper.xml new file mode 100644 index 0000000..5fbe97c --- /dev/null +++ b/bonus-mainDatabase/src/main/resources/mapper/PerformanceMapper.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + select + performance_id, enterprise_id, pro_name, contract_signing_time, + contract_amount, construction_site, construction_unit, construction_phone, + start_time, completion_time, project_manager, pro_type, voltage_level, + project_overview, create_time, create_user_id, create_user_name, + update_time, update_user_id, update_user_name, del_flag + from tb_enterprise_performance + where del_flag = '0' + + + + + + + + + + + + + + insert into tb_enterprise_performance( + enterprise_id, pro_name, contract_signing_time, contract_amount, + construction_site, construction_unit, construction_phone, start_time, + completion_time, project_manager, pro_type, voltage_level, project_overview, + create_user_id, create_user_name, create_time + )values( + #{enterpriseId}, #{proName}, #{contractSigningTime}, #{contractAmount}, + #{constructionSite}, #{constructionUnit}, #{constructionPhone}, #{startTime}, + #{completionTime}, #{projectManager}, #{proType}, #{voltageLevel}, #{projectOverview}, + #{createUserId}, #{createUserName}, sysdate() + ) + + + + + update tb_enterprise_performance + + enterprise_id = #{enterpriseId}, + pro_name = #{proName}, + contract_signing_time = #{contractSigningTime}, + contract_amount = #{contractAmount}, + construction_site = #{constructionSite}, + construction_unit = #{constructionUnit}, + construction_phone = #{constructionPhone}, + start_time = #{startTime}, + completion_time = #{completionTime}, + project_manager = #{projectManager}, + pro_type = #{proType}, + voltage_level = #{voltageLevel}, + project_overview = #{projectOverview}, + update_user_id = #{updateUserId}, + update_user_name = #{updateUserName}, + update_time = sysdate() -- 自动更新修改时间 + + where performance_id = #{performanceId} + + + + + update tb_enterprise_performance + set del_flag = '1', -- 标记为删除 + update_time = sysdate() + where performance_id = #{performanceId} + + +