diff --git a/fund-cust/src/main/java/com/fundplatform/cust/controller/CustomerController.java b/fund-cust/src/main/java/com/fundplatform/cust/controller/CustomerController.java index 62e6354..0f846ad 100644 --- a/fund-cust/src/main/java/com/fundplatform/cust/controller/CustomerController.java +++ b/fund-cust/src/main/java/com/fundplatform/cust/controller/CustomerController.java @@ -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 updateCustomer(@PathVariable Long id, @Valid @RequestBody CustomerUpdateDTO dto) { + customerService.updateCustomer(id, dto); + return Result.success(); + } + /** * 查询客户详情 */ diff --git a/fund-cust/src/main/java/com/fundplatform/cust/dto/CustomerUpdateDTO.java b/fund-cust/src/main/java/com/fundplatform/cust/dto/CustomerUpdateDTO.java new file mode 100644 index 0000000..e4b7a9e --- /dev/null +++ b/fund-cust/src/main/java/com/fundplatform/cust/dto/CustomerUpdateDTO.java @@ -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; + } +} diff --git a/fund-cust/src/main/java/com/fundplatform/cust/service/CustomerService.java b/fund-cust/src/main/java/com/fundplatform/cust/service/CustomerService.java index d785941..c60cbc8 100644 --- a/fund-cust/src/main/java/com/fundplatform/cust/service/CustomerService.java +++ b/fund-cust/src/main/java/com/fundplatform/cust/service/CustomerService.java @@ -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); + /** * 查询客户详情 */ diff --git a/fund-cust/src/main/java/com/fundplatform/cust/service/impl/CustomerServiceImpl.java b/fund-cust/src/main/java/com/fundplatform/cust/service/impl/CustomerServiceImpl.java index bde7b1d..fc28f28 100644 --- a/fund-cust/src/main/java/com/fundplatform/cust/service/impl/CustomerServiceImpl.java +++ b/fund-cust/src/main/java/com/fundplatform/cust/service/impl/CustomerServiceImpl.java @@ -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 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); diff --git a/fund-proj/src/main/java/com/fundplatform/proj/controller/ProjectController.java b/fund-proj/src/main/java/com/fundplatform/proj/controller/ProjectController.java index 5aef648..bef002a 100644 --- a/fund-proj/src/main/java/com/fundplatform/proj/controller/ProjectController.java +++ b/fund-proj/src/main/java/com/fundplatform/proj/controller/ProjectController.java @@ -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 updateProject(@PathVariable Long id, @Valid @RequestBody ProjectUpdateDTO dto) { + projectService.updateProject(id, dto); + return Result.success(); + } + /** * 查询项目详情 */ diff --git a/fund-proj/src/main/java/com/fundplatform/proj/dto/ProjectUpdateDTO.java b/fund-proj/src/main/java/com/fundplatform/proj/dto/ProjectUpdateDTO.java new file mode 100644 index 0000000..9fa74a5 --- /dev/null +++ b/fund-proj/src/main/java/com/fundplatform/proj/dto/ProjectUpdateDTO.java @@ -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; + } +} diff --git a/fund-proj/src/main/java/com/fundplatform/proj/service/ProjectService.java b/fund-proj/src/main/java/com/fundplatform/proj/service/ProjectService.java index 0999e70..af1cac7 100644 --- a/fund-proj/src/main/java/com/fundplatform/proj/service/ProjectService.java +++ b/fund-proj/src/main/java/com/fundplatform/proj/service/ProjectService.java @@ -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); + /** * 查询项目详情 */ diff --git a/fund-proj/src/main/java/com/fundplatform/proj/service/impl/ProjectServiceImpl.java b/fund-proj/src/main/java/com/fundplatform/proj/service/impl/ProjectServiceImpl.java index 4c93edc..45008b3 100644 --- a/fund-proj/src/main/java/com/fundplatform/proj/service/impl/ProjectServiceImpl.java +++ b/fund-proj/src/main/java/com/fundplatform/proj/service/impl/ProjectServiceImpl.java @@ -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 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);