diff --git a/src/main/java/cn/palmte/work/controller/backend/ProcessController.java b/src/main/java/cn/palmte/work/controller/backend/ProcessController.java index b218cf9..7da5c09 100644 --- a/src/main/java/cn/palmte/work/controller/backend/ProcessController.java +++ b/src/main/java/cn/palmte/work/controller/backend/ProcessController.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import java.math.BigDecimal; import java.sql.PreparedStatement; import java.sql.SQLException; import java.time.LocalDate; @@ -22,13 +23,19 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import cn.palmte.work.model.Admin; import cn.palmte.work.model.DeptRepository; import cn.palmte.work.model.Project; import cn.palmte.work.model.ProjectBudgetIncomeDetail; import cn.palmte.work.model.ProjectRepository; +import cn.palmte.work.model.enums.CooperationType; +import cn.palmte.work.model.enums.Enumerable; import cn.palmte.work.model.enums.ProcessStatus; +import cn.palmte.work.model.enums.ProjectType; import cn.palmte.work.model.enums.SealType; import cn.palmte.work.service.ProjectBudgetService; +import cn.palmte.work.utils.InterfaceUtil; +import lombok.Builder; import lombok.Setter; /** @@ -113,32 +120,53 @@ public class ProcessController { .collect(Collectors.toList()); } + @Builder public static class ProjectReturnValue { public final String applyDate = LocalDate.now().format(formatter); public String projectNo; public Integer projectId; + public String projectName; // 申请人 public String applyPersonName; // 项目类型 public String projectType; + // 合作类型 public String cooperationType; // 合同金额 - public String contractAmount; + public BigDecimal contractAmount; + // FIXME 垫资 + // 是否垫资 + public final String isPrepaid = "是"; + + // 垫资金额 + public final String repaidAmount = "50000元"; + + // 预算毛利率 + public final String budgetGrossMargin = "3.9%"; } @ResponseBody @GetMapping("/projects/{id}") - public Project query(@PathVariable int id) { - Project byId = projectRepository.findById(id); + public ProjectReturnValue query(@PathVariable int id) { + Project project = projectRepository.findById(id); + Admin admin = InterfaceUtil.getAdmin(); - // projectType - // cooperationType - return byId; + // 可以在对应表数据查询 是否存在再启用 + + return ProjectReturnValue.builder() + .projectId(project.getId()) + .projectName(project.getName()) + .projectNo(project.getProjectNo()) + .applyPersonName(admin.getRealName()) + .contractAmount(project.getContractAmount()) + .projectType(Enumerable.of(ProjectType.class, project.getType()).getDescription()) + .cooperationType(Enumerable.of(CooperationType.class, project.getCooperateType()).getDescription()) + .build(); } // 销售合同流程 @@ -188,8 +216,6 @@ public class ProcessController { // 税率 public String taxRate; - // 是否垫资 - // 收款条件 public String paymentTerms; diff --git a/src/main/java/cn/palmte/work/model/enums/CooperationType.java b/src/main/java/cn/palmte/work/model/enums/CooperationType.java new file mode 100644 index 0000000..3a2d022 --- /dev/null +++ b/src/main/java/cn/palmte/work/model/enums/CooperationType.java @@ -0,0 +1,30 @@ +package cn.palmte.work.model.enums; + +/** + * 合作类型:1战略合作类,2非战略合作类 + * + * @author Harry Yang + * @since 1.0 2022/12/14 15:20 + */ +public enum CooperationType implements Enumerable { + + STRATEGIC_COOPERATION(1, "战略合作"), + NOT_STRATEGIC_COOPERATION(2, "战略合作"); + + private final int value; + private final String description; + + CooperationType(int value, String description) { + this.value = value; + this.description = description; + } + + public String getDescription() { + return description; + } + + @Override + public Integer getValue() { + return value; + } +} diff --git a/src/main/java/cn/palmte/work/model/enums/Descriptive.java b/src/main/java/cn/palmte/work/model/enums/Descriptive.java new file mode 100644 index 0000000..6429f38 --- /dev/null +++ b/src/main/java/cn/palmte/work/model/enums/Descriptive.java @@ -0,0 +1,12 @@ +package cn.palmte.work.model.enums; + +/** + * @author Harry Yang + */ +public interface Descriptive { + /** + * Return a description + */ + String getDescription(); + +} \ No newline at end of file diff --git a/src/main/java/cn/palmte/work/model/enums/Enumerable.java b/src/main/java/cn/palmte/work/model/enums/Enumerable.java new file mode 100644 index 0000000..c824e3f --- /dev/null +++ b/src/main/java/cn/palmte/work/model/enums/Enumerable.java @@ -0,0 +1,106 @@ +package cn.palmte.work.model.enums; + +import java.util.Objects; +import java.util.Optional; +import java.util.function.Supplier; + +/** + * Enumerable for {@link Enum} + * + * @author Harry Yang + */ +public interface Enumerable extends Descriptive { + + @SuppressWarnings("unchecked") + default V getValue() { + return (V) name(); + } + + @Override + default String getDescription() { + return name(); + } + + /** + * The default name of the enumeration, this method does not need + * to be implemented, the enumeration class is automatically inherited + */ + String name(); + + /** + * Returns Enumerable by {@link Enumerable#getValue() enum value} + * + * @param enumerable enum + * @param value enumeration value + * @param enumeration type + * @param enumeration value type + * @return enumeration instance + * @throws NullPointerException if enumerable is {@code null} + * @see Enumerable#getValue() + */ + // @Nullable + static , V> T of(Class enumerable, /*@Nullable*/ V value) { + if (value != null) { + T[] enumConstants = enumerable.getEnumConstants(); + if (enumConstants != null) { + for (T constant : enumConstants) { + if (Objects.equals(value, constant.getValue())) { + return constant; + } + } + } + } + return null; + } + + /** + * Get the value corresponding to the name + * + * @param enumerable enumeration class + * @param name enumeration name + * @param enum type + * @param enumeration value type + * @return enumeration value + * @see Enumerable#getValue() + */ + // @Nullable + static , V> V getValue(Class enumerable, String name) { + T[] enumConstants = enumerable.getEnumConstants(); + if (enumConstants != null) { + for (T constant : enumConstants) { + if (Objects.equals(name, constant.name())) { + return constant.getValue(); + } + } + } + return null; + } + + /** + * @param enum type + * @param enumeration value type + * @param defaultValue default value + * @see #of(Class, V) + */ + static , V> T of(Class enumerable, V value, Supplier defaultValue) { + return find(enumerable, value).orElseGet(defaultValue); + } + + /** + * @param defaultValue default value + * @param enum type + * @param enumeration value type + * @see #of(Class, V) + */ + static , V> T of(Class enumerable, V value, T defaultValue) { + return find(enumerable, value).orElse(defaultValue); + } + + /** + * @return Optional of T + */ + static , V> Optional find(Class enumerable, V value) { + return Optional.ofNullable(of(enumerable, value)); + } + +} diff --git a/src/main/java/cn/palmte/work/model/enums/ProcessStatus.java b/src/main/java/cn/palmte/work/model/enums/ProcessStatus.java index f6b4ca0..c2afb9f 100644 --- a/src/main/java/cn/palmte/work/model/enums/ProcessStatus.java +++ b/src/main/java/cn/palmte/work/model/enums/ProcessStatus.java @@ -4,9 +4,20 @@ package cn.palmte.work.model.enums; * @author Harry Yang * @since 1.0 2022/12/13 16:12 */ -public enum ProcessStatus { +public enum ProcessStatus implements Enumerable { + + draft("草稿"), + completed("完成"); + + private final String description; + + ProcessStatus(String description) { + this.description = description; + } + + @Override + public String getDescription() { + return description; + } - draft, - completed - ; } diff --git a/src/main/java/cn/palmte/work/model/enums/ProjectType.java b/src/main/java/cn/palmte/work/model/enums/ProjectType.java new file mode 100644 index 0000000..03f51ea --- /dev/null +++ b/src/main/java/cn/palmte/work/model/enums/ProjectType.java @@ -0,0 +1,32 @@ +package cn.palmte.work.model.enums; + +/** + * 项目类型:1 工程集成类、2设备集成类、3战略合作类 + * + * @author Harry Yang + * @since 1.0 2022/12/14 15:10 + */ +public enum ProjectType implements Enumerable { + + ENGINEERING_INTEGRATION(1, "工程集成"), + DEVICE_INTEGRATION(2, "设备集成"), + STRATEGIC_COOPERATION(3, "战略合作"); + + private final int value; + private final String description; + + ProjectType(int value, String description) { + this.value = value; + this.description = description; + } + + public String getDescription() { + return description; + } + + @Override + public Integer getValue() { + return value; + } + +} diff --git a/src/main/java/cn/palmte/work/model/enums/SealType.java b/src/main/java/cn/palmte/work/model/enums/SealType.java index 817f469..ed5f0c4 100644 --- a/src/main/java/cn/palmte/work/model/enums/SealType.java +++ b/src/main/java/cn/palmte/work/model/enums/SealType.java @@ -6,7 +6,7 @@ package cn.palmte.work.model.enums; * @author Harry Yang * @since 1.0 2022/12/13 15:25 */ -public enum SealType { +public enum SealType implements Enumerable { // "公章" // "法人章" @@ -34,6 +34,7 @@ public enum SealType { this.description = description; } + @Override public String getDescription() { return description; } diff --git a/src/main/resources/templates/admin/business/process-new.ftl b/src/main/resources/templates/admin/business/process-new.ftl index d3f5a8a..f598708 100644 --- a/src/main/resources/templates/admin/business/process-new.ftl +++ b/src/main/resources/templates/admin/business/process-new.ftl @@ -76,26 +76,33 @@
- + - - - + + + {{projectTitle}} + 未选择项目 + + - + {{processForm.applyDate}} + 未选择项目 - + {{processForm.projectType}} + 未选择项目 - + {{processForm.cooperationType}} + 未选择项目
@@ -107,11 +114,13 @@ - + {{processForm.applyPersonName}} + 未选择项目 - + {{processForm.applyDeptLeaderName}} + 未选择部门 @@ -131,18 +140,21 @@ - + {{processForm.contractAmount}}元 + 未选择项目
- + - + <#--TODO 最终用户名称--> + {{processForm.finalUserName}} + 未选择项目
@@ -167,15 +179,18 @@ - + {{processForm.isPrepaid}} + 未选择项目 - + {{processForm.repaidAmount}} + 未选择项目 - + {{processForm.budgetGrossMargin}} + 未选择项目 @@ -715,6 +730,12 @@ }) .finally(() => loading.close()) }, + clearProjectProcess() { + this.projectSelected = false + this.processForm = { + sealType: [] + } + }, saveDraft() { this.processForm.status = 'draft' @@ -807,9 +828,9 @@ data, computed: { projectTitle() { - const { projectNo, name, applyPerson, applyDate } = this.processForm - if (projectNo && name) { - return projectNo.trim() + "-" + name.trim() + "-" + applyPerson + "-" + applyDate + const { projectNo, projectName, applyPersonName, applyDate } = this.processForm + if (projectNo && projectName) { + return projectNo.trim() + "-" + projectName.trim() + "-" + applyPersonName + "-" + applyDate } return "" }, @@ -848,7 +869,6 @@ this.processForm = { sealType: [], projectId: 135, - applyDate: new Date().toLocaleDateString(), ...data } this.projectSelected = true