From 90ffe5adb769fd1dc3e954fdb485107476838a12 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 14 Jan 2023 09:17:01 +0800 Subject: [PATCH] =?UTF-8?q?mp=EF=BC=9A=E5=A2=9E=E5=8A=A0=E5=9B=BE=E6=96=87?= =?UTF-8?q?=E8=8D=89=E7=A8=BF=E7=AE=B1=E7=9A=84=E4=BF=AE=E6=94=B9=EF=BC=9B?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/mp/enums/ErrorCodeConstants.java | 1 + .../material/vo/MpMaterialPageReqVO.java | 6 + .../admin/news/MpDraftController.http | 22 + .../admin/news/MpDraftController.java | 36 +- .../dal/mysql/material/MpMaterialMapper.java | 1 + yudao-ui-admin/src/api/mp/draft.js | 9 + .../mp/components/wx-material-select/main.vue | 7 +- yudao-ui-admin/src/views/mp/draft/index.vue | 631 ++++++++---------- 8 files changed, 365 insertions(+), 348 deletions(-) diff --git a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java index c5a2a044c1..f92fe38c82 100644 --- a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java +++ b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java @@ -46,6 +46,7 @@ public interface ErrorCodeConstants { // ========== 公众号草稿 1006007000============ ErrorCode DRAFT_LIST_FAIL = new ErrorCode(1006007000, "获得草稿列表失败,原因:{}"); ErrorCode DRAFT_CREATE_FAIL = new ErrorCode(1006007001, "创建草稿失败,原因:{}"); + ErrorCode DRAFT_UPDATE_FAIL = new ErrorCode(1006007002, "更新草稿失败,原因:{}"); // TODO 要处理下 ErrorCode MENU_NOT_EXISTS = new ErrorCode(1006001002, "菜单不存在"); diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/vo/MpMaterialPageReqVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/vo/MpMaterialPageReqVO.java index e4eb2bd7b2..88c087c939 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/vo/MpMaterialPageReqVO.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/vo/MpMaterialPageReqVO.java @@ -7,12 +7,18 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; +import javax.validation.constraints.NotNull; + @ApiModel("管理后台 - 公众号素材的分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MpMaterialPageReqVO extends PageParam { + @ApiModelProperty(value = "公众号账号的编号", required = true, example = "2048") + @NotNull(message = "公众号账号的编号不能为空") + private Long accountId; + @ApiModelProperty(value = "是否永久", example = "true") private Boolean permanent; diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.http b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.http index b60ce35195..87f9d432a1 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.http +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.http @@ -30,3 +30,25 @@ tenant-id: {{adminTenentId}} } ] } + +### 请求 /mp/draft/create 接口 => 成功 +PUT {{baseUrl}}/mp/draft/update?accountId=1&mediaId=r6ryvl6LrxBU0miaST4Y-q-G9pdsmZw0OYG4FzHQkKfpLfEwIH51wy2bxisx8PvW +Content-Type: application/json +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +[{ + "title": "我是标题(OOO)", + "author": "我是作者", + "digest": "我是摘要", + "content": "我是内容", + "contentSourceUrl": "https://www.iocoder.cn", + "thumbMediaId": "r6ryvl6LrxBU0miaST4Y-pIcmK-zAAId-9TGgy-DrSLhjVuWbuT3ZBjk9K1yQ0Dn" +}, { + "title": "我是标题(XXX)", + "author": "我是作者", + "digest": "我是摘要", + "content": "我是内容", + "contentSourceUrl": "https://www.iocoder.cn", + "thumbMediaId": "r6ryvl6LrxBU0miaST4Y-pIcmK-zAAId-9TGgy-DrSLhjVuWbuT3ZBjk9K1yQ0Dn" +}] diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.java index 93c0d92a8f..ba2323716c 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/news/MpDraftController.java @@ -7,21 +7,20 @@ import cn.iocoder.yudao.module.mp.controller.admin.news.vo.MpDraftPageReqVO; import cn.iocoder.yudao.module.mp.framework.mp.core.MpServiceFactory; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.draft.WxMpAddDraft; -import me.chanjar.weixin.mp.bean.draft.WxMpDraftItem; -import me.chanjar.weixin.mp.bean.draft.WxMpDraftList; +import me.chanjar.weixin.mp.bean.draft.*; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.DRAFT_CREATE_FAIL; -import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.DRAFT_LIST_FAIL; +import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.*; // TODO 芋艿:权限 @Api(tags = "管理后台 - 公众号草稿") @@ -54,14 +53,37 @@ public class MpDraftController { @ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true, example = "1024", dataTypeClass = Long.class) public CommonResult createDraft(@RequestParam("accountId") Long accountId, - @RequestBody WxMpAddDraft reqVO) { + @RequestBody WxMpAddDraft draft) { WxMpService mpService = mpServiceFactory.getRequiredMpService(accountId); try { - String mediaId = mpService.getDraftService().addDraft(reqVO); + String mediaId = mpService.getDraftService().addDraft(draft); return success(mediaId); } catch (WxErrorException e) { throw exception(DRAFT_CREATE_FAIL, e.getError().getErrorMsg()); } } + @PutMapping("/update") + @ApiOperation("更新草稿") + @ApiImplicitParams({ + @ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true, + example = "1024", dataTypeClass = Long.class), + @ApiImplicitParam(name = "mediaId", value = "草稿素材的编号", required = true, + example = "xxx", dataTypeClass = String.class), + }) + public CommonResult createDraft(@RequestParam("accountId") Long accountId, + @RequestParam("mediaId") String mediaId, + @RequestBody List articles) { + WxMpService mpService = mpServiceFactory.getRequiredMpService(accountId); + try { + for (int i = 0; i < articles.size(); i++) { + WxMpDraftArticles article = articles.get(i); + mpService.getDraftService().updateDraft(new WxMpUpdateDraft(mediaId, i, article)); + } + return success(true); + } catch (WxErrorException e) { + throw exception(DRAFT_UPDATE_FAIL, e.getError().getErrorMsg()); + } + } + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/mysql/material/MpMaterialMapper.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/mysql/material/MpMaterialMapper.java index ee6fc7e004..dc43bc9264 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/mysql/material/MpMaterialMapper.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/mysql/material/MpMaterialMapper.java @@ -20,6 +20,7 @@ public interface MpMaterialMapper extends BaseMapperX { default PageResult selectPage(MpMaterialPageReqVO pageReqVO) { return selectPage(pageReqVO, new LambdaQueryWrapperX() + .eq(MpMaterialDO::getAccountId, pageReqVO.getAccountId()) .eqIfPresent(MpMaterialDO::getPermanent, pageReqVO.getPermanent()) .eqIfPresent(MpMaterialDO::getType, pageReqVO.getType())); } diff --git a/yudao-ui-admin/src/api/mp/draft.js b/yudao-ui-admin/src/api/mp/draft.js index 4b8d58385e..9e2376f64e 100644 --- a/yudao-ui-admin/src/api/mp/draft.js +++ b/yudao-ui-admin/src/api/mp/draft.js @@ -19,3 +19,12 @@ export function createDraft(accountId, articles) { } }) } + +// 更新草稿 +export function updateDraft(accountId, mediaId, articles) { + return request({ + url: '/mp/draft/update?accountId=' + accountId + '&mediaId=' + mediaId, + method: 'put', + data: articles + }) +} diff --git a/yudao-ui-admin/src/views/mp/components/wx-material-select/main.vue b/yudao-ui-admin/src/views/mp/components/wx-material-select/main.vue index 547bc63e1b..137824dd6d 100644 --- a/yudao-ui-admin/src/views/mp/components/wx-material-select/main.vue +++ b/yudao-ui-admin/src/views/mp/components/wx-material-select/main.vue @@ -117,7 +117,7 @@ }, props: { objData: { - type: Object, + type: Object, // type - 类型;accountId - 公众号账号编号 required: true }, newsType:{ // 图文类型:1、已发布图文;2、草稿箱图文 @@ -148,6 +148,11 @@ selectMaterial(item) { this.$emit('selectMaterial', item) }, + /** 搜索按钮操作 */ + handleQuery() { + this.queryParams.pageNo = 1 + this.getPage() + }, getPage() { this.loading = true if (this.objData.type === 'news' && this.newsType === '1') { // 【图文】+ 【已发布】 diff --git a/yudao-ui-admin/src/views/mp/draft/index.vue b/yudao-ui-admin/src/views/mp/draft/index.vue index 3678320eb1..ecb79ad8d1 100644 --- a/yudao-ui-admin/src/views/mp/draft/index.vue +++ b/yudao-ui-admin/src/views/mp/draft/index.vue @@ -20,6 +20,8 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + 芋道源码: + ① 优化代码,和项目的代码保持一致 -->