Commit ba774870 by qwmqiuwenmin

fix

parent b95b9255
......@@ -21,11 +21,11 @@ public interface MaterialApiService {
List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertCategory(MaterialDTO materialDTO);
void insertMaterial(MaterialDTO materialDTO);
MaterialDTO selectMaterialById(String materialId);
void editCategory(MaterialDTO materialDTO);
void editMaterial(MaterialDTO materialDTO);
Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId, Integer materialType,BasePageInfo pageInfo);
......
......@@ -8,7 +8,7 @@ public interface MaterialService {
List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertCategory(MaterialDTO materialDTO);
void insertMaterial(MaterialDTO materialDTO);
MaterialDTO selectMaterialById(String materialId);
......
......@@ -26,7 +26,7 @@ public class MaterialServiceImpl implements MaterialService {
}
@Override
public void insertCategory(MaterialDTO materialDTO) {
public void insertMaterial(MaterialDTO materialDTO) {
materialDTO.setCreateTime(new Date());
materialDTO.setUpdateTime(materialDTO.getCreateTime());
materialDTO.setStatusFlag(1);
......
package com.gic.haoban.manage.service.service.out.impl;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import org.apache.commons.io.IOUtils;
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.gic.api.base.commons.JSONResponse;
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.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.MaterialCategoryDTO;
import com.gic.haoban.manage.api.dto.MaterialDTO;
import com.gic.haoban.manage.api.dto.WxEnterpriseDTO;
import com.gic.haoban.manage.api.service.MaterialApiService;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.service.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService;
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.service.qywx.QywxSuiteApiService;
import com.github.pagehelper.PageHelper;
@Service
......@@ -24,6 +39,17 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Autowired
private MaterialService materialService;
@Autowired
private QywxSuiteApiService qywxSuiteApiService;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private Config config;
private static Logger logger = LoggerFactory.getLogger(MaterialApiServiceImpl.class);
@Override
public boolean hasCategoryNameExsit(String categoryName, String categoryParentId,String categoryId) {
......@@ -68,8 +94,39 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
@Override
public void insertCategory(MaterialDTO materialDTO) {
materialService.insertCategory(materialDTO);
public void insertMaterial(MaterialDTO materialDTO) {
Integer type = materialDTO.getMaterialType();
String wxEnterpriseId = materialDTO.getWxEnterpriseId();
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if(type == null){
return;
}
if(enterprise == null){
return;
}
QywxMediaTypeEnum fileType = null;
String url = "";
if(type == 2){
fileType = QywxMediaTypeEnum.IMAGE;
url = materialDTO.getImgUrl();
}
if(type == 4){
fileType = QywxMediaTypeEnum.VIDEO;
url = materialDTO.getLink();
}
if(type == 5){
fileType = QywxMediaTypeEnum.FILE;
url = materialDTO.getLink();
}
if(fileType != null){
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), fileType.getCode());
if(jp.getErrorCode() == 0){
materialDTO.setMediaId(jp.getResult().toString());
materialService.insertMaterial(materialDTO);
}
}else{
materialService.insertMaterial(materialDTO);
}
}
@Override
......@@ -78,8 +135,45 @@ public class MaterialApiServiceImpl implements MaterialApiService {
}
@Override
public void editCategory(MaterialDTO materialDTO) {
materialService.edit(materialDTO);
public void editMaterial(MaterialDTO materialDTO) {
Integer type = materialDTO.getMaterialType();
String materialId = materialDTO.getMaterialId();
MaterialDTO old = materialService.selectMaterialById(materialId);
String wxEnterpriseId = old.getWxEnterpriseId();
WxEnterpriseDTO enterprise = wxEnterpriseService.selectById(wxEnterpriseId);
if(type == null){
return;
}
if(enterprise == null){
return;
}
QywxMediaTypeEnum fileType = null;
String url = "";
String oldUrl = "";
if(type == 2){
fileType = QywxMediaTypeEnum.IMAGE;
url = materialDTO.getImgUrl();
oldUrl = old.getImgUrl();
}
if(type == 4){
fileType = QywxMediaTypeEnum.VIDEO;
url = materialDTO.getLink();
oldUrl = old.getLink();
}
if(type == 5){
fileType = QywxMediaTypeEnum.FILE;
url = materialDTO.getLink();
oldUrl = old.getLink();
}
if(fileType != null && !url.equals(oldUrl)){
JSONResponse jp = qywxSuiteApiService.uploadMedia(enterprise.getCorpid(), config.getWxSuiteid(), getFileByte(url), fileType.getCode());
if(jp.getErrorCode() == 0){
materialDTO.setMediaId(jp.getResult().toString());
materialService.edit(materialDTO);
}
}else{
materialService.edit(materialDTO);
}
}
......@@ -89,5 +183,17 @@ public class MaterialApiServiceImpl implements MaterialApiService {
PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
return PageUtil.changePageHelperToCurrentPage(materialService.listMaterial(wxEnterpriseId,keyword,categoryId,materialType),MaterialDTO.class);
}
private byte[] getFileByte(String url) {
try {
InputStream in = new URL(url).openStream();
byte[] data = IOUtils.toByteArray(in);
return data;
}catch (Exception e){
}
return null;
}
}
......@@ -124,7 +124,7 @@ public class MaterialController extends WebBaseController{
if(categoryType == null){
return resultResponse(HaoBanErrCode.ERR_2);
}
materialApiService.insertCategory(materialDTO);
materialApiService.insertMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1);
}
......@@ -144,7 +144,7 @@ public class MaterialController extends WebBaseController{
if(dto == null){
return resultResponse(HaoBanErrCode.ERR_2);
}
materialApiService.editCategory(materialDTO);
materialApiService.editMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1);
}
......@@ -164,7 +164,7 @@ public class MaterialController extends WebBaseController{
continue;
}
dto.setStatusFlag(0);
materialApiService.editCategory(dto);
materialApiService.editMaterial(dto);
}
return resultResponse(HaoBanErrCode.ERR_1);
}
......@@ -192,7 +192,7 @@ public class MaterialController extends WebBaseController{
continue;
}
dto.setCategoryId(categoryId);;
materialApiService.editCategory(dto);
materialApiService.editMaterial(dto);
}
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