From 5a1d02dffdea63bc9b38bcf334f2dd9889db0dd3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 14 Jan 2023 15:46:35 +0800 Subject: [PATCH] =?UTF-8?q?mp=EF=BC=9A=E7=B4=A0=E6=9D=90=E7=AE=A1=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E3=80=90=E5=9B=BE=E7=89=87=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/mp/enums/ErrorCodeConstants.java | 6 +- .../admin/material/MpMaterialController.java | 23 +- .../dal/mysql/material/MpMaterialMapper.java | 3 +- .../service/material/MpMaterialService.java | 7 + .../material/MpMaterialServiceImpl.java | 24 +- yudao-ui-admin/src/api/mp/material.js | 8 + .../mp/components/wx-material-select/main.vue | 6 - .../src/views/mp/components/wx-reply/main.vue | 4 +- yudao-ui-admin/src/views/mp/draft/index.vue | 6 +- .../src/views/mp/freePublish/index.vue | 3 - .../src/views/mp/material/index.vue | 502 ++++++++++++++++++ 11 files changed, 564 insertions(+), 28 deletions(-) create mode 100644 yudao-ui-admin/src/views/mp/material/index.vue 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 409d32c88..244bff647 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 @@ -32,8 +32,10 @@ public interface ErrorCodeConstants { ErrorCode USER_UPDATE_TAG_FAIL = new ErrorCode(1006003001, "更新用户标签失败,原因:{}"); // ========== 公众号素材 1006004000============ - ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004000, "上传素材失败,原因:{}"); - ErrorCode MATERIAL_IMAGE_UPLOAD_FAIL = new ErrorCode(1006004000, "上传图片失败,原因:{}"); + ErrorCode MATERIAL_NOT_EXISTS = new ErrorCode(1006004000, "素材不存在"); + ErrorCode MATERIAL_UPLOAD_FAIL = new ErrorCode(1006004001, "上传素材失败,原因:{}"); + ErrorCode MATERIAL_IMAGE_UPLOAD_FAIL = new ErrorCode(1006004002, "上传图片失败,原因:{}"); + ErrorCode MATERIAL_DELETE_FAIL = new ErrorCode(1006004003, "删除素材失败,原因:{}"); // ========== 公众号消息 1006005000============ ErrorCode MESSAGE_SEND_FAIL = new ErrorCode(1006005000, "发送消息失败,原因:{}"); diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/MpMaterialController.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/MpMaterialController.java index 6375344d1..efd7b0420 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/MpMaterialController.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/material/MpMaterialController.java @@ -7,12 +7,11 @@ import cn.iocoder.yudao.module.mp.convert.material.MpMaterialConvert; import cn.iocoder.yudao.module.mp.dal.dataobject.material.MpMaterialDO; import cn.iocoder.yudao.module.mp.service.material.MpMaterialService; import io.swagger.annotations.Api; +import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; @@ -20,8 +19,6 @@ import java.io.IOException; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -// TODO @芋艿:权限 - @Api(tags = "管理后台 - 公众号素材") @RestController @RequestMapping("/mp/material") @@ -33,6 +30,7 @@ public class MpMaterialController { @ApiOperation("上传临时素材") @PostMapping("/upload-temporary") + @PreAuthorize("@ss.hasPermission('mp:material:upload-temporary')") public CommonResult uploadTemporaryMaterial( @Valid MpMaterialUploadTemporaryReqVO reqVO) throws IOException { MpMaterialDO material = mpMaterialService.uploadTemporaryMaterial(reqVO); @@ -41,14 +39,25 @@ public class MpMaterialController { @ApiOperation("上传永久素材") @PostMapping("/upload-permanent") + @PreAuthorize("@ss.hasPermission('mp:material:upload-permanent')") public CommonResult uploadPermanentMaterial( @Valid MpMaterialUploadPermanentReqVO reqVO) throws IOException { MpMaterialDO material = mpMaterialService.uploadPermanentMaterial(reqVO); return success(MpMaterialConvert.INSTANCE.convert(material)); } + @ApiOperation("删除素材") + @DeleteMapping("/delete-permanent") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('mp:material:delete')") + public CommonResult deleteMaterial(@RequestParam("id") Long id) { + mpMaterialService.deleteMaterial(id); + return success(true); + } + @ApiOperation("上传图文内容中的图片") @PostMapping("/upload-news-image") + @PreAuthorize("@ss.hasPermission('mp:material:upload-news-image')") public CommonResult uploadNewsImage(@Valid MpMaterialUploadNewsImageReqVO reqVO) throws IOException { return success(mpMaterialService.uploadNewsImage(reqVO)); @@ -56,10 +65,10 @@ public class MpMaterialController { @ApiOperation("获得素材分页") @GetMapping("/page") + @PreAuthorize("@ss.hasPermission('mp:material:query')") public CommonResult> getMaterialPage(@Valid MpMaterialPageReqVO pageReqVO) { PageResult pageResult = mpMaterialService.getMaterialPage(pageReqVO); return success(MpMaterialConvert.INSTANCE.convertPage(pageResult)); } - } 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 dc43bc926..ca3c6b3a9 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 @@ -22,7 +22,8 @@ public interface MpMaterialMapper extends BaseMapperX { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eq(MpMaterialDO::getAccountId, pageReqVO.getAccountId()) .eqIfPresent(MpMaterialDO::getPermanent, pageReqVO.getPermanent()) - .eqIfPresent(MpMaterialDO::getType, pageReqVO.getType())); + .eqIfPresent(MpMaterialDO::getType, pageReqVO.getType()) + .orderByDesc(MpMaterialDO::getId)); } default List selectListByMediaId(Collection mediaIds) { diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialService.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialService.java index 2275795ba..60e4c07b4 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialService.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialService.java @@ -74,4 +74,11 @@ public interface MpMaterialService { */ List getMaterialListByMediaId(Collection mediaIds); + /** + * 删除素材 + * + * @param id 编号 + */ + void deleteMaterial(Long id); + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialServiceImpl.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialServiceImpl.java index 57da3e353..9e48a8f97 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialServiceImpl.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/material/MpMaterialServiceImpl.java @@ -32,8 +32,7 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MATERIAL_IMAGE_UPLOAD_FAIL; -import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.MATERIAL_UPLOAD_FAIL; +import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.*; /** * 公众号素材 Service 接口 @@ -172,6 +171,27 @@ public class MpMaterialServiceImpl implements MpMaterialService { return mpMaterialMapper.selectListByMediaId(mediaIds); } + @Override + public void deleteMaterial(Long id) { + MpMaterialDO material = mpMaterialMapper.selectById(id); + if (material == null) { + throw exception(MATERIAL_NOT_EXISTS); + } + + // 第一步,从公众号删除 + if (material.getPermanent()) { + WxMpService mpService = mpServiceFactory.getRequiredMpService(material.getAppId()); + try { + mpService.getMaterialService().materialDelete(material.getMediaId()); + } catch (WxErrorException e) { + throw exception(MATERIAL_DELETE_FAIL, e.getError().getErrorMsg()); + } + } + + // 第二步,从数据库中删除 + mpMaterialMapper.deleteById(id); + } + /** * 下载微信媒体文件的内容,并上传到文件服务 * diff --git a/yudao-ui-admin/src/api/mp/material.js b/yudao-ui-admin/src/api/mp/material.js index 03662f906..7bdcc31d8 100644 --- a/yudao-ui-admin/src/api/mp/material.js +++ b/yudao-ui-admin/src/api/mp/material.js @@ -8,3 +8,11 @@ export function getMaterialPage(query) { params: query }) } + +// 删除公众号永久素材 +export function deletePermanentMaterial(id) { + return request({ + url: '/mp/material/delete-permanent?id=' + id, + method: 'delete' + }) +} 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 137824dd6..0fb8de19d 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 @@ -19,9 +19,6 @@ -
- 暂无数据 -
@@ -92,9 +89,6 @@ -
- 暂无数据 -
diff --git a/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue b/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue index a6ccdb5ec..6b8c80fc4 100644 --- a/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue +++ b/yudao-ui-admin/src/views/mp/components/wx-reply/main.vue @@ -235,7 +235,7 @@ "title":'', "introduction":'' }, - actionUrl: process.env.VUE_APP_BASE_API +'/admin-api/mp/material/upload-temporary', + actionUrl: process.env.VUE_APP_BASE_API + '/admin-api/mp/material/upload-temporary', headers: { Authorization: "Bearer " + getAccessToken() }, // 设置上传的请求头部 } }, @@ -279,7 +279,7 @@ this.uploadData.accountId = this.objData.accountId; return true; }, - beforeImageUpload(file){ + beforeImageUpload(file) { // 校验格式 const isType = file.type === 'image/jpeg' || file.type === 'image/png' diff --git a/yudao-ui-admin/src/views/mp/draft/index.vue b/yudao-ui-admin/src/views/mp/draft/index.vue index dcac01487..3439b1f6e 100644 --- a/yudao-ui-admin/src/views/mp/draft/index.vue +++ b/yudao-ui-admin/src/views/mp/draft/index.vue @@ -64,9 +64,6 @@ SOFTWARE. -
- 暂无数据 -
@@ -218,7 +215,6 @@ export default { this.accounts = response.data; // 默认选中第一个 if (this.accounts.length > 0) { - this.queryParams.accountId = this.accounts[0].id; this.setAccountId(this.accounts[0].id); } // 加载数据 @@ -241,7 +237,7 @@ export default { } this.loading = true - getDraftPage((this.queryParams)).then(response => { + getDraftPage(this.queryParams).then(response => { // 将 thumbUrl 转成 picUrl,保证 wx-news 组件可以预览封面 response.data.list.forEach(item => { const newsItem = item.content.newsItem; diff --git a/yudao-ui-admin/src/views/mp/freePublish/index.vue b/yudao-ui-admin/src/views/mp/freePublish/index.vue index 7db3663cd..03c90c8be 100644 --- a/yudao-ui-admin/src/views/mp/freePublish/index.vue +++ b/yudao-ui-admin/src/views/mp/freePublish/index.vue @@ -51,9 +51,6 @@ SOFTWARE. -
- 暂无数据 -
diff --git a/yudao-ui-admin/src/views/mp/material/index.vue b/yudao-ui-admin/src/views/mp/material/index.vue new file mode 100644 index 000000000..a46b3daa6 --- /dev/null +++ b/yudao-ui-admin/src/views/mp/material/index.vue @@ -0,0 +1,502 @@ + + + + + +