Commit 27b15d8b by xugaojun

【11-2迭代-[素材库默认查询全部分组]】:代码实现

parent f9f42fc5
...@@ -277,7 +277,13 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -277,7 +277,13 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Override @Override
public Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId, public Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId,
Integer materialType, BasePageInfo pageInfo) { Integer materialType, BasePageInfo pageInfo) {
List<String> categoryIds = this.listSubCategoryIdsByParentId(categoryId); List<String> categoryIds;
if ("-1".equals(categoryId)) {
// 传入-1默认查询全部
categoryIds = Collections.emptyList();
} else {
categoryIds = this.listSubCategoryIdsByParentId(categoryId);
}
PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize()); PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
com.github.pagehelper.Page<TabHaobanMaterial> page = materialService.listMaterial(wxEnterpriseId, keyword, categoryIds, materialType); com.github.pagehelper.Page<TabHaobanMaterial> page = materialService.listMaterial(wxEnterpriseId, keyword, categoryIds, materialType);
List<TabHaobanMaterial> result = page.getResult(); List<TabHaobanMaterial> result = page.getResult();
...@@ -389,23 +395,23 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -389,23 +395,23 @@ public class MaterialApiServiceImpl implements MaterialApiService {
if (enterprise == null) { if (enterprise == null) {
return; return;
} }
List<BatchAddMaterialDTO.MaterialMedia> materialMediaList = dto.getMaterialMediaList(); List<BatchAddMaterialDTO.MaterialMedia> materialMediaList = dto.getMaterialMediaList();
if (CollectionUtils.isEmpty(materialMediaList)) { if (CollectionUtils.isEmpty(materialMediaList)) {
return; return;
} }
List<MaterialDTO> materialList = materialMediaList.stream().map(one -> { List<MaterialDTO> materialList = materialMediaList.stream().map(one -> {
MaterialDTO materialDTO = new MaterialDTO(); MaterialDTO materialDTO = new MaterialDTO();
// 必填字段 // 必填字段
materialDTO.setCreateTime(new Date()); materialDTO.setCreateTime(new Date());
materialDTO.setUpdateTime(materialDTO.getCreateTime()); materialDTO.setUpdateTime(materialDTO.getCreateTime());
materialDTO.setStatusFlag(1); materialDTO.setStatusFlag(1);
materialDTO.setMaterialId(StringUtil.randomUUID()); materialDTO.setMaterialId(StringUtil.randomUUID());
// 传入字段 // 传入字段
materialDTO.setCategoryId(material.getCategoryId()); materialDTO.setCategoryId(material.getCategoryId());
materialDTO.setMaterialType(material.getMaterialType()); materialDTO.setMaterialType(material.getMaterialType());
materialDTO.setWxEnterpriseId(material.getWxEnterpriseId()); materialDTO.setWxEnterpriseId(material.getWxEnterpriseId());
materialDTO.setStaffId(material.getStaffId()); materialDTO.setStaffId(material.getStaffId());
materialDTO.setStaffName(material.getStaffName()); materialDTO.setStaffName(material.getStaffName());
// 图片类型素材标题为图片实际名称 // 图片类型素材标题为图片实际名称
if (material.getMaterialType() == 2) { if (material.getMaterialType() == 2) {
materialDTO.setMaterialTitle(one.getMediaName()); materialDTO.setMaterialTitle(one.getMediaName());
...@@ -414,26 +420,26 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -414,26 +420,26 @@ public class MaterialApiServiceImpl implements MaterialApiService {
} }
materialDTO.setImgUrl(one.getMediaUrl()); materialDTO.setImgUrl(one.getMediaUrl());
String mediaId = uploadMediaToWx(enterprise.getCorpid(), one.getMediaUrl()); String mediaId = uploadMediaToWx(enterprise.getCorpid(), one.getMediaUrl());
if (StringUtils.isNotEmpty(mediaId)) { if (StringUtils.isNotEmpty(mediaId)) {
materialDTO.setWxLastUploadTime(new Date()); materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(mediaId); materialDTO.setMediaId(mediaId);
} }
return materialDTO; return materialDTO;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
// batch-insert // batch-insert
materialService.batchInsertMaterial(materialList); materialService.batchInsertMaterial(materialList);
} }
private String uploadMediaToWx(String corPid, String url) { private String uploadMediaToWx(String corPid, String url) {
String[] arr = url.split("/"); String[] arr = url.split("/");
// 先写死为图片类型, 以后有别的再扩展 // 先写死为图片类型, 以后有别的再扩展
QywxMediaTypeEnum fileType = QywxMediaTypeEnum.IMAGE; QywxMediaTypeEnum fileType = QywxMediaTypeEnum.IMAGE;
int count = arr.length; int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(corPid, config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode()); JSONResponse jp = qywxSuiteApiService.uploadMedia(corPid, config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) { if (jp.getErrorCode() == 0) {
return jp.getResult().toString(); return jp.getResult().toString();
} }
return null; return null;
} }
} }
package com.gic.haoban.manage.web.controller; package com.gic.haoban.manage.web.controller;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.commons.util.DateUtil; import com.gic.commons.util.DateUtil;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
...@@ -26,71 +12,101 @@ import com.gic.haoban.manage.api.dto.MaterialDTO; ...@@ -26,71 +12,101 @@ import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.service.MaterialApiService; import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode; import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import com.gic.haoban.manage.web.vo.MaterialVO; import com.gic.haoban.manage.web.vo.MaterialVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController @RestController
public class MaterialController extends WebBaseController{ public class MaterialController extends WebBaseController {
private static Logger logger = LoggerFactory.getLogger(MaterialController.class); private static Logger logger = LoggerFactory.getLogger(MaterialController.class);
@Autowired @Autowired
private MaterialApiService materialApiService; private MaterialApiService materialApiService;
/**
* 素材查询 /**
* @return * desc: 分页查询素材
*
* @param wxEnterpriseId 企业微信id
* @param keyword 素材标题
* @param categoryId 分类id
* @param materialType 素材类型
* @param pageInfo 分页参数
* @return : {@link HaobanResponse}
* @author : YongEn
* @date : 2021/11/18
*/ */
@RequestMapping("/material-list") @RequestMapping("/material-list")
public HaobanResponse materialList(String wxEnterpriseId,String keyword,String categoryId,Integer materialType,BasePageInfo pageInfo) { public HaobanResponse materialList(String wxEnterpriseId,
Page<MaterialDTO> page = materialApiService.listMaterial(wxEnterpriseId,keyword,categoryId,materialType,pageInfo); String keyword,
//暂时转换 String categoryId,
Integer materialType,
BasePageInfo pageInfo) {
Page<MaterialDTO> page = materialApiService.listMaterial(wxEnterpriseId, keyword, categoryId, materialType, pageInfo);
//暂时转换
PageResult2 pageResult2 = PageUtil.getPageInfo(page); PageResult2 pageResult2 = PageUtil.getPageInfo(page);
return resultResponse(HaoBanErrCode.ERR_1, pageResult2); return resultResponse(HaoBanErrCode.ERR_1, pageResult2);
} }
/** /**
* 素材查询 * 素材查询
*
* @return * @return
*/ */
@RequestMapping("/material-type") @RequestMapping("/material-type")
public HaobanResponse materialType(String wxEnterpriseId) { public HaobanResponse materialType(String wxEnterpriseId) {
List<MaterialCategoryDTO> list = materialApiService.listCategory(wxEnterpriseId); List<MaterialCategoryDTO> list = materialApiService.listCategory(wxEnterpriseId);
List<MaterialVO> handerList = new ArrayList<MaterialVO>(); List<MaterialVO> handerList = new ArrayList<MaterialVO>();
MaterialVO vo = new MaterialVO(); MaterialVO vo = new MaterialVO();
vo.setCategoryId("-1"); // 默认给-1位全部分组标准-查询列表时如果传入-1默认查询全部素材
vo.setCategoryName("未分组"); vo.setCategoryId("-1");
vo.setCategoryParentId("0"); vo.setCategoryName("全部分组");
vo.setWxEnterpriseId(wxEnterpriseId); vo.setCategoryParentId("0");
handerList.add(vo); vo.setWxEnterpriseId(wxEnterpriseId);
for (MaterialCategoryDTO materialCategoryDTO : list) { handerList.add(vo);
if("0".equals(materialCategoryDTO.getCategoryParentId())){ for (MaterialCategoryDTO materialCategoryDTO : list) {
handerList.add(EntityUtil.changeEntityByJSON(MaterialVO.class, materialCategoryDTO)); if ("0".equals(materialCategoryDTO.getCategoryParentId())) {
} handerList.add(EntityUtil.changeEntityByJSON(MaterialVO.class, materialCategoryDTO));
} }
Map<String,List<MaterialCategoryDTO>> map = list.stream().collect(Collectors.groupingBy(MaterialCategoryDTO::getCategoryParentId)); }
handerSonMaterial(handerList, map); Map<String, List<MaterialCategoryDTO>> map = list.stream().collect(Collectors.groupingBy(MaterialCategoryDTO::getCategoryParentId));
for (MaterialVO materialVO : handerList) { handerSonMaterial(handerList, map);
List<MaterialVO> sonVoList = materialVO.getList(); for (MaterialVO materialVO : handerList) {
if(sonVoList != null && !sonVoList.isEmpty()){ List<MaterialVO> sonVoList = materialVO.getList();
handerSonMaterial(sonVoList, map); if (sonVoList != null && !sonVoList.isEmpty()) {
} handerSonMaterial(sonVoList, map);
} }
return resultResponse(HaoBanErrCode.ERR_1,handerList); }
return resultResponse(HaoBanErrCode.ERR_1, handerList);
} }
/** /**
* 素材查询 * 素材查询
*
* @return * @return
*/ */
@RequestMapping("/reupdalod-material") @RequestMapping("/reupdalod-material")
public HaobanResponse reUpdalodMetail(String materialId) { public HaobanResponse reUpdalodMetail(String materialId) {
if(StringUtils.isBlank(materialId)){ if (StringUtils.isBlank(materialId)) {
return resultResponse(HaoBanErrCode.ERR_10015); return resultResponse(HaoBanErrCode.ERR_10015);
} }
MaterialDTO material = materialApiService.selectMaterialById(materialId); MaterialDTO material = materialApiService.selectMaterialById(materialId);
if(material == null){ if (material == null) {
} }
String medialId = ""; String medialId = "";
if(material.getMaterialType() == 2 || material.getMaterialType() == 4 || material.getMaterialType() == 5){ if (material.getMaterialType() == 2 || material.getMaterialType() == 4 || material.getMaterialType() == 5) {
if (material.getMediaId() == null) { if (material.getMediaId() == null) {
medialId = materialApiService.reUpdalodMetail(materialId); medialId = materialApiService.reUpdalodMetail(materialId);
} else { } else {
...@@ -100,21 +116,21 @@ public class MaterialController extends WebBaseController{ ...@@ -100,21 +116,21 @@ public class MaterialController extends WebBaseController{
medialId = materialApiService.reUpdalodMetail(materialId); medialId = materialApiService.reUpdalodMetail(materialId);
} }
} }
} }
return resultResponse(HaoBanErrCode.ERR_1,medialId); return resultResponse(HaoBanErrCode.ERR_1, medialId);
} }
private void handerSonMaterial(List<MaterialVO> handerList,Map<String,List<MaterialCategoryDTO>> map){ private void handerSonMaterial(List<MaterialVO> handerList, Map<String, List<MaterialCategoryDTO>> map) {
for (MaterialVO materialVO : handerList) { for (MaterialVO materialVO : handerList) {
List<MaterialCategoryDTO> sonList = map.get(materialVO.getCategoryId()); List<MaterialCategoryDTO> sonList = map.get(materialVO.getCategoryId());
List<MaterialVO> sonVoList = EntityUtil.changeEntityListByJSON(MaterialVO.class, sonList); List<MaterialVO> sonVoList = EntityUtil.changeEntityListByJSON(MaterialVO.class, sonList);
materialVO.setList(sonVoList); materialVO.setList(sonVoList);
// logger.info("map={},handerList={},categoryId={},sonVoList={}",JSON.toJSONString(map),JSON.toJSONString(handerList),materialVO.getCategoryId(),JSON.toJSONString(sonVoList)); // logger.info("map={},handerList={},categoryId={},sonVoList={}",JSON.toJSONString(map),JSON.toJSONString(handerList),materialVO.getCategoryId(),JSON.toJSONString(sonVoList));
// while(sonVoList != null && sonVoList.size() > 0){ // while(sonVoList != null && sonVoList.size() > 0){
// handerSonMaterial(sonVoList, map); // handerSonMaterial(sonVoList, map);
// } // }
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment