From ab2b968badee084910a0d7490d8b6d8b3be72052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=B9=8F?= Date: Thu, 20 Feb 2025 11:45:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=BF=E7=AD=96?= =?UTF-8?q?=E6=B3=95=E8=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/http/HttpUtils.java | 19 +++ .../system/enums/ErrorCodeConstants.java | 2 +- .../admin/policy/PolicyController.java | 140 ++++++++++++++++++ .../admin/policy/PolicyHtmlController.java | 57 +++++++ .../admin/policy/vo/PolicyPageReqVO.java | 25 ++++ .../admin/policy/vo/PolicyRespDetailVO.java | 29 ++++ .../admin/policy/vo/PolicyRespVO.java | 27 ++++ .../admin/policy/vo/PolicySaveReqVO.java | 20 +++ .../dal/dataobject/policy/PolicyDO.java | 39 +++++ .../system/dal/mysql/policy/PolicyMapper.java | 27 ++++ .../system/service/maxkb/MaxkbApiService.java | 6 + .../service/maxkb/MaxkbApiServiceImpl.java | 52 +++++++ .../system/service/policy/PolicyService.java | 56 +++++++ .../service/policy/PolicyServiceImpl.java | 75 ++++++++++ .../resources/mapper/policy/PolicyMapper.xml | 12 ++ .../src/main/resources/application-dev.yaml | 6 + .../src/main/resources/application-local.yaml | 6 + .../src/main/resources/application.yaml | 4 + 18 files changed, 601 insertions(+), 1 deletion(-) create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyHtmlController.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyPageReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespDetailVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicySaveReqVO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/policy/PolicyDO.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/policy/PolicyMapper.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyService.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyServiceImpl.java create mode 100644 yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/policy/PolicyMapper.xml diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java index 7ecc8cd..3f48a15 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java @@ -143,6 +143,25 @@ public class HttpUtils { } } + /** + * HTTP post 请求,基于 {@link cn.hutool.http.HttpUtil} 实现 + * + * 为什么要封装该方法,因为 HttpUtil 默认封装的方法,没有允许传递 headers 参数 + * + * @param url URL + * @param headers 请求头 + * @param requestBody 请求体 + * @return 请求结果 + */ + public static String delete(String url, Map headers, String requestBody) { + try (HttpResponse response = HttpRequest.delete(url) + .addHeaders(headers) + .body(requestBody) + .execute()) { + return response.body(); + } + } + /** * HTTP get 请求,基于 {@link cn.hutool.http.HttpUtil} 实现 * diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index 5effb1e..a1e5efb 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -205,5 +205,5 @@ public interface ErrorCodeConstants { ErrorCode SIGN_IN_LOG_ERROR6 = new ErrorCode(1-003-005-003, "超过2人才能打开"); - + ErrorCode POLICY_NOT_EXISTS = new ErrorCode(1-003-006-001, "政策法规不存在"); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyController.java new file mode 100644 index 0000000..28905ee --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyController.java @@ -0,0 +1,140 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy; + +import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import cn.iocoder.yudao.module.system.service.maxkb.MaxkbApiService; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.*; +import org.springframework.validation.annotation.Validated; +import org.springframework.security.access.prepost.PreAuthorize; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Operation; + +import java.util.*; +import java.io.IOException; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.policy.PolicyDO; +import cn.iocoder.yudao.module.system.service.policy.PolicyService; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +@Tag(name = "管理后台 - 政策法规") +@RestController +@RequestMapping("/system/policy") +@Validated +public class PolicyController { + + @Resource + private PolicyService policyService; + + @Resource + private MaxkbApiService maxkbApiService; + + @Value("${yudao.web.url}") + private String webUrl; + + @Value("${yudao.maxkb.policy.url}") + private String policyUrl; + + @Value("${yudao.maxkb.policy.id}") + private String policyMaxId; + + @PostMapping("/create") + @Operation(summary = "创建政策法规") + @PreAuthorize("@ss.hasPermission('system:policy:create')") + public CommonResult createPolicy(@Valid @RequestBody PolicySaveReqVO createReqVO) { + Integer policy = policyService.createPolicy(createReqVO); + MaxkbdocumentVo maxkbdocumentVo =new MaxkbdocumentVo(); + maxkbdocumentVo.setId(policyMaxId); + maxkbdocumentVo.setSource_url_list(new String[]{getViewUrl(policy)}); + + maxkbApiService.pushWebUrl(maxkbdocumentVo); + return success(policy); + } + + private String getViewUrl(Integer id){ + return webUrl+policyUrl+"?id="+id; + } + + @PutMapping("/update") + @Operation(summary = "更新政策法规") + @PreAuthorize("@ss.hasPermission('system:policy:update')") + public CommonResult updatePolicy(@Valid @RequestBody PolicySaveReqVO updateReqVO) { + policyService.updatePolicy(updateReqVO); + String viewUrl = getViewUrl(updateReqVO.getId()); + maxkbApiService.deleteByName(viewUrl,policyMaxId); + MaxkbdocumentVo maxkbdocumentVo =new MaxkbdocumentVo(); + maxkbdocumentVo.setId(policyMaxId); + maxkbdocumentVo.setSource_url_list(new String[]{getViewUrl(updateReqVO.getId())}); + maxkbApiService.pushWebUrl(maxkbdocumentVo); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除政策法规") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('system:policy:delete')") + public CommonResult deletePolicy(@RequestParam("id") Integer id) { + policyService.deletePolicy(id); + String viewUrl = getViewUrl(id); + maxkbApiService.deleteByName(viewUrl,policyMaxId); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得政策法规") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PermitAll + public CommonResult getPolicy(@RequestParam("id") Integer id) { + PolicyDO policy = policyService.getPolicy(id); + return success(BeanUtils.toBean(policy, PolicyRespDetailVO.class)); + } + + @GetMapping("/getContent") + @Operation(summary = "获得政策法规") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PermitAll + public String getContentPolicy(@RequestParam("id") Integer id) { + PolicyDO policy = policyService.getPolicy(id); + String context = policy.getContext(); + + return ""+context+""; + } + + @GetMapping("/page") + @Operation(summary = "获得政策法规分页") + @PreAuthorize("@ss.hasPermission('system:policy:query')") + public CommonResult> getPolicyPage(@Valid PolicyPageReqVO pageReqVO) { + PageResult pageResult = policyService.getPolicyPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, PolicyRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出政策法规 Excel") + @PreAuthorize("@ss.hasPermission('system:policy:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPolicyExcel(@Valid PolicyPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = policyService.getPolicyPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "政策法规.xls", "数据", PolicyRespVO.class, + BeanUtils.toBean(list, PolicyRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyHtmlController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyHtmlController.java new file mode 100644 index 0000000..a460c6e --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/PolicyHtmlController.java @@ -0,0 +1,57 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy; + +import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.PolicyPageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.PolicyRespDetailVO; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.PolicyRespVO; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.PolicySaveReqVO; +import cn.iocoder.yudao.module.system.dal.dataobject.policy.PolicyDO; +import cn.iocoder.yudao.module.system.service.maxkb.MaxkbApiService; +import cn.iocoder.yudao.module.system.service.policy.PolicyService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 政策法规") +@RequestMapping("/system/policyHtml") +@RestController +public class PolicyHtmlController { + + @Resource + private PolicyService policyService; + + + @GetMapping("/getContent") + @Operation(summary = "获得政策法规") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PermitAll + @ResponseBody + public String getContentPolicy(@RequestParam("id") Integer id) { + PolicyDO policy = policyService.getPolicy(id); + String context = policy.getContext(); + + return ""+context+""; + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyPageReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyPageReqVO.java new file mode 100644 index 0000000..6c351db --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyPageReqVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 政策法规分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class PolicyPageReqVO extends PageParam { + + @Schema(description = "名称", example = "王五") + private String name; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespDetailVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespDetailVO.java new file mode 100644 index 0000000..f663313 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespDetailVO.java @@ -0,0 +1,29 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 政策法规 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PolicyRespDetailVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29928") + @ExcelProperty("id") + private Integer id; + + @Schema(description = "名称", example = "王五") + @ExcelProperty("名称") + private String name; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + + private String context; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespVO.java new file mode 100644 index 0000000..d165df3 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicyRespVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 政策法规 Response VO") +@Data +@ExcelIgnoreUnannotated +public class PolicyRespVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29928") + @ExcelProperty("id") + private Integer id; + + @Schema(description = "名称", example = "王五") + @ExcelProperty("名称") + private String name; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicySaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicySaveReqVO.java new file mode 100644 index 0000000..7fc1ed8 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/policy/vo/PolicySaveReqVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.system.controller.admin.policy.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; + +@Schema(description = "管理后台 - 政策法规新增/修改 Request VO") +@Data +public class PolicySaveReqVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "29928") + private Integer id; + + @Schema(description = "名称", example = "王五") + private String name; + + @Schema(description = "内容") + private String context; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/policy/PolicyDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/policy/PolicyDO.java new file mode 100644 index 0000000..103e564 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/policy/PolicyDO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.system.dal.dataobject.policy; + +import lombok.*; +import java.util.*; +import java.time.LocalDateTime; +import java.time.LocalDateTime; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; + +/** + * 政策法规 DO + * + * @author 芋道源码 + */ +@TableName("hb_policy") +@KeySequence("hb_policy_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class PolicyDO extends BaseDO { + + /** + * id + */ + @TableId + private Integer id; + /** + * 名称 + */ + private String name; + /** + * 内容 + */ + private String context; + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/policy/PolicyMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/policy/PolicyMapper.java new file mode 100644 index 0000000..75a0d17 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/policy/PolicyMapper.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.system.dal.mysql.policy; + +import java.util.*; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.system.dal.dataobject.policy.PolicyDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.*; + +/** + * 政策法规 Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface PolicyMapper extends BaseMapperX { + + default PageResult selectPage(PolicyPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(PolicyDO::getName, reqVO.getName()) + .betweenIfPresent(PolicyDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(PolicyDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java index 24220b7..2a57755 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiService.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.system.service.maxkb; +import cn.hutool.json.JSONArray; import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import com.google.gson.JsonObject; import java.util.List; @@ -10,4 +12,8 @@ public interface MaxkbApiService { public void pushWebUrl(MaxkbdocumentVo maxkbdocumentVo) ; + public JSONArray getDocumentList(String name, String id); + + public void deleteByName(String name, String id); + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java index 94cd3c9..bb08ec7 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java @@ -7,6 +7,7 @@ import cn.hutool.json.JSONUtil; import cn.iocoder.yudao.framework.common.util.http.HttpUtils; import cn.iocoder.yudao.module.infra.api.config.ConfigApi; import cn.iocoder.yudao.module.system.controller.admin.maxkb.vo.MaxkbdocumentVo; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -16,6 +17,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @Service @Slf4j @@ -50,11 +52,61 @@ public class MaxkbApiServiceImpl implements MaxkbApiService { @Override public void pushWebUrl(MaxkbdocumentVo maxkbdocumentVo) { + log.info("web知识库请求信息:"+configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+maxkbdocumentVo.getId()+"/document/web"); + if(StrUtil.isEmpty(maxkbdocumentVo.getSelector())){ + maxkbdocumentVo.setSelector(""); + } + log.info("web知识库请求参数:"+JSONUtil.toJsonStr(maxkbdocumentVo)); + log.info("webtoken:"+JSONUtil.toJsonStr(getMaxkbHeager())); String s = HttpUtils.post(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+maxkbdocumentVo.getId()+"/document/web",getMaxkbHeager(), JSONUtil.toJsonStr(maxkbdocumentVo)); log.info("web知识库返回信息"+s); } + + + @Override + public JSONArray getDocumentList(String name, String id) { + String s = HttpUtils.get(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/" + id + "/document/1/10000?name="+name, getMaxkbHeager()); + log.info("web知识库返回信息"+s); + JSONObject jsonObject = JSONUtil.parseObj(s); + if("200".equals(jsonObject.getStr("code"))) { + + JSONObject data = jsonObject.getJSONObject("data"); + log.info("web知识库返回信息data"+JSONUtil.toJsonStr(data)); + if (data != null) { + if(!JSONUtil.isNull(data)){ + if(data.containsKey("records")){ + log.info("web知识库返回信息records"+data.containsKey("records")); + + } + JSONArray records = data.getJSONArray("records"); + return records; + } + } + } + + throw new RuntimeException(jsonObject.getStr("message")); + } + + @Override + public void deleteByName(String name, String id) { + JSONArray documentList = getDocumentList(name, id); + if(documentList!= null && !documentList.isEmpty()){ + //取出所有id + List ids = documentList.stream().map(o -> ((JSONObject) o).getStr("id")).collect(Collectors.toList()); + JSONObject jsonObject = new JSONObject(); + jsonObject.set("id_list",ids); + String s = HttpUtils.delete(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+id+"/document/web",getMaxkbHeager(), JSONUtil.toJsonStr(jsonObject)); + log.info("web知识库返回信息"+s); + } + + + } + + + + private MapgetMaxkbHeager(){ String token = stringRedisTemplate.opsForValue().get(MAXKB_ACCOUNT_TOKEN); if(StrUtil.isEmpty(token)){ diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyService.java new file mode 100644 index 0000000..c2ebd55 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyService.java @@ -0,0 +1,56 @@ +package cn.iocoder.yudao.module.system.service.policy; + +import java.util.*; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.policy.PolicyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; + +import javax.validation.Valid; + +/** + * 政策法规 Service 接口 + * + * @author 芋道源码 + */ +public interface PolicyService { + + /** + * 创建政策法规 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Integer createPolicy(@Valid PolicySaveReqVO createReqVO); + + /** + * 更新政策法规 + * + * @param updateReqVO 更新信息 + */ + void updatePolicy(@Valid PolicySaveReqVO updateReqVO); + + /** + * 删除政策法规 + * + * @param id 编号 + */ + void deletePolicy(Integer id); + + /** + * 获得政策法规 + * + * @param id 编号 + * @return 政策法规 + */ + PolicyDO getPolicy(Integer id); + + /** + * 获得政策法规分页 + * + * @param pageReqVO 分页查询 + * @return 政策法规分页 + */ + PageResult getPolicyPage(PolicyPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyServiceImpl.java new file mode 100644 index 0000000..944b511 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/policy/PolicyServiceImpl.java @@ -0,0 +1,75 @@ +package cn.iocoder.yudao.module.system.service.policy; + +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; +import cn.iocoder.yudao.module.system.controller.admin.policy.vo.*; +import cn.iocoder.yudao.module.system.dal.dataobject.policy.PolicyDO; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; + +import cn.iocoder.yudao.module.system.dal.mysql.policy.PolicyMapper; + +import javax.annotation.Resource; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; + +/** + * 政策法规 Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Validated +public class PolicyServiceImpl implements PolicyService { + + @Resource + private PolicyMapper policyMapper; + + @Override + public Integer createPolicy(PolicySaveReqVO createReqVO) { + // 插入 + PolicyDO policy = BeanUtils.toBean(createReqVO, PolicyDO.class); + policyMapper.insert(policy); + // 返回 + return policy.getId(); + } + + @Override + public void updatePolicy(PolicySaveReqVO updateReqVO) { + // 校验存在 + validatePolicyExists(updateReqVO.getId()); + // 更新 + PolicyDO updateObj = BeanUtils.toBean(updateReqVO, PolicyDO.class); + policyMapper.updateById(updateObj); + } + + @Override + public void deletePolicy(Integer id) { + // 校验存在 + validatePolicyExists(id); + // 删除 + policyMapper.deleteById(id); + } + + private void validatePolicyExists(Integer id) { + if (policyMapper.selectById(id) == null) { + throw exception(POLICY_NOT_EXISTS); + } + } + + @Override + public PolicyDO getPolicy(Integer id) { + return policyMapper.selectById(id); + } + + @Override + public PageResult getPolicyPage(PolicyPageReqVO pageReqVO) { + return policyMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/policy/PolicyMapper.xml b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/policy/PolicyMapper.xml new file mode 100644 index 0000000..9f0f1b9 --- /dev/null +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/policy/PolicyMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-server/src/main/resources/application-dev.yaml b/yudao-server/src/main/resources/application-dev.yaml index 16ab13e..a65e886 100644 --- a/yudao-server/src/main/resources/application-dev.yaml +++ b/yudao-server/src/main/resources/application-dev.yaml @@ -164,6 +164,12 @@ wx: # 参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-sta # 芋道配置项,设置当前项目所有自定义的配置 yudao: + web: + url: http://localhost:9980/ + maxkb: + policy: + url: policyDetail + id: bff33a78-e5bd-11ef-825e-0242ac110003 pay: order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址 refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 09ccef5..e90fd3a 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -212,6 +212,12 @@ wx: # 芋道配置项,设置当前项目所有自定义的配置 yudao: + web: + url: http://localhost:9980/ + maxkb: + policy: + url: policyDetail + id: bff33a78-e5bd-11ef-825e-0242ac110003 captcha: enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试; security: diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 9edf6e5..799212c 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -221,6 +221,9 @@ yudao: security: permit-all_urls: - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,不需要登录 + - /admin-api/system/policy/get # 微信公众号开放平台,微信回调接口,不需要登录 + - /admin-api/system/policy/getContent # 微信公众号开放平台,微信回调接口,不需要登录 + - /admin-api/system/policyHtml/getContent # 微信公众号开放平台,微信回调接口,不需要登录 websocket: enable: true # websocket的开关 path: /infra/ws # 路径 @@ -260,6 +263,7 @@ yudao: - /jmreport/* # 积木报表,无法携带租户编号 - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 - /admin-api/system/wechat/** + - /policyDetail ignore-tables: - system_tenant - system_tenant_package From f194e35c58d7fdecc5f009dcabbcb85ba9d09f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=B9=8F?= Date: Thu, 20 Feb 2025 14:28:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java index bb08ec7..99ed35a 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/maxkb/MaxkbApiServiceImpl.java @@ -97,7 +97,7 @@ public class MaxkbApiServiceImpl implements MaxkbApiService { List ids = documentList.stream().map(o -> ((JSONObject) o).getStr("id")).collect(Collectors.toList()); JSONObject jsonObject = new JSONObject(); jsonObject.set("id_list",ids); - String s = HttpUtils.delete(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+id+"/document/web",getMaxkbHeager(), JSONUtil.toJsonStr(jsonObject)); + String s = HttpUtils.delete(configApi.getConfigValueByKey(MAXKB_ACCOUNT_URL) + "/api/dataset/"+id+"/document/_bach",getMaxkbHeager(), JSONUtil.toJsonStr(jsonObject)); log.info("web知识库返回信息"+s); }