Commit cd5e0eb7 by xugaojun

【3.0】11-1迭代:素材库支持添加多张图片实现

parent eeb3a234
package com.gic.haoban.manage.api.dto;
import java.io.Serializable;
import java.util.List;
/**
* desc:批量新增素材请求类
*
* @author: YongEn
* @date: 2021/11/8
**/
public class BatchAddMaterialDTO implements Serializable {
private static final long serialVersionUID = 4485943179748351877L;
/**
* 素材主要信息
*/
private Material material;
/**
* 素材媒体信息列表
*/
private List<MaterialMedia> materialMediaList;
public Material getMaterial() {
return material;
}
public void setMaterial(Material material) {
this.material = material;
}
public List<MaterialMedia> getMaterialMediaList() {
return materialMediaList;
}
public void setMaterialMediaList(List<MaterialMedia> materialMediaList) {
this.materialMediaList = materialMediaList;
}
@Override
public String toString() {
return "BatchAddMaterialDTO{" +
"material=" + material +
", materialMediaList=" + materialMediaList +
'}';
}
/**
* 素材主要信息
*/
public static class Material implements Serializable {
private static final long serialVersionUID = 5186039465841424394L;
/**
* 素材标题
*/
private String materialTitle;
/**
* 素材类型
* 素材类型, 1文本, 2图片, 3网页, 4视频, 5文件,6小程序
*/
private Integer materialType;
/**
* 素材分类id
*/
private String categoryId;
/**
* 企业微信id
*/
private String wxEnterpriseId;
/**
* 员工id
*/
private String staffId;
/**
* 员工姓名
*/
private String staffName;
public String getMaterialTitle() {
return materialTitle;
}
public void setMaterialTitle(String materialTitle) {
this.materialTitle = materialTitle;
}
public Integer getMaterialType() {
return materialType;
}
public void setMaterialType(Integer materialType) {
this.materialType = materialType;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
public String getWxEnterpriseId() {
return wxEnterpriseId;
}
public void setWxEnterpriseId(String wxEnterpriseId) {
this.wxEnterpriseId = wxEnterpriseId;
}
public String getStaffId() {
return staffId;
}
public void setStaffId(String staffId) {
this.staffId = staffId;
}
public String getStaffName() {
return staffName;
}
public void setStaffName(String staffName) {
this.staffName = staffName;
}
}
/**
* 素材媒体信息
*/
public static class MaterialMedia implements Serializable {
private static final long serialVersionUID = -6540716764890860601L;
/**
* 素材路径
*/
String url;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
}
package com.gic.haoban.manage.api.service; package com.gic.haoban.manage.api.service;
import java.util.List;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.ServiceResponse; import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import java.util.List;
public interface MaterialApiService { public interface MaterialApiService {
boolean hasCategoryNameExsit(String categoryName, String categoryParentId,String categoryId); boolean hasCategoryNameExsit(String categoryName, String categoryParentId, String categoryId);
void insertCategory(MaterialCategoryDTO materialCategoryDTO); void insertCategory(MaterialCategoryDTO materialCategoryDTO);
List<MaterialCategoryDTO> listCategory(String wxEnterpriseId); List<MaterialCategoryDTO> listCategory(String wxEnterpriseId);
MaterialCategoryDTO selectMaterialCategoryById(String categoryId); MaterialCategoryDTO selectMaterialCategoryById(String categoryId);
void editCategory(MaterialCategoryDTO materialCategoryDTO); void editCategory(MaterialCategoryDTO materialCategoryDTO);
List<MaterialDTO> listMaterialByCategoryId(String categoryId); List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertMaterial(MaterialDTO materialDTO); void insertMaterial(MaterialDTO materialDTO);
MaterialDTO selectMaterialById(String materialId); MaterialDTO selectMaterialById(String materialId);
List<MaterialDTO> listMaterialByIds(List<String> materialIds); List<MaterialDTO> listMaterialByIds(List<String> materialIds);
void editMaterial(MaterialDTO materialDTO); void editMaterial(MaterialDTO materialDTO);
Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId, Integer materialType,BasePageInfo pageInfo); Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId, Integer materialType, BasePageInfo pageInfo);
String reUpdalodMetail(String materialId); String reUpdalodMetail(String materialId);
List<MaterialCategoryDTO> listByParentCategory(String categoryId); List<MaterialCategoryDTO> listByParentCategory(String categoryId);
/** /**
* 分析素材 * 分析素材
...@@ -45,19 +46,19 @@ public interface MaterialApiService { ...@@ -45,19 +46,19 @@ public interface MaterialApiService {
*/ */
ServiceResponse<Void> shareMaterial(String wxEnterpriseId, String toWxEnterpriseId, String materialId); ServiceResponse<Void> shareMaterial(String wxEnterpriseId, String toWxEnterpriseId, String materialId);
/** /**
* 素材关联的已分配企业 * 素材关联的已分配企业
* *
* @param materialId * @param materialId
*/ */
List<MaterialDTO> listByFromMaterialId(String materialId); List<MaterialDTO> listByFromMaterialId(String materialId);
/** /**
* 删除 * 删除
* *
* @param ids * @param ids
*/ */
void delMaterial(List<String> ids); void delMaterial(List<String> ids);
/** /**
* 自动刷新madiaid的 获取素材 * 自动刷新madiaid的 获取素材
...@@ -67,4 +68,12 @@ public interface MaterialApiService { ...@@ -67,4 +68,12 @@ public interface MaterialApiService {
*/ */
MaterialDTO getHasChangeMadieMaterialById(String materialId); MaterialDTO getHasChangeMadieMaterialById(String materialId);
/**
* 批量新增素材
*
* @param dto dto
* @author: YongEn
*/
void batchInsertMaterial(BatchAddMaterialDTO dto);
} }
package com.gic.haoban.manage.service.dao.mapper; package com.gic.haoban.manage.service.dao.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.gic.haoban.manage.service.entity.TabHaobanMaterial; import com.gic.haoban.manage.service.entity.TabHaobanMaterial;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface TabHaobanMaterialMapper { public interface TabHaobanMaterialMapper {
int deleteByPrimaryKey(String materialId); int deleteByPrimaryKey(String materialId);
int insert(TabHaobanMaterial record); int insert(TabHaobanMaterial record);
int batchInsert(@Param("records") List<TabHaobanMaterial> records);
int insertSelective(TabHaobanMaterial record); int insertSelective(TabHaobanMaterial record);
TabHaobanMaterial selectByPrimaryKey(String materialId); TabHaobanMaterial selectByPrimaryKey(String materialId);
...@@ -22,9 +23,9 @@ public interface TabHaobanMaterialMapper { ...@@ -22,9 +23,9 @@ public interface TabHaobanMaterialMapper {
int updateByPrimaryKey(TabHaobanMaterial record); int updateByPrimaryKey(TabHaobanMaterial record);
List<TabHaobanMaterial> listMaterialByCategoryId(String categoryId); List<TabHaobanMaterial> listMaterialByCategoryId(String categoryId);
Page<TabHaobanMaterial> listMaterial(@Param("wxEnterpriseId")String wxEnterpriseId, @Param("keyword")String keyword, @Param("categoryId")String categoryId, @Param("materialType")Integer materialType); Page<TabHaobanMaterial> listMaterial(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("keyword") String keyword, @Param("categoryId") String categoryId, @Param("materialType") Integer materialType);
List<TabHaobanMaterial> listMaterialByCategoryIds(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("keyword") String keyword, @Param("categoryIds") List<String> categoryIds, @Param("materialType") Integer materialType); List<TabHaobanMaterial> listMaterialByCategoryIds(@Param("wxEnterpriseId") String wxEnterpriseId, @Param("keyword") String keyword, @Param("categoryIds") List<String> categoryIds, @Param("materialType") Integer materialType);
......
package com.gic.haoban.manage.service.service; package com.gic.haoban.manage.service.service;
import java.util.List;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import java.util.List;
public interface MaterialService { public interface MaterialService {
List<MaterialDTO> listMaterialByCategoryId(String categoryId); List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertMaterial(MaterialDTO materialDTO); void insertMaterial(MaterialDTO materialDTO);
void batchInsertMaterial(List<MaterialDTO> materialList);
MaterialDTO selectMaterialById(String materialId); MaterialDTO selectMaterialById(String materialId);
List<MaterialDTO> listMaterialByIds(List<String> materialIds); List<MaterialDTO> listMaterialByIds(List<String> materialIds);
......
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.gic.haoban.common.utils.EntityUtil; import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.StringUtil; import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
...@@ -15,6 +7,11 @@ import com.gic.haoban.manage.service.dao.mapper.TabHaobanMaterialMapper; ...@@ -15,6 +7,11 @@ import com.gic.haoban.manage.service.dao.mapper.TabHaobanMaterialMapper;
import com.gic.haoban.manage.service.entity.TabHaobanMaterial; import com.gic.haoban.manage.service.entity.TabHaobanMaterial;
import com.gic.haoban.manage.service.service.MaterialService; import com.gic.haoban.manage.service.service.MaterialService;
import com.github.pagehelper.Page; import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service @Service
public class MaterialServiceImpl implements MaterialService { public class MaterialServiceImpl implements MaterialService {
...@@ -38,6 +35,11 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -38,6 +35,11 @@ public class MaterialServiceImpl implements MaterialService {
} }
@Override @Override
public void batchInsertMaterial(List<MaterialDTO> materialList) {
mapper.batchInsert(EntityUtil.changeEntityListByOrika(TabHaobanMaterial.class, materialList));
}
@Override
public MaterialDTO selectMaterialById(String materialId) { public MaterialDTO selectMaterialById(String materialId) {
return EntityUtil.changeEntityByJSON(MaterialDTO.class, mapper.selectByPrimaryKey(materialId)); return EntityUtil.changeEntityByJSON(MaterialDTO.class, mapper.selectByPrimaryKey(materialId));
} }
......
package com.gic.haoban.manage.service.service.out.impl; package com.gic.haoban.manage.service.service.out.impl;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.service.entity.TabMiniprogramSetting;
import com.gic.haoban.manage.service.service.MiniprogramSettingService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse; import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.Page; import com.gic.api.base.commons.Page;
import com.gic.commons.util.GlobalInfo;
import com.gic.commons.util.GlobalVar;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.common.utils.PageUtil; import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.DepartmentDTO; import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO; import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO; import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.service.MaterialApiService; import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.service.config.Config; import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.entity.TabHaobanMaterial; import com.gic.haoban.manage.service.entity.TabHaobanMaterial;
import com.gic.haoban.manage.service.entity.TabMiniprogramSetting;
import com.gic.haoban.manage.service.service.MaterialCategoryService; import com.gic.haoban.manage.service.service.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService; import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.MiniprogramSettingService;
import com.gic.haoban.manage.service.service.WxEnterpriseService; import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.thirdparty.api.dto.PicUploadResDTO;
import com.gic.wechat.api.enums.QywxMediaTypeEnum; import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService; import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;
@Service @Service
public class MaterialApiServiceImpl implements MaterialApiService { public class MaterialApiServiceImpl implements MaterialApiService {
@Autowired @Autowired
private MaterialCategoryService materialCategoryService; private MaterialCategoryService materialCategoryService;
@Autowired @Autowired
private MaterialService materialService; private MaterialService materialService;
@Autowired @Autowired
private QywxSuiteApiService qywxSuiteApiService; private QywxSuiteApiService qywxSuiteApiService;
@Autowired @Autowired
private WxEnterpriseService wxEnterpriseService; private WxEnterpriseService wxEnterpriseService;
@Autowired @Autowired
private Config config; private Config config;
@Autowired @Autowired
private MiniprogramSettingService miniprogramSettingService; private MiniprogramSettingService miniprogramSettingService;
private static Logger logger = LoggerFactory.getLogger(MaterialApiServiceImpl.class); private static Logger logger = LoggerFactory.getLogger(MaterialApiServiceImpl.class);
@Override @Override
public boolean hasCategoryNameExsit(String categoryName, String categoryParentId,String categoryId) { public boolean hasCategoryNameExsit(String categoryName, String categoryParentId, String categoryId) {
MaterialCategoryDTO category = materialCategoryService.hasCategoryNameExsit(categoryName,categoryParentId); MaterialCategoryDTO category = materialCategoryService.hasCategoryNameExsit(categoryName, categoryParentId);
if(category != null){ if (category != null) {
if(category.getCategoryId().equals(categoryId)){ if (category.getCategoryId().equals(categoryId)) {
return false; return false;
} } else {
else{ return true;
return true; }
} }
} return false;
return false;
}
@Override }
public void insertCategory(MaterialCategoryDTO materialCategoryDTO) {
materialCategoryService.insert(materialCategoryDTO);
}
@Override @Override
public List<MaterialCategoryDTO> listCategory(String wxEnterpriseId) { public void insertCategory(MaterialCategoryDTO materialCategoryDTO) {
return materialCategoryService.listCategory(wxEnterpriseId); materialCategoryService.insert(materialCategoryDTO);
}
@Override }
public MaterialCategoryDTO selectMaterialCategoryById(String categoryId) {
return materialCategoryService.selectMaterialCategoryById(categoryId);
}
@Override @Override
public void editCategory(MaterialCategoryDTO materialCategoryDTO) { public List<MaterialCategoryDTO> listCategory(String wxEnterpriseId) {
materialCategoryService.editCategory(materialCategoryDTO); return materialCategoryService.listCategory(wxEnterpriseId);
}
@Override
} public MaterialCategoryDTO selectMaterialCategoryById(String categoryId) {
return materialCategoryService.selectMaterialCategoryById(categoryId);
}
@Override @Override
public List<MaterialDTO> listMaterialByCategoryId(String categoryId) { public void editCategory(MaterialCategoryDTO materialCategoryDTO) {
return materialService.listMaterialByCategoryId(categoryId); materialCategoryService.editCategory(materialCategoryDTO);
}
@Override
public void insertMaterial(MaterialDTO materialDTO) { }
Integer type = materialDTO.getMaterialType();
String wxEnterpriseId = materialDTO.getWxEnterpriseId(); @Override
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId); public List<MaterialDTO> listMaterialByCategoryId(String categoryId) {
if(type == null){ return materialService.listMaterialByCategoryId(categoryId);
return; }
}
if(enterprise == null){ @Override
return; public void insertMaterial(MaterialDTO materialDTO) {
} Integer type = materialDTO.getMaterialType();
QywxMediaTypeEnum fileType = null; String wxEnterpriseId = materialDTO.getWxEnterpriseId();
String url = ""; WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if(type == 2){ if (type == null) {
fileType = QywxMediaTypeEnum.IMAGE; return;
url = materialDTO.getImgUrl(); }
} if (enterprise == null) {
if(type == 4){ return;
fileType = QywxMediaTypeEnum.VIDEO; }
url = materialDTO.getLink(); QywxMediaTypeEnum fileType = null;
} String url = "";
if(type == 5){ if (type == 2) {
fileType = QywxMediaTypeEnum.FILE; fileType = QywxMediaTypeEnum.IMAGE;
url = materialDTO.getLink(); url = materialDTO.getImgUrl();
} }
if (type == 4) {
fileType = QywxMediaTypeEnum.VIDEO;
url = materialDTO.getLink();
}
if (type == 5) {
fileType = QywxMediaTypeEnum.FILE;
url = materialDTO.getLink();
}
if (type == 6) { if (type == 6) {
fileType = QywxMediaTypeEnum.IMAGE; fileType = QywxMediaTypeEnum.IMAGE;
url = materialDTO.getImgUrl(); url = materialDTO.getImgUrl();
} }
if(type == 3){ if (type == 3) {
String imgUrl = materialDTO.getImgUrl(); String imgUrl = materialDTO.getImgUrl();
logger.info("【上传图片】imgUrl={}",imgUrl); logger.info("【上传图片】imgUrl={}", imgUrl);
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl)); JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl));
logger.info("【上传图片返回】response={}",JSON.toJSONString(response)); logger.info("【上传图片返回】response={}", JSON.toJSONString(response));
String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString(); String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString();
materialDTO.setWxImgUrl(wxImgUrl); materialDTO.setWxImgUrl(wxImgUrl);
} }
if(fileType != null){ if (fileType != null) {
String[] arr = url.split("/"); String[] arr = url.split("/");
int count = arr.length; int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url),arr[count - 1], fileType.getCode()); JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
if(jp.getErrorCode() == 0){ if (jp.getErrorCode() == 0) {
materialDTO.setWxLastUploadTime(new Date()); materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(jp.getResult().toString()); materialDTO.setMediaId(jp.getResult().toString());
materialService.insertMaterial(materialDTO); materialService.insertMaterial(materialDTO);
} }
}else{ } else {
materialService.insertMaterial(materialDTO); materialService.insertMaterial(materialDTO);
} }
} }
@Override @Override
public MaterialDTO selectMaterialById(String materialId) { public MaterialDTO selectMaterialById(String materialId) {
return materialService.selectMaterialById(materialId); return materialService.selectMaterialById(materialId);
} }
@Override @Override
public List<MaterialDTO> listMaterialByIds(List<String> materialIds) { public List<MaterialDTO> listMaterialByIds(List<String> materialIds) {
return materialService.listMaterialByIds(materialIds); return materialService.listMaterialByIds(materialIds);
} }
...@@ -174,118 +169,118 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -174,118 +169,118 @@ public class MaterialApiServiceImpl implements MaterialApiService {
MaterialDTO old = materialService.selectMaterialById(materialId); MaterialDTO old = materialService.selectMaterialById(materialId);
String wxEnterpriseId = old.getWxEnterpriseId(); String wxEnterpriseId = old.getWxEnterpriseId();
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId); WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if(type == null){ if (type == null) {
return; return;
} }
if(enterprise == null){ if (enterprise == null) {
return; return;
} }
QywxMediaTypeEnum fileType = null; QywxMediaTypeEnum fileType = null;
String url = ""; String url = "";
String oldUrl = ""; String oldUrl = "";
if(type == 2){ if (type == 2) {
fileType = QywxMediaTypeEnum.IMAGE; fileType = QywxMediaTypeEnum.IMAGE;
url = materialDTO.getImgUrl(); url = materialDTO.getImgUrl();
oldUrl = old.getImgUrl(); oldUrl = old.getImgUrl();
} }
if(type == 4){ if (type == 4) {
fileType = QywxMediaTypeEnum.VIDEO; fileType = QywxMediaTypeEnum.VIDEO;
url = materialDTO.getLink(); url = materialDTO.getLink();
oldUrl = old.getLink(); oldUrl = old.getLink();
} }
if(type == 5){ if (type == 5) {
fileType = QywxMediaTypeEnum.FILE; fileType = QywxMediaTypeEnum.FILE;
url = materialDTO.getLink(); url = materialDTO.getLink();
oldUrl = old.getLink(); oldUrl = old.getLink();
} }
if(type == 3){ if (type == 3) {
String imgUrl = materialDTO.getImgUrl(); String imgUrl = materialDTO.getImgUrl();
String oldImgUrl = materialDTO.getImgUrl(); String oldImgUrl = materialDTO.getImgUrl();
if(!imgUrl.equals(oldImgUrl)){ if (!imgUrl.equals(oldImgUrl)) {
JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl)); JSONResponse response = qywxSuiteApiService.uploadImage(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(imgUrl));
String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString(); String wxImgUrl = response.getResult() == null ? "" : response.getResult().toString();
materialDTO.setWxImgUrl(wxImgUrl); materialDTO.setWxImgUrl(wxImgUrl);
} }
} }
if(fileType != null && !url.equals(oldUrl)){ if (fileType != null && !url.equals(oldUrl)) {
String[] arr = url.split("/"); String[] arr = url.split("/");
int count = arr.length; int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url),arr[count - 1], fileType.getCode()); JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
if(jp.getErrorCode() == 0){ if (jp.getErrorCode() == 0) {
materialDTO.setWxLastUploadTime(new Date()); materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(jp.getResult().toString()); materialDTO.setMediaId(jp.getResult().toString());
materialService.edit(materialDTO); materialService.edit(materialDTO);
} }
}else{ } else {
materialService.edit(materialDTO); materialService.edit(materialDTO);
} }
} }
@Override @Override
public String reUpdalodMetail(String materialId){ public String reUpdalodMetail(String materialId) {
MaterialDTO old = materialService.selectMaterialById(materialId); MaterialDTO old = materialService.selectMaterialById(materialId);
Integer type = old.getMaterialType(); Integer type = old.getMaterialType();
if(type == null){ if (type == null) {
return ""; return "";
} }
String wxEnterpriseId = old.getWxEnterpriseId(); String wxEnterpriseId = old.getWxEnterpriseId();
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId); WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if(enterprise == null){ if (enterprise == null) {
return ""; return "";
} }
String url = ""; String url = "";
String oldUrl = ""; String oldUrl = "";
QywxMediaTypeEnum fileType = null; QywxMediaTypeEnum fileType = null;
if(type == 2){ if (type == 2) {
fileType = QywxMediaTypeEnum.IMAGE; fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl(); url = old.getImgUrl();
} }
if(type == 4){ if (type == 4) {
fileType = QywxMediaTypeEnum.VIDEO; fileType = QywxMediaTypeEnum.VIDEO;
url = old.getLink(); url = old.getLink();
} }
if(type == 5){ if (type == 5) {
fileType = QywxMediaTypeEnum.FILE; fileType = QywxMediaTypeEnum.FILE;
url = old.getLink(); url = old.getLink();
} else if (type == 6) { } else if (type == 6) {
fileType = QywxMediaTypeEnum.IMAGE; fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl(); url = old.getImgUrl();
} }
String[] arr = url.split("/"); String[] arr = url.split("/");
int count = arr.length; int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url),arr[count - 1], fileType.getCode()); JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
if(jp.getErrorCode() == 0){ if (jp.getErrorCode() == 0) {
old.setWxLastUploadTime(new Date()); old.setWxLastUploadTime(new Date());
old.setMediaId(jp.getResult().toString()); old.setMediaId(jp.getResult().toString());
materialService.edit(old); materialService.edit(old);
} }
return old.getMediaId(); return old.getMediaId();
} }
private List<String> listSubCategoryIdsByParentId(String categoryId) { private List<String> listSubCategoryIdsByParentId(String categoryId) {
List<String> categoryIds = new ArrayList<>(); List<String> categoryIds = new ArrayList<>();
categoryIds.add(categoryId); categoryIds.add(categoryId);
if (StringUtils.isBlank(categoryId)) { if (StringUtils.isBlank(categoryId)) {
return categoryIds; return categoryIds;
} }
List<MaterialCategoryDTO> categoryDTOList = materialCategoryService.listByParentCategory(categoryId); List<MaterialCategoryDTO> categoryDTOList = materialCategoryService.listByParentCategory(categoryId);
if (CollectionUtils.isEmpty(categoryDTOList)) { if (CollectionUtils.isEmpty(categoryDTOList)) {
return categoryIds; return categoryIds;
} }
for (MaterialCategoryDTO categoryDTO : categoryDTOList) { for (MaterialCategoryDTO categoryDTO : categoryDTOList) {
categoryIds.addAll(this.listSubCategoryIdsByParentId(categoryDTO.getCategoryId())); categoryIds.addAll(this.listSubCategoryIdsByParentId(categoryDTO.getCategoryId()));
} }
return categoryIds; return categoryIds;
} }
@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 = 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();
List<TabMiniprogramSetting> settings = miniprogramSettingService.listMiniprogram(wxEnterpriseId); List<TabMiniprogramSetting> settings = miniprogramSettingService.listMiniprogram(wxEnterpriseId);
if (CollectionUtils.isNotEmpty(result) && CollectionUtils.isNotEmpty(settings)) { if (CollectionUtils.isNotEmpty(result) && CollectionUtils.isNotEmpty(settings)) {
Map<String, TabMiniprogramSetting> settingMap = settings.stream().collect(Collectors.toMap(dto -> dto.getAppId(), dto -> dto)); Map<String, TabMiniprogramSetting> settingMap = settings.stream().collect(Collectors.toMap(dto -> dto.getAppId(), dto -> dto));
...@@ -294,73 +289,73 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -294,73 +289,73 @@ public class MaterialApiServiceImpl implements MaterialApiService {
dto.setMaterialDesc(miniprogramSetting == null ? "--" : miniprogramSetting.getMiniprogramName()); dto.setMaterialDesc(miniprogramSetting == null ? "--" : miniprogramSetting.getMiniprogramName());
}); });
} }
return PageUtil.changePageHelperToCurrentPage(page,MaterialDTO.class); return PageUtil.changePageHelperToCurrentPage(page, MaterialDTO.class);
} }
public static void main(String[] args) {
String str = "https://other-1251519181.cos.ap-shanghai.myqcloud.com/haoban/20200518101933/【④好办-数据】(1)(1).xlsx";
int count = str.split("/").length;
System.err.println(str.split("/")[count - 1]);
}
private static byte[] getFileByte(String url) {
try {
InputStream in = new URL(url).openStream();
byte[] data = IOUtils.toByteArray(in);
return data;
}catch (Exception e){
logger.info("【异常】"+e.getMessage(),e);
}
return null;
}
@Override public static void main(String[] args) {
public List<MaterialCategoryDTO> listByParentCategory(String categoryId) { String str = "https://other-1251519181.cos.ap-shanghai.myqcloud.com/haoban/20200518101933/【④好办-数据】(1)(1).xlsx";
return materialCategoryService.listByParentCategory(categoryId); int count = str.split("/").length;
} System.err.println(str.split("/")[count - 1]);
}
@Override private static byte[] getFileByte(String url) {
public ServiceResponse<Void> shareMaterial(String wxEnterpriseId, String toWxEnterpriseId, String materialId) {
ServiceResponse<Void> res = new ServiceResponse<>();
MaterialDTO materialDTO = materialService.selectMaterialById(materialId);
if (null == materialDTO) {
logger.info("不存在该素材");
res.setCode(2);
res.setMessage("不存在该素材");
return res;
}
if (!materialDTO.getFromMaterialId().equals("-1")) {
logger.info("该素材不允许分享");
res.setCode(3);
res.setMessage("该素材不允许分享");
return res;
}
MaterialDTO fromMaterialDTO = materialService.getMaterialByFromMaterialId(materialId, toWxEnterpriseId);
if (fromMaterialDTO != null) {
logger.info("已经存在素材,不能重复分享");
res.setCode(4);
res.setMessage("已经存在素材,不能重复分享");
return res;
}
materialDTO.setWxEnterpriseId(toWxEnterpriseId);
materialDTO.setFromMaterialId(materialId);
materialDTO.setMediaId(null);
materialDTO.setWxLastUploadTime(null);
materialService.insertMaterial(materialDTO);
return res;
}
@Override try {
public List<MaterialDTO> listByFromMaterialId(String materialId) { InputStream in = new URL(url).openStream();
List<MaterialDTO> materialDTOS = materialService.listMaterialByFromMateralId(materialId); byte[] data = IOUtils.toByteArray(in);
return materialDTOS; return data;
} } catch (Exception e) {
logger.info("【异常】" + e.getMessage(), e);
}
return null;
}
@Override @Override
public void delMaterial(List<String> ids) { public List<MaterialCategoryDTO> listByParentCategory(String categoryId) {
materialService.delmaterialByIds(ids); return materialCategoryService.listByParentCategory(categoryId);
} }
@Override
public ServiceResponse<Void> shareMaterial(String wxEnterpriseId, String toWxEnterpriseId, String materialId) {
ServiceResponse<Void> res = new ServiceResponse<>();
MaterialDTO materialDTO = materialService.selectMaterialById(materialId);
if (null == materialDTO) {
logger.info("不存在该素材");
res.setCode(2);
res.setMessage("不存在该素材");
return res;
}
if (!materialDTO.getFromMaterialId().equals("-1")) {
logger.info("该素材不允许分享");
res.setCode(3);
res.setMessage("该素材不允许分享");
return res;
}
MaterialDTO fromMaterialDTO = materialService.getMaterialByFromMaterialId(materialId, toWxEnterpriseId);
if (fromMaterialDTO != null) {
logger.info("已经存在素材,不能重复分享");
res.setCode(4);
res.setMessage("已经存在素材,不能重复分享");
return res;
}
materialDTO.setWxEnterpriseId(toWxEnterpriseId);
materialDTO.setFromMaterialId(materialId);
materialDTO.setMediaId(null);
materialDTO.setWxLastUploadTime(null);
materialService.insertMaterial(materialDTO);
return res;
}
@Override
public List<MaterialDTO> listByFromMaterialId(String materialId) {
List<MaterialDTO> materialDTOS = materialService.listMaterialByFromMateralId(materialId);
return materialDTOS;
}
@Override
public void delMaterial(List<String> ids) {
materialService.delmaterialByIds(ids);
}
@Override @Override
public MaterialDTO getHasChangeMadieMaterialById(String materialId) { public MaterialDTO getHasChangeMadieMaterialById(String materialId) {
...@@ -385,4 +380,54 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -385,4 +380,54 @@ public class MaterialApiServiceImpl implements MaterialApiService {
materialDTO.setWxLastUploadTime(date); materialDTO.setWxLastUploadTime(date);
return materialDTO; return materialDTO;
} }
@Override
public void batchInsertMaterial(BatchAddMaterialDTO dto) {
// 构造素材实体类
BatchAddMaterialDTO.Material material = dto.getMaterial();
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(material.getWxEnterpriseId());
if (enterprise == null) {
return;
}
List<BatchAddMaterialDTO.MaterialMedia> materialMediaList = dto.getMaterialMediaList();
if (CollectionUtils.isEmpty(materialMediaList)) {
return;
}
List<MaterialDTO> materialList = materialMediaList.stream().map(one -> {
MaterialDTO materialDTO = new MaterialDTO();
// 必填字段
materialDTO.setCreateTime(new Date());
materialDTO.setUpdateTime(materialDTO.getCreateTime());
materialDTO.setStatusFlag(1);
materialDTO.setMaterialId(StringUtil.randomUUID());
// 传入字段
materialDTO.setCategoryId(material.getCategoryId());
materialDTO.setMaterialTitle(material.getMaterialTitle());
materialDTO.setMaterialType(material.getMaterialType());
materialDTO.setWxEnterpriseId(material.getWxEnterpriseId());
materialDTO.setStaffId(material.getStaffId());
materialDTO.setStaffName(material.getStaffName());
String mediaId = uploadMediaToWx(enterprise.getCorpid(), one.getUrl());
if (StringUtils.isNotEmpty(mediaId)) {
materialDTO.setWxLastUploadTime(new Date());
materialDTO.setMediaId(mediaId);
}
return materialDTO;
}).collect(Collectors.toList());
// batch-insert
materialService.batchInsertMaterial(materialList);
}
private String uploadMediaToWx(String corPid, String url) {
String[] arr = url.split("/");
// 先写死为图片类型, 以后有别的再扩展
QywxMediaTypeEnum fileType = QywxMediaTypeEnum.IMAGE;
int count = arr.length;
JSONResponse jp = qywxSuiteApiService.uploadMedia(corPid, config.getWxSuiteid(), getFileByte(url), arr[count - 1], fileType.getCode());
if (jp.getErrorCode() == 0) {
return jp.getResult().toString();
}
return null;
}
} }
...@@ -173,6 +173,57 @@ ...@@ -173,6 +173,57 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<insert id="batchInsert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial">
insert into tab_haoban_material
(
material_id,
from_material_id,
material_title,
material_type,
category_id,
material_content,
wx_last_upload_time,
media_id,
wx_enterprise_id,
staff_id,
staff_name,
img_url,
wx_img_url,
material_desc,
status_flag,
link,
app_id,
create_time,
update_time
)
VALUES
(
<foreach collection="records" item="one" separator=",">
#{one.materialId,jdbcType=VARCHAR},
#{one.fromMaterialId,jdbcType=VARCHAR},
#{one.materialTitle,jdbcType=VARCHAR},
#{one.materialType,jdbcType=INTEGER},
#{one.categoryId,jdbcType=VARCHAR},
#{one.materialContent,jdbcType=VARCHAR},
#{one.wxLastUploadTime,jdbcType=TIMESTAMP},
#{one.mediaId,jdbcType=VARCHAR},
#{one.wxEnterpriseId,jdbcType=VARCHAR},
#{one.staffId,jdbcType=VARCHAR},
#{one.staffName,jdbcType=VARCHAR},
#{one.imgUrl,jdbcType=VARCHAR},
#{one.wxImgUrl,jdbcType=VARCHAR},
#{one.materialDesc,jdbcType=VARCHAR},
#{one.statusFlag,jdbcType=INTEGER},
#{one.link,jdbcType=VARCHAR},
#{one.appId,jdbcType=VARCHAR},
#{one.createTime,jdbcType=TIMESTAMP},
#{one.updateTime,jdbcType=TIMESTAMP}
</foreach>
)
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" > <update id="updateByPrimaryKeySelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" >
update tab_haoban_material update tab_haoban_material
<set > <set >
......
...@@ -5,146 +5,177 @@ import com.gic.api.base.commons.Page; ...@@ -5,146 +5,177 @@ import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo; import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.ServiceResponse; import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.common.utils.HaobanResponse; import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.LoginDTO; import com.gic.haoban.manage.api.dto.*;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.service.MaterialApiService; import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.web.auth.AuthRequestUtil; import com.gic.haoban.manage.web.auth.AuthRequestUtil;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode; import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
@RestController @RestController
public class MaterialController extends WebBaseController{ public class MaterialController extends WebBaseController {
@Autowired @Autowired
private MaterialApiService materialApiService; private MaterialApiService materialApiService;
/** /**
* 素材分组新增 * 素材分组新增
*
* @return * @return
*/ */
@RequestMapping("/mateial-add-category") @RequestMapping("/mateial-add-category")
public HaobanResponse materialAddCategory(MaterialCategoryDTO materialCategoryDTO) { public HaobanResponse materialAddCategory(MaterialCategoryDTO materialCategoryDTO) {
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser(); LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser();
String wxEnterpriseId = login.getWxEnterpriseId(); String wxEnterpriseId = login.getWxEnterpriseId();
materialCategoryDTO.setWxEnterpriseId(wxEnterpriseId); materialCategoryDTO.setWxEnterpriseId(wxEnterpriseId);
String categoryName = materialCategoryDTO.getCategoryName(); String categoryName = materialCategoryDTO.getCategoryName();
String categoryParentId = materialCategoryDTO.getCategoryParentId(); String categoryParentId = materialCategoryDTO.getCategoryParentId();
if(StringUtils.isAnyBlank(categoryParentId,categoryName)){ if (StringUtils.isAnyBlank(categoryParentId, categoryName)) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
boolean flag = materialApiService.hasCategoryNameExsit(categoryName,categoryParentId,null); boolean flag = materialApiService.hasCategoryNameExsit(categoryName, categoryParentId, null);
if(flag){ if (flag) {
return resultResponse(HaoBanErrCode.ERR_10015); return resultResponse(HaoBanErrCode.ERR_10015);
} }
materialApiService.insertCategory(materialCategoryDTO); materialApiService.insertCategory(materialCategoryDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 素材分组查询 * 素材分组查询
*
* @return * @return
*/ */
@RequestMapping("/category-list") @RequestMapping("/category-list")
public HaobanResponse categoryList(String wxEnterpriseId) { public HaobanResponse categoryList(String wxEnterpriseId) {
List<MaterialCategoryDTO> list = materialApiService.listCategory(wxEnterpriseId); List<MaterialCategoryDTO> list = materialApiService.listCategory(wxEnterpriseId);
return resultResponse(HaoBanErrCode.ERR_1,list); return resultResponse(HaoBanErrCode.ERR_1, list);
} }
/** /**
* 素材分组修改 * 素材分组修改
*
* @return * @return
*/ */
@RequestMapping("/category-edit") @RequestMapping("/category-edit")
public HaobanResponse categoryEdit(MaterialCategoryDTO materialCategoryDTO) { public HaobanResponse categoryEdit(MaterialCategoryDTO materialCategoryDTO) {
String categoryName = materialCategoryDTO.getCategoryName(); String categoryName = materialCategoryDTO.getCategoryName();
String categoryId = materialCategoryDTO.getCategoryId(); String categoryId = materialCategoryDTO.getCategoryId();
if(StringUtils.isAnyBlank(categoryName,categoryId)){ if (StringUtils.isAnyBlank(categoryName, categoryId)) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
MaterialCategoryDTO dto = materialApiService.selectMaterialCategoryById(categoryId); MaterialCategoryDTO dto = materialApiService.selectMaterialCategoryById(categoryId);
if(dto == null){ if (dto == null) {
return resultResponse(HaoBanErrCode.ERR_10016); return resultResponse(HaoBanErrCode.ERR_10016);
} }
String categoryParentId = dto.getCategoryParentId(); String categoryParentId = dto.getCategoryParentId();
boolean flag = materialApiService.hasCategoryNameExsit(categoryName,categoryParentId,materialCategoryDTO.getCategoryId()); boolean flag = materialApiService.hasCategoryNameExsit(categoryName, categoryParentId, materialCategoryDTO.getCategoryId());
if(flag){ if (flag) {
return resultResponse(HaoBanErrCode.ERR_10015); return resultResponse(HaoBanErrCode.ERR_10015);
} }
materialApiService.editCategory(materialCategoryDTO); materialApiService.editCategory(materialCategoryDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 素材分组删除 * 素材分组删除
*
* @return * @return
*/ */
@RequestMapping("/category-del") @RequestMapping("/category-del")
public HaobanResponse categoryDel(String categoryId) { public HaobanResponse categoryDel(String categoryId) {
MaterialCategoryDTO dto = materialApiService.selectMaterialCategoryById(categoryId); MaterialCategoryDTO dto = materialApiService.selectMaterialCategoryById(categoryId);
if(dto == null){ if (dto == null) {
return resultResponse(HaoBanErrCode.ERR_10016); return resultResponse(HaoBanErrCode.ERR_10016);
} }
List<MaterialCategoryDTO> categoryList = materialApiService.listByParentCategory(categoryId); List<MaterialCategoryDTO> categoryList = materialApiService.listByParentCategory(categoryId);
if(categoryList != null && !categoryList.isEmpty()){ if (categoryList != null && !categoryList.isEmpty()) {
return resultResponse(HaoBanErrCode.ERR_10017); return resultResponse(HaoBanErrCode.ERR_10017);
} }
List<MaterialDTO> list = materialApiService.listMaterialByCategoryId(categoryId); List<MaterialDTO> list = materialApiService.listMaterialByCategoryId(categoryId);
if(list!= null && !list.isEmpty()){ if (list != null && !list.isEmpty()) {
return resultResponse(HaoBanErrCode.ERR_10017); return resultResponse(HaoBanErrCode.ERR_10017);
} }
dto.setStatusFlag(0); dto.setStatusFlag(0);
materialApiService.editCategory(dto); materialApiService.editCategory(dto);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 素材新增 * 素材新增
*
* @return * @return
*/ */
@RequestMapping("/material-add") @RequestMapping("/material-add")
public HaobanResponse materialAdd(MaterialDTO materialDTO) { public HaobanResponse materialAdd(MaterialDTO materialDTO) {
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser(); LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser();
String wxEnterpriseId = login.getWxEnterpriseId(); String wxEnterpriseId = login.getWxEnterpriseId();
materialDTO.setWxEnterpriseId(wxEnterpriseId); materialDTO.setWxEnterpriseId(wxEnterpriseId);
StaffDTO staff = login.getStaffDTO(); StaffDTO staff = login.getStaffDTO();
materialDTO.setStaffId(staff.getStaffId()); materialDTO.setStaffId(staff.getStaffId());
materialDTO.setStaffName(staff.getStaffName()); materialDTO.setStaffName(staff.getStaffName());
String materialTitle = materialDTO.getMaterialTitle(); String materialTitle = materialDTO.getMaterialTitle();
String categoryId = materialDTO.getCategoryId(); String categoryId = materialDTO.getCategoryId();
Integer categoryType = materialDTO.getMaterialType(); Integer categoryType = materialDTO.getMaterialType();
if(StringUtils.isAnyBlank(categoryId,materialTitle)){ if (StringUtils.isAnyBlank(categoryId, materialTitle)) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
if(categoryType == null){ if (categoryType == null) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
materialApiService.insertMaterial(materialDTO); materialApiService.insertMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/**
* 批量新增素材
*
* @param dto dto
* @return res
*/
@RequestMapping("/material-batch-add")
public HaobanResponse batchAddMaterial(@RequestBody BatchAddMaterialDTO dto) {
if (Objects.isNull(dto) || Objects.isNull(dto.getMaterial())) {
return resultResponse(HaoBanErrCode.ERR_2);
}
BatchAddMaterialDTO.Material material = dto.getMaterial();
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser();
material.setWxEnterpriseId(login.getWxEnterpriseId());
StaffDTO staff = login.getStaffDTO();
material.setStaffId(staff.getStaffId());
material.setStaffName(staff.getStaffName());
if (StringUtils.isAnyBlank(material.getCategoryId(), material.getMaterialTitle())
|| Objects.isNull(material.getMaterialType())) {
return resultResponse(HaoBanErrCode.ERR_2);
}
materialApiService.batchInsertMaterial(dto);
return resultResponse(HaoBanErrCode.ERR_1);
}
/** /**
* 素材详情 * 素材详情
*
* @return * @return
*/ */
@RequestMapping("/material-detail") @RequestMapping("/material-detail")
public HaobanResponse materialDetail(String materialId) { public HaobanResponse materialDetail(String materialId) {
MaterialDTO dto = materialApiService.selectMaterialById(materialId); MaterialDTO dto = materialApiService.selectMaterialById(materialId);
return resultResponse(HaoBanErrCode.ERR_1,dto); return resultResponse(HaoBanErrCode.ERR_1, dto);
} }
/** /**
* 素材修改 * 素材修改
*
* @return * @return
*/ */
@RequestMapping("/material-edit") @RequestMapping("/material-edit")
...@@ -152,67 +183,71 @@ public class MaterialController extends WebBaseController{ ...@@ -152,67 +183,71 @@ public class MaterialController extends WebBaseController{
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser(); LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser();
StaffDTO staff = login.getStaffDTO(); StaffDTO staff = login.getStaffDTO();
materialDTO.setStaffId(staff.getStaffId()); materialDTO.setStaffId(staff.getStaffId());
materialDTO.setStaffName(staff.getStaffName()); materialDTO.setStaffName(staff.getStaffName());
String materialId = materialDTO.getMaterialId(); String materialId = materialDTO.getMaterialId();
MaterialDTO dto = materialApiService.selectMaterialById(materialId); MaterialDTO dto = materialApiService.selectMaterialById(materialId);
if(dto == null){ if (dto == null) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
materialApiService.editMaterial(materialDTO); materialApiService.editMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 素材删除 * 素材删除
*
* @return * @return
*/ */
@RequestMapping("/material-del") @RequestMapping("/material-del")
public HaobanResponse materialEdit(String materialIds) { public HaobanResponse materialEdit(String materialIds) {
if(StringUtils.isBlank(materialIds)){ if (StringUtils.isBlank(materialIds)) {
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
String[] stringArr = materialIds.split(","); String[] stringArr = materialIds.split(",");
List<String> list = Arrays.asList(stringArr); List<String> list = Arrays.asList(stringArr);
materialApiService.delMaterial(list); materialApiService.delMaterial(list);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 素材查询 * 素材查询
*
* @return * @return
*/ */
@RequestMapping("/material-list") @RequestMapping("/material-list")
public HaobanResponse materialList(String wxEnterpriseId,String keyword,String categoryId,Integer materialType,BasePageInfo pageInfo) { public HaobanResponse materialList(String wxEnterpriseId, String keyword, String categoryId, Integer materialType, BasePageInfo pageInfo) {
Page<MaterialDTO> page = materialApiService.listMaterial(wxEnterpriseId,keyword,categoryId,materialType,pageInfo); Page<MaterialDTO> page = materialApiService.listMaterial(wxEnterpriseId, keyword, categoryId, materialType, pageInfo);
return resultResponse(HaoBanErrCode.ERR_1,page); return resultResponse(HaoBanErrCode.ERR_1, page);
} }
/** /**
* 素材批量转移 * 素材批量转移
*
* @return * @return
*/ */
@RequestMapping("/material-batch") @RequestMapping("/material-batch")
public HaobanResponse materialBatch(String materialIds,String categoryId) { public HaobanResponse materialBatch(String materialIds, String categoryId) {
String[] stringArr = materialIds.split(","); String[] stringArr = materialIds.split(",");
for (String materialId : stringArr) { for (String materialId : stringArr) {
MaterialDTO dto = materialApiService.selectMaterialById(materialId); MaterialDTO dto = materialApiService.selectMaterialById(materialId);
if(dto == null){ if (dto == null) {
continue; continue;
} }
dto.setCategoryId(categoryId);; dto.setCategoryId(categoryId);
materialApiService.editMaterial(dto); ;
} materialApiService.editMaterial(dto);
return resultResponse(HaoBanErrCode.ERR_1); }
return resultResponse(HaoBanErrCode.ERR_1);
} }
/** /**
* 分析素材 * 分析素材
* *
* @return * @return
*/ */
@RequestMapping("/material-share") @RequestMapping("/material-share")
public HaobanResponse materialShare(String materialIds, String toWxEnterpriseIds) { public HaobanResponse materialShare(String materialIds, String toWxEnterpriseIds) {
LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser(); LoginDTO login = (LoginDTO) AuthRequestUtil.getLoginUser();
String[] wxEids = toWxEnterpriseIds.split(","); String[] wxEids = toWxEnterpriseIds.split(",");
...@@ -227,7 +262,7 @@ public class MaterialController extends WebBaseController{ ...@@ -227,7 +262,7 @@ public class MaterialController extends WebBaseController{
return resultResponse(HaoBanErrCode.ERR_DEFINE); return resultResponse(HaoBanErrCode.ERR_DEFINE);
} }
} }
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
} }
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