From 0de126309156431c7045e631cc34f40ca5f50f88 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Wed, 15 Feb 2023 11:07:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=84=E5=AE=A1=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E9=85=8D=E7=BD=AE=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReviewTemplateSettingsController.java | 23 +++++++- .../manage/ReviewTemplateSettingsManage.java | 63 ++++++++++++++++++++++ .../model/entity/ReviewTemplateSettings.java | 33 ++++++++---- .../model/enumeration/ReviewTemplateTypeEnum.java | 46 ++++++++++++++++ .../pmapi/expert/model/req/ReviewTemplateReq.java | 32 +++++++++++ .../pmapi/expert/model/vo/ReviewTemplateVO.java | 34 ++++++++++++ .../ningdatech/pmapi/sys/model/entity/Menu.java | 2 +- .../pmapi/sys/service/IMenuServiceTest.java | 11 ++-- 8 files changed, 225 insertions(+), 19 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ReviewTemplateSettingsManage.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/expert/model/enumeration/ReviewTemplateTypeEnum.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/expert/model/req/ReviewTemplateReq.java create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/expert/model/vo/ReviewTemplateVO.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/controller/ReviewTemplateSettingsController.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/controller/ReviewTemplateSettingsController.java index 8cecd91..e4633b0 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/controller/ReviewTemplateSettingsController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/controller/ReviewTemplateSettingsController.java @@ -1,10 +1,15 @@ package com.ningdatech.pmapi.expert.controller; +import com.ningdatech.pmapi.expert.manage.ReviewTemplateSettingsManage; +import com.ningdatech.pmapi.expert.model.req.ReviewTemplateReq; +import com.ningdatech.pmapi.expert.model.vo.ReviewTemplateVO; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; /** *

@@ -20,4 +25,18 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/api/v1/reviewTemplateSettings") public class ReviewTemplateSettingsController { + private final ReviewTemplateSettingsManage reviewTemplateSettingsManage; + + @GetMapping("/template/{templateType}") + @ApiOperation("根据模版类型获取模版") + public ReviewTemplateVO getReviewTemplateByType(@PathVariable Integer templateType) { + return reviewTemplateSettingsManage.getReviewTemplateSettings(templateType); + } + + @PostMapping("/modify") + @ApiOperation("修改或保存模版配置") + public void modifyReviewTemplateSettings(@RequestBody @Valid ReviewTemplateReq req) { + reviewTemplateSettingsManage.saveOrUpdate(req); + } + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ReviewTemplateSettingsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ReviewTemplateSettingsManage.java new file mode 100644 index 0000000..e99acac --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/manage/ReviewTemplateSettingsManage.java @@ -0,0 +1,63 @@ +package com.ningdatech.pmapi.expert.manage; + +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ningdatech.basic.exception.BizException; +import com.ningdatech.pmapi.common.constant.BizConst; +import com.ningdatech.pmapi.expert.model.dto.ReviewTemplateSettingsDTO; +import com.ningdatech.pmapi.expert.model.entity.ReviewTemplateSettings; +import com.ningdatech.pmapi.expert.model.req.ReviewTemplateReq; +import com.ningdatech.pmapi.expert.model.vo.ReviewTemplateVO; +import com.ningdatech.pmapi.expert.service.IReviewTemplateSettingsService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +/** + *

+ * ReviewTemplateSettingsManage + *

+ * + * @author WendyYang + * @since 09:41 2023/2/15 + */ +@Component +@AllArgsConstructor +public class ReviewTemplateSettingsManage { + + private final IReviewTemplateSettingsService reviewTemplateSettingsService; + + @Transactional(rollbackFor = Exception.class) + public void saveOrUpdate(ReviewTemplateReq req) { + LambdaUpdateWrapper update = Wrappers.lambdaUpdate(ReviewTemplateSettings.class) + .eq(ReviewTemplateSettings::getTemplateType, req.getTemplateType()) + .eq(ReviewTemplateSettings::getIsLast, Boolean.TRUE) + .set(ReviewTemplateSettings::getIsLast, Boolean.FALSE) + .last(BizConst.LIMIT_1); + reviewTemplateSettingsService.update(update); + ReviewTemplateSettings settings = new ReviewTemplateSettings(); + settings.setTemplateType(req.getTemplateType()); + settings.setIsLast(Boolean.TRUE); + settings.setContent(JSONUtil.toJsonStr(req.getTemplates())); + reviewTemplateSettingsService.save(settings); + } + + public ReviewTemplateVO getReviewTemplateSettings(Integer templateType) { + LambdaQueryWrapper query = Wrappers.lambdaQuery(ReviewTemplateSettings.class) + .eq(ReviewTemplateSettings::getIsLast, Boolean.TRUE) + .eq(ReviewTemplateSettings::getTemplateType, templateType) + .last(BizConst.LIMIT_1); + ReviewTemplateSettings settings = reviewTemplateSettingsService.getOne(query); + if (settings == null) { + throw BizException.wrap("模版不存在"); + } + return ReviewTemplateVO.builder() + .templateId(settings.getId()) + .templateType(settings.getTemplateType()) + .templates(JSONUtil.toList(settings.getContent(), ReviewTemplateSettingsDTO.class)) + .build(); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/entity/ReviewTemplateSettings.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/entity/ReviewTemplateSettings.java index 1c3e544..7caefe8 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/entity/ReviewTemplateSettings.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/entity/ReviewTemplateSettings.java @@ -1,11 +1,14 @@ package com.ningdatech.pmapi.expert.model.entity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import java.io.Serializable; -import java.time.LocalDateTime; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import java.io.Serializable; +import java.time.LocalDateTime; + /** *

* 评审模版配置表 @@ -21,6 +24,7 @@ public class ReviewTemplateSettings implements Serializable { private static final long serialVersionUID = 1L; @ApiModelProperty("主键") + @TableId(type = IdType.AUTO) private Long id; @ApiModelProperty("模版类型:1 初步方案评审模版、2 建设方案评审模版、3 验收方案评审模版") @@ -47,6 +51,7 @@ public class ReviewTemplateSettings implements Serializable { public void setId(Long id) { this.id = id; } + public Integer getTemplateType() { return templateType; } @@ -54,6 +59,7 @@ public class ReviewTemplateSettings implements Serializable { public void setTemplateType(Integer templateType) { this.templateType = templateType; } + public String getContent() { return content; } @@ -61,6 +67,7 @@ public class ReviewTemplateSettings implements Serializable { public void setContent(String content) { this.content = content; } + public Long getCreateBy() { return createBy; } @@ -68,6 +75,7 @@ public class ReviewTemplateSettings implements Serializable { public void setCreateBy(Long createBy) { this.createBy = createBy; } + public Long getUpdateBy() { return updateBy; } @@ -75,6 +83,7 @@ public class ReviewTemplateSettings implements Serializable { public void setUpdateBy(Long updateBy) { this.updateBy = updateBy; } + public LocalDateTime getCreateOn() { return createOn; } @@ -82,6 +91,7 @@ public class ReviewTemplateSettings implements Serializable { public void setCreateOn(LocalDateTime createOn) { this.createOn = createOn; } + public LocalDateTime getUpdateOn() { return updateOn; } @@ -89,6 +99,7 @@ public class ReviewTemplateSettings implements Serializable { public void setUpdateOn(LocalDateTime updateOn) { this.updateOn = updateOn; } + public Boolean getIsLast() { return isLast; } @@ -100,14 +111,14 @@ public class ReviewTemplateSettings implements Serializable { @Override public String toString() { return "NdReviewTemplateSettings{" + - "id=" + id + - ", templateType=" + templateType + - ", content=" + content + - ", createBy=" + createBy + - ", updateBy=" + updateBy + - ", createOn=" + createOn + - ", updateOn=" + updateOn + - ", isLast=" + isLast + - "}"; + "id=" + id + + ", templateType=" + templateType + + ", content=" + content + + ", createBy=" + createBy + + ", updateBy=" + updateBy + + ", createOn=" + createOn + + ", updateOn=" + updateOn + + ", isLast=" + isLast + + "}"; } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/enumeration/ReviewTemplateTypeEnum.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/enumeration/ReviewTemplateTypeEnum.java new file mode 100644 index 0000000..4e9da26 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/enumeration/ReviewTemplateTypeEnum.java @@ -0,0 +1,46 @@ +package com.ningdatech.pmapi.expert.model.enumeration; + +import lombok.Getter; + +import java.util.Arrays; + +/** + *

+ * ReviewTemplateTypeEnum + *

+ * + * @author WendyYang + * @since 09:48 2023/2/15 + */ +@Getter +public enum ReviewTemplateTypeEnum { + /** + * 评审模版类型 + */ + PRELIMINARY_SCHEME_REVIEW("初步方案评审", 1), + + CONSTRUCTION_SCHEME_REVIEW("建设方案评审", 2), + + ACCEPTANCE_SCHEME_REVIEW("验收方案评审", 3); + + + private final String value; + private final Integer code; + + ReviewTemplateTypeEnum(String value, Integer code) { + this.value = value; + this.code = code; + } + + public boolean eq(Integer code) { + return this.getCode().equals(code); + } + + public static ReviewTemplateTypeEnum getByCode(Integer code) { + return Arrays.stream(values()) + .filter(w -> w.getCode().equals(code)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("评审模版类型编码无效")); + } + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/req/ReviewTemplateReq.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/req/ReviewTemplateReq.java new file mode 100644 index 0000000..7c96f19 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/req/ReviewTemplateReq.java @@ -0,0 +1,32 @@ +package com.ningdatech.pmapi.expert.model.req; + +import com.ningdatech.pmapi.expert.model.dto.ReviewTemplateSettingsDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + *

+ * ReviewTemplateReq + *

+ * + * @author WendyYang + * @since 10:11 2023/2/15 + */ +@Data +public class ReviewTemplateReq { + + @ApiModelProperty("模版类型") + @NotNull(message = "模版类型不能为空") + private Integer templateType; + + @Valid + @NotEmpty(message = "模版不能为空") + @ApiModelProperty("模版数据") + private List templates; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/vo/ReviewTemplateVO.java b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/vo/ReviewTemplateVO.java new file mode 100644 index 0000000..f887fb4 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/expert/model/vo/ReviewTemplateVO.java @@ -0,0 +1,34 @@ +package com.ningdatech.pmapi.expert.model.vo; + +import com.ningdatech.pmapi.expert.model.dto.ReviewTemplateSettingsDTO; +import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; +import lombok.Data; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + *

+ * ReviewTemplateReq + *

+ * + * @author WendyYang + * @since 10:11 2023/2/15 + */ +@Data +@Builder +public class ReviewTemplateVO { + + @ApiModelProperty("模版ID") + private Long templateId; + + @ApiModelProperty("模版类型") + private Integer templateType; + + @ApiModelProperty("模版数据") + private List templates; + +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java index a1ec156..247a63b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sys/model/entity/Menu.java @@ -46,7 +46,7 @@ public class Menu extends MenuTreeEntity { @ApiModelProperty(value = "是否隐藏") @TableField(value = "hidden") - private Boolean hidden; + private Integer hidden; @ApiModelProperty(value = "activeMenu") @TableField(value = "active_menu") diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java index 78af962..fcb8319 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/sys/service/IMenuServiceTest.java @@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.db.Db; import cn.hutool.db.Entity; -import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.ningdatech.pmapi.AppTests; @@ -46,11 +45,13 @@ class IMenuServiceTest extends AppTests { @Test public void initMenu() { - /*String str = FileUtil.readString("/Users/wendy/Desktop/long_text_2023-02-13-15-28-42.txt", "UTF-8"); + menuService.remove(null); + roleMenuService.remove(null); + String str = FileUtil.readString("/Users/wendy/Desktop/long_text_2023-02-13-15-28-42.txt", "UTF-8"); List obj = JSONUtil.toList(str, JSONObject.class); - save(obj, 0);*/ + save(obj, 0); menuService.list().forEach(w -> { - roleMenuService.save(new RoleMenu(){{ + roleMenuService.save(new RoleMenu() {{ setRoleId(1L); setMenuId(w.getId()); }}); @@ -67,7 +68,7 @@ class IMenuServiceTest extends AppTests { menu.setName(w.getStr("path").replace("/", "")); menu.setTopMenu(w.getStr("topMenu")); menu.setTitle(w.getStr("title")); - menu.setHidden(w.getBool("hidden")); + menu.setHidden(w.getInt("hidden")); menu.setPid(parentId); menu.setRedirect(w.getStr("redirect")); menu.setSort(w.getInt("sort"));