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 c5a2a044c..f92fe38c8 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 e4eb2bd7b..88c087c93 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 b60ce3519..87f9d432a 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 93c0d92a8..ba2323716 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 ee6fc7e00..dc43bc926 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 4b8d58385..9e2376f64 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 547bc63e1..137824dd6 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 3678320eb..ecb79ad8d 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. + 芋道源码: + ① 优化代码,和项目的代码保持一致 -->