feat: 客户管理和项目管理模块完善更新接口

## 客户管理模块
- CustomerUpdateDTO: 客户更新DTO
- CustomerService: 新增updateCustomer方法
- CustomerServiceImpl: 实现客户更新逻辑
- CustomerController: 新增PUT /api/v1/customer/{id}接口

## 项目管理模块
- ProjectUpdateDTO: 项目更新DTO
- ProjectService: 新增updateProject方法
- ProjectServiceImpl: 实现项目更新逻辑
- ProjectController: 新增PUT /api/v1/project/{id}接口

## 功能特性
- 更新时检查编码唯一性(排除自身)
- 支持状态更新
- 自动记录更新人和更新时间
This commit is contained in:
zhangjf 2026-02-17 15:41:58 +08:00
parent 075525d577
commit 6d06a361fe
8 changed files with 303 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fundplatform.common.core.PageResult;
import com.fundplatform.common.core.Result;
import com.fundplatform.cust.dto.CustomerCreateDTO;
import com.fundplatform.cust.dto.CustomerUpdateDTO;
import com.fundplatform.cust.service.CustomerService;
import com.fundplatform.cust.vo.CustomerVO;
import jakarta.validation.Valid;
@ -31,6 +32,15 @@ public class CustomerController {
return Result.success(id);
}
/**
* 更新客户
*/
@PutMapping("/{id}")
public Result<Void> updateCustomer(@PathVariable Long id, @Valid @RequestBody CustomerUpdateDTO dto) {
customerService.updateCustomer(id, dto);
return Result.success();
}
/**
* 查询客户详情
*/

View File

