mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-25 00:15:06 +08:00
mp:增加【图片】素材的选择
This commit is contained in:
@ -0,0 +1,5 @@
|
||||
### 请求 /mp/material/page 接口 => 成功
|
||||
GET {{baseUrl}}/mp/material/page?permanent=true&pageNo=1&pageSize=10
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {{token}}
|
||||
tenant-id: {{adminTenentId}}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.material;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadPermanentReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadRespVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadTemporaryReqVO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.*;
|
||||
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.ApiOperation;
|
||||
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;
|
||||
@ -45,4 +45,11 @@ public class MpMaterialController {
|
||||
return success(MpMaterialConvert.INSTANCE.convert(material));
|
||||
}
|
||||
|
||||
@ApiOperation("获得素材分页")
|
||||
@GetMapping("/page")
|
||||
public CommonResult<PageResult<MpMaterialRespVO>> getMaterialPage(@Valid MpMaterialPageReqVO pageReqVO) {
|
||||
PageResult<MpMaterialDO> pageResult = mpMaterialService.getMaterialPage(pageReqVO);
|
||||
return success(MpMaterialConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.material.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@ApiModel("管理后台 - 公众号素材的分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class MpMaterialPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "是否永久", example = "true")
|
||||
private Boolean permanent;
|
||||
|
||||
@ApiModelProperty(value = "文件类型", example = "image", notes = "参见 WxConsts.MediaFileType 枚举")
|
||||
private String type;
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.material.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("管理后台 - 公众号素材 Response VO")
|
||||
@Data
|
||||
public class MpMaterialRespVO {
|
||||
|
||||
@ApiModelProperty(value = "主键", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "公众号账号的编号", required = true, example = "1")
|
||||
private Long accountId;
|
||||
@ApiModelProperty(value = "公众号账号的 appId", required = true, example = "wx1234567890")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "素材的 media_id", required = true, example = "123")
|
||||
private String mediaId;
|
||||
|
||||
@ApiModelProperty(value = "文件类型", required = true, example = "image", notes = "参见 WxConsts.MediaFileType 枚举")
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "是否永久", required = true, example = "true", notes = "true - 永久;false - 临时")
|
||||
private Boolean permanent;
|
||||
|
||||
@ApiModelProperty(value = "素材的 URL", required = true, example = "https://www.iocoder.cn/1.png")
|
||||
private String url;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "名字", example = "yunai.png")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "公众号文件 URL", example = "https://mmbiz.qpic.cn/xxx.mp3", notes = "只有【永久素材】使用")
|
||||
private String mpUrl;
|
||||
|
||||
@ApiModelProperty(value = "视频素材的标题", example = "我是标题", notes = "只有【永久素材】使用")
|
||||
private String title;
|
||||
@ApiModelProperty(value = "视频素材的描述", example = "我是介绍", notes = "只有【永久素材】使用")
|
||||
private String introduction;
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.mp.convert.material;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialRespVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadRespVO;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.material.MpMaterialDO;
|
||||
@ -20,8 +22,10 @@ public interface MpMaterialConvert {
|
||||
@Mapping(target = "id", ignore = true),
|
||||
@Mapping(source = "account.id", target = "accountId"),
|
||||
@Mapping(source = "account.appId", target = "appId"),
|
||||
@Mapping(source = "name", target = "name")
|
||||
})
|
||||
MpMaterialDO convert(String mediaId, String type, String url, MpAccountDO account);
|
||||
MpMaterialDO convert(String mediaId, String type, String url, MpAccountDO account,
|
||||
String name);
|
||||
|
||||
@Mappings({
|
||||
@Mapping(target = "id", ignore = true),
|
||||
@ -38,4 +42,6 @@ public interface MpMaterialConvert {
|
||||
return new WxMpMaterial(name, file, title, introduction);
|
||||
}
|
||||
|
||||
PageResult<MpMaterialRespVO> convertPage(PageResult<MpMaterialDO> page);
|
||||
|
||||
}
|
||||
|
@ -69,9 +69,13 @@ public class MpMaterialDO extends BaseDO {
|
||||
/**
|
||||
* 名字
|
||||
*
|
||||
* 只有【永久素材】使用
|
||||
* 永久素材:非空
|
||||
* 临时素材:可能为空。
|
||||
* 1. 为空的情况:用户主动发送的图片、语音等
|
||||
* 2. 非空的情况:主动发送给用户的图片、语音等
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 公众号文件 URL
|
||||
*
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.iocoder.yudao.module.mp.dal.mysql.material;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialPageReqVO;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.material.MpMaterialDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@ -12,4 +15,10 @@ public interface MpMaterialMapper extends BaseMapperX<MpMaterialDO> {
|
||||
MpMaterialDO::getMediaId, mediaId);
|
||||
}
|
||||
|
||||
default PageResult<MpMaterialDO> selectPage(MpMaterialPageReqVO pageReqVO) {
|
||||
return selectPage(pageReqVO, new LambdaQueryWrapperX<MpMaterialDO>()
|
||||
.eqIfPresent(MpMaterialDO::getPermanent, pageReqVO.getPermanent())
|
||||
.eqIfPresent(MpMaterialDO::getType, pageReqVO.getType()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.iocoder.yudao.module.mp.service.material;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialPageReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadPermanentReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadTemporaryReqVO;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.material.MpMaterialDO;
|
||||
@ -45,4 +47,12 @@ public interface MpMaterialService {
|
||||
*/
|
||||
MpMaterialDO uploadPermanentMaterial(@Valid MpMaterialUploadPermanentReqVO reqVO) throws IOException;
|
||||
|
||||
/**
|
||||
* 获得素材分页
|
||||
*
|
||||
* @param pageReqVO 分页请求
|
||||
* @return 素材分页
|
||||
*/
|
||||
PageResult<MpMaterialDO> getMaterialPage(MpMaterialPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ import cn.hutool.core.io.FileTypeUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialPageReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadPermanentReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.material.vo.MpMaterialUploadTemporaryReqVO;
|
||||
import cn.iocoder.yudao.module.mp.convert.material.MpMaterialConvert;
|
||||
@ -67,7 +69,7 @@ public class MpMaterialServiceImpl implements MpMaterialService {
|
||||
return null;
|
||||
}
|
||||
MpAccountDO account = mpAccountService.getRequiredAccount(accountId);
|
||||
material = MpMaterialConvert.INSTANCE.convert(mediaId, type, url, account)
|
||||
material = MpMaterialConvert.INSTANCE.convert(mediaId, type, url, account, null)
|
||||
.setPermanent(false);
|
||||
mpMaterialMapper.insert(material);
|
||||
|
||||
@ -100,8 +102,8 @@ public class MpMaterialServiceImpl implements MpMaterialService {
|
||||
|
||||
// 第二步,存储到数据库
|
||||
MpAccountDO account = mpAccountService.getRequiredAccount(reqVO.getAccountId());
|
||||
MpMaterialDO material = MpMaterialConvert.INSTANCE.convert(mediaId, reqVO.getType(), url, account)
|
||||
.setPermanent(false);
|
||||
MpMaterialDO material = MpMaterialConvert.INSTANCE.convert(mediaId, reqVO.getType(), url, account,
|
||||
reqVO.getFile().getName()).setPermanent(false);
|
||||
mpMaterialMapper.insert(material);
|
||||
return material;
|
||||
}
|
||||
@ -139,6 +141,11 @@ public class MpMaterialServiceImpl implements MpMaterialService {
|
||||
return material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<MpMaterialDO> getMaterialPage(MpMaterialPageReqVO pageReqVO) {
|
||||
return mpMaterialMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载微信媒体文件的内容,并上传到文件服务
|
||||
*
|
||||
|
Reference in New Issue
Block a user