Commit ba774870 by qwmqiuwenmin

fix

parent b95b9255
...@@ -21,11 +21,11 @@ public interface MaterialApiService { ...@@ -21,11 +21,11 @@ public interface MaterialApiService {
List<MaterialDTO> listMaterialByCategoryId(String categoryId); List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertCategory(MaterialDTO materialDTO); void insertMaterial(MaterialDTO materialDTO);
MaterialDTO selectMaterialById(String materialId); 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); Page<MaterialDTO> listMaterial(String wxEnterpriseId, String keyword, String categoryId, Integer materialType,BasePageInfo pageInfo);
......
...@@ -8,7 +8,7 @@ public interface MaterialService { ...@@ -8,7 +8,7 @@ public interface MaterialService {
List<MaterialDTO> listMaterialByCategoryId(String categoryId); List<MaterialDTO> listMaterialByCategoryId(String categoryId);
void insertCategory(MaterialDTO materialDTO); void insertMaterial(MaterialDTO materialDTO);
MaterialDTO selectMaterialById(String materialId); MaterialDTO selectMaterialById(String materialId);
......
...@@ -26,7 +26,7 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -26,7 +26,7 @@ public class MaterialServiceImpl implements MaterialService {
} }
@Override @Override
public void insertCategory(MaterialDTO materialDTO) { public void insertMaterial(MaterialDTO materialDTO) {
materialDTO.setCreateTime(new Date()); materialDTO.setCreateTime(new Date());
materialDTO.setUpdateTime(materialDTO.getCreateTime()); materialDTO.setUpdateTime(materialDTO.getCreateTime());
materialDTO.setStatusFlag(1); materialDTO.setStatusFlag(1);
......
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.List; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.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.common.utils.PageUtil; import com.gic.haoban.common.utils.PageUtil;
import com.gic.haoban.manage.api.dto.DepartmentDTO; import com.gic.haoban.manage.api.dto.DepartmentDTO;
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.service.MaterialApiService; 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.MaterialCategoryService;
import com.gic.haoban.manage.service.service.MaterialService; 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; import com.github.pagehelper.PageHelper;
@Service @Service
...@@ -24,6 +39,17 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -24,6 +39,17 @@ public class MaterialApiServiceImpl implements MaterialApiService {
@Autowired @Autowired
private MaterialService materialService; private MaterialService materialService;
@Autowired
private QywxSuiteApiService qywxSuiteApiService;
@Autowired
private WxEnterpriseService wxEnterpriseService;
@Autowired
private Config config;
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) {
...@@ -68,8 +94,39 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -68,8 +94,39 @@ public class MaterialApiServiceImpl implements MaterialApiService {
} }
@Override @Override
public void insertCategory(MaterialDTO materialDTO) { public void insertMaterial(MaterialDTO materialDTO) {
materialService.insertCategory(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 @Override
...@@ -78,8 +135,45 @@ public class MaterialApiServiceImpl implements MaterialApiService { ...@@ -78,8 +135,45 @@ public class MaterialApiServiceImpl implements MaterialApiService {
} }
@Override @Override
public void editCategory(MaterialDTO materialDTO) { public void editMaterial(MaterialDTO materialDTO) {
materialService.edit(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 { ...@@ -89,5 +183,17 @@ public class MaterialApiServiceImpl implements MaterialApiService {
PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize()); PageHelper.startPage(pageInfo.getPageNum(), pageInfo.getPageSize());
return PageUtil.changePageHelperToCurrentPage(materialService.listMaterial(wxEnterpriseId,keyword,categoryId,materialType),MaterialDTO.class); 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{ ...@@ -124,7 +124,7 @@ public class MaterialController extends WebBaseController{
if(categoryType == null){ if(categoryType == null){
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
materialApiService.insertCategory(materialDTO); materialApiService.insertMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
...@@ -144,7 +144,7 @@ public class MaterialController extends WebBaseController{ ...@@ -144,7 +144,7 @@ public class MaterialController extends WebBaseController{
if(dto == null){ if(dto == null){
return resultResponse(HaoBanErrCode.ERR_2); return resultResponse(HaoBanErrCode.ERR_2);
} }
materialApiService.editCategory(materialDTO); materialApiService.editMaterial(materialDTO);
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
...@@ -164,7 +164,7 @@ public class MaterialController extends WebBaseController{ ...@@ -164,7 +164,7 @@ public class MaterialController extends WebBaseController{
continue; continue;
} }
dto.setStatusFlag(0); dto.setStatusFlag(0);
materialApiService.editCategory(dto); materialApiService.editMaterial(dto);
} }
return resultResponse(HaoBanErrCode.ERR_1); return resultResponse(HaoBanErrCode.ERR_1);
} }
...@@ -192,7 +192,7 @@ public class MaterialController extends WebBaseController{ ...@@ -192,7 +192,7 @@ public class MaterialController extends WebBaseController{
continue; continue;
} }
dto.setCategoryId(categoryId);; dto.setCategoryId(categoryId);;
materialApiService.editCategory(dto); materialApiService.editMaterial(dto);
} }
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