Commit 95f510a5 by 徐高华

群发+朋友圈

parent 9dfc1bd8
...@@ -7,22 +7,17 @@ import org.apache.ibatis.annotations.Param; ...@@ -7,22 +7,17 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
public interface TabHaobanMaterialMapper { public interface TabHaobanMaterialMapper {
int deleteByPrimaryKey(String materialId);
int insert(TabHaobanMaterial record); int insert(TabHaobanMaterial record);
int batchInsert(@Param("records") List<TabHaobanMaterial> records); int batchInsert(@Param("records") List<TabHaobanMaterial> records);
int insertSelective(TabHaobanMaterial record);
TabHaobanMaterial selectByPrimaryKey(String materialId); TabHaobanMaterial selectByPrimaryKey(String materialId);
List<TabHaobanMaterial> listByids(@Param("materialIds") List<String> materialIds); List<TabHaobanMaterial> listByids(@Param("materialIds") List<String> materialIds);
int updateByPrimaryKeySelective(TabHaobanMaterial record); int updateByPrimaryKeySelective(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);
...@@ -35,9 +30,6 @@ public interface TabHaobanMaterialMapper { ...@@ -35,9 +30,6 @@ public interface TabHaobanMaterialMapper {
/** /**
* 删除 * 删除
*
* @param ids
* @return
*/ */
int delMaterialByIds(@Param("ids") List<String> ids); int delMaterialByIds(@Param("ids") List<String> ids);
} }
\ No newline at end of file
...@@ -49,5 +49,7 @@ public interface MaterialService { ...@@ -49,5 +49,7 @@ public interface MaterialService {
* @param ids * @param ids
*/ */
void delmaterialByIds(List<String> ids); void delmaterialByIds(List<String> ids);
public MaterialDTO getHasChangeMadieMaterialById(String materialId,int from) ;
} }
package com.gic.haoban.manage.service.service.impl; package com.gic.haoban.manage.service.service.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
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.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;
import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
import com.gic.haoban.manage.service.config.Config;
import com.gic.haoban.manage.service.dao.mapper.TabHaobanMaterialMapper; import com.gic.haoban.manage.service.dao.mapper.TabHaobanMaterialMapper;
import com.gic.haoban.manage.service.dao.mapper.TabMaterialContentMapper;
import com.gic.haoban.manage.service.entity.TabHaobanMaterial; import com.gic.haoban.manage.service.entity.TabHaobanMaterial;
import com.gic.haoban.manage.service.entity.TabMaterialContent;
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.haoban.manage.service.util.CommonUtil;
import com.gic.wechat.api.enums.QywxMediaTypeEnum;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
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 {
private static final Logger logger = getLogger(MaterialService.class);
@Autowired @Autowired
private TabHaobanMaterialMapper mapper; private TabHaobanMaterialMapper mapper;
@Autowired
private TabMaterialContentMapper materialContentMapper ;
@Autowired
private WxEnterpriseService wxEnterpriseService ;
@Autowired
private QywxSuiteApiService qywxSuiteApiService ;
@Autowired
private Config config;
@Override @Override
public List<MaterialDTO> listMaterialByCategoryId(String categoryId) { public List<MaterialDTO> listMaterialByCategoryId(String categoryId) {
...@@ -82,4 +108,105 @@ public class MaterialServiceImpl implements MaterialService { ...@@ -82,4 +108,105 @@ public class MaterialServiceImpl implements MaterialService {
public void delmaterialByIds(List<String> ids) { public void delmaterialByIds(List<String> ids) {
mapper.delMaterialByIds(ids); mapper.delMaterialByIds(ids);
} }
@Override
public MaterialDTO getHasChangeMadieMaterialById(String materialId, int from) {
MaterialDTO materialDTO = null ;
TabMaterialContent entity =null ;
if(from == 1) {
materialDTO = this.selectMaterialById(materialId);
}
if(from == 2) {
entity =this.materialContentMapper.selectById(materialId) ;
if(null != entity) {
materialDTO = EntityUtil.changeEntityByJSON(MaterialDTO.class, entity) ;
}
}
if (null == materialDTO) {
return null;
}
Date lastUploadTime = materialDTO.getWxLastUploadTime();
Date date = new Date();
Date compareDate = DateUtils.addDays(date, -3);
if (lastUploadTime != null && lastUploadTime.after(compareDate) && StringUtils.isNotBlank(materialDTO.getMediaId())) {
return materialDTO;
}
Integer materialType = materialDTO.getMaterialType();
String madiaId = materialDTO.getMediaId();
//需要上传的类型
List<Integer> typeList = Arrays.asList(2, 4, 5, 6);
if (typeList.contains(materialType)) {
madiaId = this.reUpdalodMetail(materialId,from);
}
materialDTO.setMediaId(madiaId);
materialDTO.setWxLastUploadTime(date);
return materialDTO;
}
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 "";
}
String[] arr = url.split("/");
int count = arr.length;
JSONResponse jp = null ;
if(from==2 && entity.getMediaType()==2) {
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 old.getMediaId();
}
} }
...@@ -27,7 +27,6 @@ import com.gic.haoban.common.utils.StringUtil; ...@@ -27,7 +27,6 @@ import com.gic.haoban.common.utils.StringUtil;
import com.gic.haoban.manage.api.dto.BatchAddMaterialDTO; 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.WxEnterpriseQwDTO; import com.gic.haoban.manage.api.dto.WxEnterpriseQwDTO;
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;
......
...@@ -44,10 +44,6 @@ ...@@ -44,10 +44,6 @@
</foreach> </foreach>
</select> </select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from tab_haoban_material
where material_id = #{materialId,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" > <insert id="insert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" >
insert into tab_haoban_material (material_id, from_material_id, material_title, material_type, insert into tab_haoban_material (material_id, from_material_id, material_title, material_type,
category_id, material_content, wx_last_upload_time, category_id, material_content, wx_last_upload_time,
...@@ -64,115 +60,7 @@ ...@@ -64,115 +60,7 @@
#{createTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP},
#{updateTime,jdbcType=TIMESTAMP}) #{updateTime,jdbcType=TIMESTAMP})
</insert> </insert>
<insert id="insertSelective" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" >
insert into tab_haoban_material
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="materialId != null" >
material_id,
</if>
<if test="materialTitle != null" >
material_title,
</if>
<if test="materialType != null" >
material_type,
</if>
<if test="categoryId != null" >
category_id,
</if>
<if test="materialContent != null" >
material_content,
</if>
<if test="wxLastUploadTime != null" >
wx_last_upload_time,
</if>
<if test="mediaId != null" >
media_id,
</if>
<if test="wxEnterpriseId != null" >
wx_enterprise_id,
</if>
<if test="staffId != null" >
staff_id,
</if>
<if test="staffName != null" >
staff_name,
</if>
<if test="imgUrl != null" >
img_url,
</if>
<if test="wxImgUrl != null" >
wx_img_url,
</if>
<if test="materialDesc != null" >
material_desc,
</if>
<if test="statusFlag != null" >
status_flag,
</if>
<if test="link != null" >
link,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="materialId != null" >
#{materialId,jdbcType=VARCHAR},
</if>
<if test="materialTitle != null" >
#{materialTitle,jdbcType=VARCHAR},
</if>
<if test="materialType != null" >
#{materialType,jdbcType=INTEGER},
</if>
<if test="categoryId != null" >
#{categoryId,jdbcType=VARCHAR},
</if>
<if test="materialContent != null" >
#{materialContent,jdbcType=VARCHAR},
</if>
<if test="wxLastUploadTime != null" >
#{wxLastUploadTime,jdbcType=TIMESTAMP},
</if>
<if test="mediaId != null" >
#{mediaId,jdbcType=VARCHAR},
</if>
<if test="wxEnterpriseId != null" >
#{wxEnterpriseId,jdbcType=VARCHAR},
</if>
<if test="staffId != null" >
#{staffId,jdbcType=VARCHAR},
</if>
<if test="staffName != null" >
#{staffName,jdbcType=VARCHAR},
</if>
<if test="imgUrl != null" >
#{imgUrl,jdbcType=VARCHAR},
</if>
<if test="wxImgUrl != null" >
#{wxImgUrl,jdbcType=VARCHAR},
</if>
<if test="materialDesc != null" >
#{materialDesc,jdbcType=VARCHAR},
</if>
<if test="statusFlag != null" >
#{statusFlag,jdbcType=INTEGER},
</if>
<if test="link != null" >
#{link,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<insert id="batchInsert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial"> <insert id="batchInsert" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial">
insert into tab_haoban_material insert into tab_haoban_material
...@@ -280,26 +168,6 @@ ...@@ -280,26 +168,6 @@
</set> </set>
where material_id = #{materialId,jdbcType=VARCHAR} where material_id = #{materialId,jdbcType=VARCHAR}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.gic.haoban.manage.service.entity.TabHaobanMaterial" >
update tab_haoban_material
set material_title = #{materialTitle,jdbcType=VARCHAR},
material_type = #{materialType,jdbcType=INTEGER},
category_id = #{categoryId,jdbcType=VARCHAR},
material_content = #{materialContent,jdbcType=VARCHAR},
wx_last_upload_time = #{wxLastUploadTime,jdbcType=TIMESTAMP},
media_id = #{mediaId,jdbcType=VARCHAR},
wx_enterprise_id = #{wxEnterpriseId,jdbcType=VARCHAR},
staff_id = #{staffId,jdbcType=VARCHAR},
staff_name = #{staffName,jdbcType=VARCHAR},
img_url = #{imgUrl,jdbcType=VARCHAR},
wx_img_url = #{wxImgUrl,jdbcType=VARCHAR},
material_desc = #{materialDesc,jdbcType=VARCHAR},
status_flag = #{statusFlag,jdbcType=INTEGER},
link = #{link,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where material_id = #{materialId,jdbcType=VARCHAR}
</update>
<select id="listMaterialByCategoryId" resultMap="BaseResultMap" parameterType="java.lang.String" > <select id="listMaterialByCategoryId" resultMap="BaseResultMap" parameterType="java.lang.String" >
select select
......
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