Commit 856ac61b by 徐高华

企微上传

parent 81235af2
......@@ -4,6 +4,7 @@ import com.gic.api.base.commons.Page;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
......@@ -75,5 +76,7 @@ public interface MaterialApiService {
* @author: YongEn
*/
void batchInsertMaterial(BatchAddMaterialDTO dto);
public com.gic.api.base.commons.ServiceResponse<String> getMaterialId(String wxEnterpriseId, ContentMaterialDTO dto) ;
}
package com.gic.haoban.manage.service.service;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import java.util.List;
......@@ -51,5 +53,9 @@ public interface MaterialService {
void delmaterialByIds(List<String> ids);
public MaterialDTO getHasChangeMadieMaterialById(String materialId,int from) ;
public JSONResponse reUpdalodMetailJson(String materialId,int from) ;
public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) ;
}
......@@ -2,6 +2,7 @@ package com.gic.haoban.manage.service.service.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
......@@ -15,6 +16,7 @@ import org.springframework.stereotype.Service;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.service.config.Config;
......@@ -27,6 +29,7 @@ import com.gic.haoban.manage.service.service.WxEnterpriseService;
import com.gic.haoban.manage.service.util.CommonUtil;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.weimob.common.Md5Util;
import com.github.pagehelper.Page;
@Service
......@@ -144,78 +147,110 @@ public class MaterialServiceImpl implements MaterialService {
}
private String reUpdalodMetail(String materialId,int from) {
MaterialDTO old = null ;
TabMaterialContent entity =null ;
if(from == 1) {
old = this.selectMaterialById(materialId);
}
if(from == 2) {
entity =this.materialContentMapper.selectById(materialId) ;
if(null != entity) {
old = EntityUtil.changeEntityByJSON(MaterialDTO.class, entity) ;
}
}
Integer type = old.getMaterialType();
if (type == null) {
return "";
}
String wxEnterpriseId = old.getWxEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
if (qwDTO == null) {
logger.info("qwDTO is null");
return "";
}
String url = "";
QywxMediaTypeEnum fileType = null;
if (type == 2) {
fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl();
}
if (type == 4) {
fileType = QywxMediaTypeEnum.VIDEO;
url = old.getLink();
}
if (type == 5) {
fileType = QywxMediaTypeEnum.FILE;
url = old.getLink();
} else if (type == 6) {
fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl();
}
if (fileType == null) {
logger.error("materialId无类型,materialId:{}", materialId);
return "";
}
if(from == 2) {
url = entity.getImgUrl() ;
}
String[] arr = url.split("/");
int count = arr.length;
JSONResponse jp = null ;
if(from==2 && entity.getMediaType()==2) {
if (type == 2) {
url+= "?imageView2/2/w/1440/h/1080" ;
}
jp = qywxSuiteApiService.uploadAttachment(qwDTO.getThirdCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
}else {
jp = qywxSuiteApiService.uploadMedia(qwDTO.getThirdCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
}
String mediaid = old.getMediaId();
if (jp.getErrorCode() == 0) {
if(from==1) {
old.setWxLastUploadTime(new Date());
old.setMediaId(jp.getResult().toString());
mediaid = old.getMediaId() ;
this.edit(old);
}
if(from==2) {
entity.setWxLastUploadTime(new Date());
entity.setMediaId(jp.getResult().toString());
mediaid = entity.getMediaId() ;
this.materialContentMapper.updateByPrimaryKey(entity) ;
JSONResponse jp = this.reUpdalodMetailJson(materialId, from) ;
if(null == jp) {
return "";
}
if (jp.getErrorCode() == 0) {
return jp.getResult().toString() ;
}
return "";
}
public JSONResponse reUpdalodMetailJson(String materialId,int from) {
JSONResponse jp = new JSONResponse() ;
MaterialDTO old = null ;
TabMaterialContent entity =null ;
if(from == 1) {
old = this.selectMaterialById(materialId);
}
if(from == 2) {
entity =this.materialContentMapper.selectById(materialId) ;
if(null != entity) {
old = EntityUtil.changeEntityByJSON(MaterialDTO.class, entity) ;
}
}
Integer type = old.getMaterialType();
if (type == null) {
return jp;
}
String wxEnterpriseId = old.getWxEnterpriseId();
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId) ;
if (qwDTO == null) {
logger.info("qwDTO is null");
return jp;
}
String url = "";
QywxMediaTypeEnum fileType = null;
if (type == 2) {
fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl();
}
if (type == 4) {
fileType = QywxMediaTypeEnum.VIDEO;
url = old.getLink();
}
if (type == 5) {
fileType = QywxMediaTypeEnum.FILE;
url = old.getLink();
} else if (type == 6) {
fileType = QywxMediaTypeEnum.IMAGE;
url = old.getImgUrl();
}
if (fileType == null) {
logger.error("materialId无类型,materialId:{}", materialId);
return jp;
}
if(from == 2) {
url = entity.getImgUrl() ;
}
String[] arr = url.split("/");
int count = arr.length;
if(from==2 && entity.getMediaType()==2) {
if (type == 2) {
url+= "?imageView2/2/w/1440/h/1080" ;
}
jp = qywxSuiteApiService.uploadAttachment(qwDTO.getThirdCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
}else {
jp = qywxSuiteApiService.uploadMedia(qwDTO.getThirdCorpid(), config.getWxSuiteid(), CommonUtil.getFileByte(url), arr[count - 1], fileType.getCode());
}
if (jp.getErrorCode() == 0) {
if(from==1) {
old.setWxLastUploadTime(new Date());
old.setMediaId(jp.getResult().toString());
this.edit(old);
}
if(from==2) {
entity.setWxLastUploadTime(new Date());
entity.setMediaId(jp.getResult().toString());
this.materialContentMapper.updateByPrimaryKey(entity) ;
}
}
return jp;
}
public List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) {
List<String> materialIdList = new ArrayList<>();
imageList.forEach(dto -> {
String imageUrl = dto.getImgUrl();
int type = dto.getMaterialType();
String md5 = Md5Util.MD5(imageUrl);
TabMaterialContent tab = this.materialContentMapper.selectByUrl(wxEnterpriseId, md5, mediaType);
if (null != tab) {
materialIdList.add(tab.getMaterialId());
} else {
String id = StringUtil.randomUUID();
tab = new TabMaterialContent();
tab.setMaterialId(id);
tab.setMaterialType(type);
tab.setImgUrl(imageUrl);
tab.setUrlMd5(md5);
tab.setMediaType(mediaType);
tab.setWxEnterpriseId(wxEnterpriseId);
this.materialContentMapper.insert(tab);
materialIdList.add(id);
}
}
return mediaid;
});
return materialIdList;
}
}
......@@ -15,16 +15,13 @@ import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.JSONResponse;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanStaffClerkRelationMapper;
import com.gic.haoban.manage.service.dao.mapper.TabMaterialContentMapper;
import com.gic.haoban.manage.service.entity.TabHaobanStaff;
import com.gic.haoban.manage.service.entity.TabMaterialContent;
import com.gic.haoban.manage.service.service.MaterialService;
import com.gic.haoban.manage.service.service.QywxSendService;
import com.gic.haoban.manage.service.service.StaffService;
......@@ -42,7 +39,6 @@ import com.gic.wechat.api.dto.qywx.moment.VisibleRange;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxExternalUserService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.weimob.common.Md5Util;
/**
*
......@@ -68,8 +64,6 @@ public class QywxSendServiceImpl implements QywxSendService {
@Autowired
private QywxSuiteApiService qywxSuiteApiService;
@Autowired
private TabMaterialContentMapper tabMaterialContentMapper;
@Autowired
private QywxExternalUserService qywxExternalUserService;
@Autowired
private TabHaobanStaffClerkRelationMapper tabHaobanStaffClerkRelationMapper;
......@@ -83,7 +77,7 @@ public class QywxSendServiceImpl implements QywxSendService {
@Override
public ServiceResponse<String> sendMessageShare(String wxEnterpriseId, String staffId, List<String> extendUserList,
List<ContentMaterialDTO> imageList, String message) {
List<String> materialIdList = this.getImageMediaId(wxEnterpriseId, imageList, 1);
List<String> materialIdList = this.materialService.getImageMediaId(wxEnterpriseId, imageList, 1);
return this.send(wxEnterpriseId, staffId, extendUserList, materialIdList, message, 2);
}
......@@ -123,37 +117,12 @@ public class QywxSendServiceImpl implements QywxSendService {
return ServiceResponse.failure("9999", error);
}
private List<String> getImageMediaId(String wxEnterpriseId, List<ContentMaterialDTO> imageList, int mediaType) {
List<String> materialIdList = new ArrayList<>();
imageList.forEach(dto -> {
String imageUrl = dto.getImgUrl();
int type = dto.getMaterialType();
String md5 = Md5Util.MD5(imageUrl);
TabMaterialContent tab = this.tabMaterialContentMapper.selectByUrl(wxEnterpriseId, md5, mediaType);
if (null != tab) {
materialIdList.add(tab.getMaterialId());
} else {
String id = StringUtil.randomUUID();
tab = new TabMaterialContent();
tab.setMaterialId(id);
tab.setMaterialType(type);
tab.setImgUrl(imageUrl);
tab.setUrlMd5(md5);
tab.setMediaType(mediaType);
tab.setWxEnterpriseId(wxEnterpriseId);
this.tabMaterialContentMapper.insert(tab);
materialIdList.add(id);
}
});
return materialIdList;
}
// 分享朋友圈
@Override
public ServiceResponse<String> share(String wxEnterpriseId, List<String> clerkIdList, String message,
List<ContentMaterialDTO> imageList) {
WxEnterpriseQwDTO qwDTO = this.wxEnterpriseService.getQwInfo(wxEnterpriseId);
List<String> materialIdList = this.getImageMediaId(wxEnterpriseId, imageList, 2);
List<String> materialIdList = this.materialService.getImageMediaId(wxEnterpriseId, imageList, 2);
QywxExternalMessageDTO dto = this.getMessage(2, message, materialIdList);
MomentTaskDTO moment = EntityUtil.changeEntity(MomentTaskDTO.class, dto);
Text text = new Text();
......
......@@ -25,12 +25,15 @@ import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.TabMaterialContentMapper;
import com.gic.haoban.manage.service.entity.TabHaobanMaterial;
import com.gic.haoban.manage.service.entity.TabMaterialContent;
import com.gic.haoban.manage.service.entity.TabMiniprogramSetting;
import com.gic.haoban.manage.service.service.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService;
......@@ -61,6 +64,8 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Autowired
private MiniprogramSettingService miniprogramSettingService;
@Autowired
private TabMaterialContentMapper materialContentMapper ;
private static Logger logger = LoggerFactory.getLogger(MaterialApiServiceImpl.class);
......@@ -444,4 +449,33 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
return null;
}
public com.gic.api.base.commons.ServiceResponse<String> getMaterialId(String wxEnterpriseId, ContentMaterialDTO dto) {
List<ContentMaterialDTO> imageList = Arrays.asList(dto) ;
List<String> materialIdList = this.materialService.getImageMediaId(wxEnterpriseId, imageList, dto.getMaterialType());
if (CollectionUtils.isEmpty(materialIdList)) {
com.gic.api.base.commons.ServiceResponse.failure("9999", "素材记录不存") ;
}
String materialId = materialIdList.get(0) ;
TabMaterialContent entity = this.materialContentMapper.selectById(materialId) ;
if(null == entity) {
com.gic.api.base.commons.ServiceResponse.failure("9999", "素材记录不存") ;
}
Date lastUploadTime = entity.getWxLastUploadTime();
Date date = new Date();
Date compareDate = DateUtils.addDays(date, -3);
String madiaId= entity.getMediaId() ;
if (lastUploadTime != null && lastUploadTime.after(compareDate) && StringUtils.isNotBlank(madiaId)) {
return com.gic.api.base.commons.ServiceResponse.success(madiaId) ;
}
JSONResponse json = this.materialService.reUpdalodMetailJson(materialId,2) ;
if (json.getErrorCode() == 0) {
madiaId= json.getResult().toString() ;
return com.gic.api.base.commons.ServiceResponse.success(madiaId) ;
}else {
return com.gic.api.base.commons.ServiceResponse.failure("9999",json.getErrorMessage()) ;
}
}
}
......@@ -11,8 +11,8 @@ 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.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.commons.util.GICMQClientUtil;
......@@ -21,7 +21,9 @@ import com.gic.haoban.app.customer.dto.CustomerDTO;
import com.gic.haoban.app.customer.dto.MemberInfoListParamsDTO;
import com.gic.haoban.app.customer.service.api.service.DistributeApiService;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.manage.api.dto.ContentMaterialDTO;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.StaffClerkRelationApiService;
import com.gic.haoban.manage.web.controller.WebBaseController;
......@@ -39,6 +41,8 @@ public class QwMessageController extends WebBaseController {
private ClerkService clerkService;
@Autowired
private StaffClerkRelationApiService staffClerkRelationApiService ;
@Autowired
private MaterialApiService materialApiService ;
/**
* 群发-分享 - 店员和店长
......@@ -150,5 +154,16 @@ public class QwMessageController extends WebBaseController {
}
return RestResponse.successResult();
}
@RequestMapping("get-qw-materialId")
public RestResponse<Object> getMaterialId(String wxEnterpriseId,String imgUrl , int materialType) {
ContentMaterialDTO dto = new ContentMaterialDTO();
dto.setImgUrl(imgUrl);
dto.setMaterialType(materialType);
ServiceResponse<String> resp = this.materialApiService.getMaterialId(wxEnterpriseId, dto) ;
if(resp.isSuccess()) {
return RestResponse.successResult(resp.getResult()) ;
}
return RestResponse.failure("-1", resp.getMessage()) ;
}
}
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