@ -0,0 +1,91 @@
package com.fundplatform.cust.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
/**
* 客户更新DTO
*/
public class CustomerUpdateDTO {
@NotBlank(message = "客户编码不能为空")
private String customerCode;
@NotBlank(message = "客户名称不能为空")
private String customerName;
@NotBlank(message = "联系人不能为空")
private String contact;
@Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
private String phone;
private String email;
private String address;
private Integer status;
private String remark;
public String getCustomerCode() {
return customerCode;
}
public void setCustomerCode(String customerCode) {
this.customerCode = customerCode;
}
public String getCustomerName() {
return customerName;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -2,6 +2,7 @@ package com.fundplatform.cust.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fundplatform.cust.dto.CustomerCreateDTO;
import com.fundplatform.cust.dto.CustomerUpdateDTO;
import com.fundplatform.cust.vo.CustomerVO;
/**
@ -14,6 +15,11 @@ public interface CustomerService {
*/
Long createCustomer(CustomerCreateDTO dto);
/**
* 更新客户
*/
void updateCustomer(Long id, CustomerUpdateDTO dto);
/**
* 查询客户详情
*/

View File

@ -7,6 +7,7 @@ import com.fundplatform.common.context.UserContextHolder;
import com.fundplatform.cust.data.entity.Customer;
import com.fundplatform.cust.data.service.CustomerDataService;
import com.fundplatform.cust.dto.CustomerCreateDTO;
import com.fundplatform.cust.dto.CustomerUpdateDTO;
import com.fundplatform.cust.service.CustomerService;
import com.fundplatform.cust.vo.CustomerVO;
import org.springframework.stereotype.Service;
@ -50,6 +51,38 @@ public class CustomerServiceImpl implements CustomerService {
return customer.getId();
}
@Override
public void updateCustomer(Long id, CustomerUpdateDTO dto) {
Customer customer = customerDataService.getById(id);
if (customer == null) {
throw new RuntimeException("客户不存在");
}
// 检查编码是否重复排除自身
if (!customer.getCustomerCode().equals(dto.getCustomerCode())) {
LambdaQueryWrapper<Customer> checkWrapper = new LambdaQueryWrapper<>();
checkWrapper.eq(Customer::getCustomerCode, dto.getCustomerCode())
.ne(Customer::getId, id);
if (customerDataService.count(checkWrapper) > 0) {
throw new RuntimeException("客户编码已存在");
}
}
customer.setCustomerCode(dto.getCustomerCode());
customer.setCustomerName(dto.getCustomerName());
customer.setContact(dto.getContact());
customer.setPhone(dto.getPhone());
customer.setEmail(dto.getEmail());
customer.setAddress(dto.getAddress());
if (dto.getStatus() != null) {
customer.setStatus(dto.getStatus());
}
customer.setRemark(dto.getRemark());
customer.setUpdatedBy(UserContextHolder.getUserId());
customerDataService.updateById(customer);
}
@Override
public CustomerVO getCustomerById(Long id) {
Customer customer = customerDataService.getById(id);

View File

@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fundplatform.common.core.PageResult;
import com.fundplatform.common.core.Result;
import com.fundplatform.proj.dto.ProjectCreateDTO;
import com.fundplatform.proj.dto.ProjectUpdateDTO;
import com.fundplatform.proj.service.ProjectService;
import com.fundplatform.proj.vo.ProjectVO;
import jakarta.validation.Valid;
@ -31,6 +32,15 @@ public class ProjectController {
return Result.success(id);
}
/**
* 更新项目
*/
@PutMapping("/{id}")
public Result<Void> updateProject(@PathVariable Long id, @Valid @RequestBody ProjectUpdateDTO dto) {
projectService.updateProject(id, dto);
return Result.success();
}
/**
* 查询项目详情
*/

View File

@ -0,0 +1,112 @@
package com.fundplatform.proj.dto;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDate;
/**
* 项目更新DTO
*/
public class ProjectUpdateDTO {
@NotBlank(message = "项目编码不能为空")
private String projectCode;
@NotBlank(message = "项目名称不能为空")
private String projectName;
@NotNull(message = "客户ID不能为空")
private Long customerId;
@NotBlank(message = "项目类型不能为空")
private String projectType;
private BigDecimal budgetAmount;
private LocalDate startDate;
private LocalDate endDate;
private String projectManager;
private Integer status;
private String remark;
public String getProjectCode() {
return projectCode;
}
public void setProjectCode(String projectCode) {
this.projectCode = projectCode;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public Long getCustomerId() {
return customerId;
}
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
public String getProjectType() {
return projectType;
}
public void setProjectType(String projectType) {
this.projectType = projectType;
}
public BigDecimal getBudgetAmount() {
return budgetAmount;
}
public void setBudgetAmount(BigDecimal budgetAmount) {
this.budgetAmount = budgetAmount;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}
public String getProjectManager() {
return projectManager;
}
public void setProjectManager(String projectManager) {
this.projectManager = projectManager;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

View File

@ -2,6 +2,7 @@ package com.fundplatform.proj.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fundplatform.proj.dto.ProjectCreateDTO;
import com.fundplatform.proj.dto.ProjectUpdateDTO;
import com.fundplatform.proj.vo.ProjectVO;
/**
@ -14,6 +15,11 @@ public interface ProjectService {
*/
Long createProject(ProjectCreateDTO dto);
/**
* 更新项目
*/
void updateProject(Long id, ProjectUpdateDTO dto);
/**
* 查询项目详情
*/

View File

@ -7,6 +7,7 @@ import com.fundplatform.common.context.UserContextHolder;
import com.fundplatform.proj.data.entity.Project;
import com.fundplatform.proj.data.service.ProjectDataService;
import com.fundplatform.proj.dto.ProjectCreateDTO;
import com.fundplatform.proj.dto.ProjectUpdateDTO;
import com.fundplatform.proj.service.ProjectService;
import com.fundplatform.proj.vo.ProjectVO;
import org.springframework.stereotype.Service;
@ -52,6 +53,40 @@ public class ProjectServiceImpl implements ProjectService {
return project.getId();
}
@Override
public void updateProject(Long id, ProjectUpdateDTO dto) {
Project project = projectDataService.getById(id);
if (project == null) {
throw new RuntimeException("项目不存在");
}
// 检查编码是否重复排除自身
if (!project.getProjectCode().equals(dto.getProjectCode())) {
LambdaQueryWrapper<Project> checkWrapper = new LambdaQueryWrapper<>();
checkWrapper.eq(Project::getProjectCode, dto.getProjectCode())
.ne(Project::getId, id);
if (projectDataService.count(checkWrapper) > 0) {
throw new RuntimeException("项目编码已存在");
}
}
project.setProjectCode(dto.getProjectCode());
project.setProjectName(dto.getProjectName());
project.setCustomerId(dto.getCustomerId());
project.setProjectType(dto.getProjectType());
project.setBudgetAmount(dto.getBudgetAmount());
project.setStartDate(dto.getStartDate());
project.setEndDate(dto.getEndDate());
project.setProjectManager(dto.getProjectManager());
if (dto.getStatus() != null) {
project.setStatus(dto.getStatus());
}
project.setRemark(dto.getRemark());
project.setUpdatedBy(UserContextHolder.getUserId());
projectDataService.updateById(project);
}
@Override
public ProjectVO getProjectById(Long id) {
Project project = projectDataService.getById(id);