Commit 3c532b67 by 水库浪子

修改群发,任务宝图片上传等BUG;

1 parent 04e3839d
......@@ -36,7 +36,6 @@ public class WeCustomerMessagePushController extends BaseController {
@Autowired
@Lazy
private IWeCustomerMessagePushService weCustomerMessagePushService;
@Autowired
......@@ -59,7 +58,7 @@ public class WeCustomerMessagePushController extends BaseController {
SecurityContextHolder.setContext(context);
weCustomerMessagePushService.addWeCustomerMessagePush(customerMessagePushDto);
} catch (JsonProcessingException | ParseException e) {
} catch (JsonProcessingException | ParseException | CloneNotSupportedException e) {
e.printStackTrace();
return AjaxResult.error("群发失败");
}
......
......@@ -18,6 +18,8 @@ import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUploadUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.framework.web.domain.server.SysFile;
import com.linkwechat.framework.web.service.FileService;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeTaskFission;
import com.linkwechat.wecom.domain.dto.WeChatUserDTO;
......@@ -55,9 +57,13 @@ import java.util.Objects;
public class WeTaskFissionController extends BaseController {
@Autowired
private IWeTaskFissionService weTaskFissionService;
@Autowired
private CosConfig cosConfig;
@Autowired
private FileService fileService;
/**
* 查询任务宝列表
*/
......@@ -226,10 +232,13 @@ public class WeTaskFissionController extends BaseController {
@Log(title = "上传兑奖图片", businessType = BusinessType.OTHER)
@PostMapping("/upload")
@ApiOperation(value = "上传兑奖图片", httpMethod = "POST")
public AjaxResult<JSONObject> upload(@RequestParam(value = "file") MultipartFile file) throws IOException {
String url = FileUploadUtils.upload2Cos(file, cosConfig);
public AjaxResult<JSONObject> upload(@RequestParam(value = "file") MultipartFile file) throws Exception {
SysFile sysFile
= fileService.upload(file);
// String url = FileUploadUtils.upload2Cos(file, cosConfig);
JSONObject json = new JSONObject();
json.put("rewardImageUrl", cosConfig.getCosImgUrlPrefix()+url);
json.put("rewardImageUrl", sysFile.getImgUrlPrefix()+sysFile.getFileName());
return AjaxResult.success(json);
}
......
......@@ -2,6 +2,7 @@ package com.linkwechat.wecom.domain.dto.message;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -9,7 +10,7 @@ import java.util.List;
*/
@SuppressWarnings("all")
@Data
public class CustomerMessagePushDto {
public class CustomerMessagePushDto implements Cloneable{
/**
* 群发类型 0 发给客户 1 发给客户群
......@@ -108,4 +109,25 @@ public class CustomerMessagePushDto {
}
@Override
public CustomerMessagePushDto clone() throws CloneNotSupportedException {
return (CustomerMessagePushDto) super.clone();
}
public List<CustomerMessagePushDto> handleImageAndText() throws CloneNotSupportedException {
List<CustomerMessagePushDto> customerMessagePushDtos=new ArrayList<>();
CustomerMessagePushDto cloneOne = this.clone();
cloneOne.setMessageType("0");
customerMessagePushDtos.add(cloneOne);
CustomerMessagePushDto cloneTwo = this.clone();
cloneTwo.setMessageType("1");
customerMessagePushDtos.add(cloneTwo);
return customerMessagePushDtos;
}
}
......@@ -99,4 +99,14 @@ public interface WeCustomerMapper extends BaseMapper<WeCustomer>
WeCustomerSocialConn countSocialConn(@Param("externalUserid")String externalUserid,@Param("userid")String userid);
/**
* 查询企业微信客户列表,不查询一对多关系相关数据
*
* @param weCustomer 企业微信客户
* @return 企业微信客户集合
*/
public List<WeCustomer> selectWeCustomerListNoRel(WeCustomer weCustomer);
}
......@@ -18,9 +18,9 @@ public interface IWeCustomerMessagePushService {
/**
* 新增群发消息发送
*
*@param customerMessagePushDto 原始数据信息
*@param customerMessagePush 原始数据信息
*/
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException, ParseException;
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePush) throws JsonProcessingException, ParseException, CloneNotSupportedException;
/**
* 群发消息列表
......
......@@ -135,4 +135,16 @@ public interface IWeCustomerService extends IService<WeCustomer>
*/
public List<WeCustomer> selectWeCustomerAllList(WeCustomer weCustomer);
/**
* 查询企业微信客户列表,不查询一对多关系相关数据
*
* @param weCustomer 企业微信客户
* @return 企业微信客户集合
*/
List<WeCustomer> selectWeCustomerListNoRel(WeCustomer weCustomer);
}
......@@ -2,11 +2,13 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
......@@ -14,7 +16,9 @@ import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerMessageTimeTask;
import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.dto.WeMediaDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.ImageMessageDto;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import com.linkwechat.wecom.mapper.WeCustomerMessageTimeTaskMapper;
import com.linkwechat.wecom.service.*;
......@@ -71,71 +75,109 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
@Autowired
private WeCustomerMessageTimeTaskMapper customerMessageTimeTaskMapper;
@Autowired
private IWeMaterialService materialService;
@Override
@Transactional(rollbackFor = Exception.class)
@Async
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException, ParseException {
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePush) throws JsonProcessingException, ParseException, CloneNotSupportedException {
// if ((null != customerMessagePushDto.getSettingTime() && !"".equals(customerMessagePushDto.getSettingTime()))
// && DateUtils.diffTime(new Date(), DateUtil.parse(customerMessagePushDto.getSettingTime(), "yyyy-MM-dd HH:mm")) > 0) {
// throw new WeComException("发送时间不能小于当前时间");
// }
if(StrUtil.isNotBlank(customerMessagePushDto.getSettingTime())){
if(DateUtils.diffTime(new Date(), DateUtil.parse(customerMessagePushDto.getSettingTime(), "yyyy-MM-dd HH:mm")) > 0){
if(StrUtil.isNotBlank(customerMessagePush.getSettingTime())){
if(DateUtils.diffTime(new Date(), DateUtil.parse(customerMessagePush.getSettingTime(), "yyyy-MM-dd HH:mm")) > 0){
throw new WeComException("发送时间不能小于当前时间");
}
}
/*if(StrUtil.isBlank(customerMessagePushDto.getSettingTime())){
throw new WeComException("发送时间不能为空");
}*/
List<CustomerMessagePushDto> customerMessagePushDtos=new ArrayList<>();
if(customerMessagePush.getMessageType().equals("4")){
customerMessagePushDtos=customerMessagePush.handleImageAndText();
List<WeCustomer> customers = Lists.newArrayList();
List<WeGroup> groups = new ArrayList<>();
// 0 发给客户
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
//查询客户信息列表
if ("all".equals(customerMessagePushDto.getTag())) {
customers = externalUserIds(WeConstans.SEND_MESSAGE_CUSTOMER_ALL, customerMessagePushDto.getStaffId(), customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
} else {
customers = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId()
, customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
}
if (CollectionUtils.isEmpty(customers)) {
throw new WeComException("没有外部联系人");
}
}else{
customerMessagePushDtos.add(customerMessagePush);
}
// 1 发给客户群
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)) {
if (customerMessagePushDto.getStaffId() == null || customerMessagePushDto.getStaffId().equals("")) {
throw new WeComException("请选择人员!");
}
//通过员工id查询群列表
WeGroup weGroup = new WeGroup();
weGroup.setUserIds(customerMessagePushDto.getStaffId());
groups = weGroupService.selectWeGroupList(weGroup);
if (CollectionUtils.isEmpty(groups)) {
throw new WeComException("没有客户群!");
for(CustomerMessagePushDto customerMessagePushDto:customerMessagePushDtos){
if(customerMessagePush.getMessageType().equals("1")){//等于图片或者图文,根据图片URL,获取新的media_id
ImageMessageDto imageMessage = customerMessagePushDto.getImageMessage();
if(null != imageMessage && StrUtil.isNotBlank(imageMessage.getPic_url())){
WeMediaDto weMediaDto = materialService.uploadTemporaryMaterial(imageMessage.getPic_url(),
MediaType.IMAGE.getMediaType()
,imageMessage.getPic_url());
if(StrUtil.isNotBlank(weMediaDto.getMedia_id())){
imageMessage.setMedia_id(weMediaDto.getMedia_id());
}
}
}
List<WeCustomer> customers = Lists.newArrayList();
List<WeGroup> groups = new ArrayList<>();
// 0 发给客户
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_CUSTOMER)) {
//查询客户信息列表
if ("all".equals(customerMessagePushDto.getTag())) {
customers = externalUserIds(WeConstans.SEND_MESSAGE_CUSTOMER_ALL, customerMessagePushDto.getStaffId(), customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
} else {
customers = externalUserIds(customerMessagePushDto.getPushRange(), customerMessagePushDto.getStaffId()
, customerMessagePushDto.getDepartment(), customerMessagePushDto.getTag());
}
if (CollectionUtils.isEmpty(customers)) {
throw new WeComException("没有外部联系人");
}
}
// 1 发给客户群
if (customerMessagePushDto.getPushType().equals(WeConstans.SEND_MESSAGE_GROUP)) {
if (customerMessagePushDto.getStaffId() == null || customerMessagePushDto.getStaffId().equals("")) {
throw new WeComException("请选择人员!");
}
//通过员工id查询群列表
WeGroup weGroup = new WeGroup();
weGroup.setUserIds(customerMessagePushDto.getStaffId());
groups = weGroupService.selectWeGroupList(weGroup);
if (CollectionUtils.isEmpty(groups)) {
throw new WeComException("没有客户群!");
}
}
//保存原始数据信息表
long messageOriginalId = weCustomerMessageOriginalService.saveWeCustomerMessageOriginal(customerMessagePushDto);
long messageId = SnowFlakeUtil.nextId();
//保存映射信息
int size = weCustomerMessgaeResultService.workerMappingCustomer(customerMessagePushDto, messageId, customers, groups);
//保存微信消息
weCustomerMessageService.saveWeCustomerMessage(messageId, messageOriginalId, customerMessagePushDto, size, customerMessagePushDto.content());
//保存分类消息信息
weCustomerSeedMessageService.saveSeedMessage(customerMessagePushDto, messageId);
this.sendMessage(customerMessagePushDto,messageId,customers,groups);
}
}
//保存原始数据信息表
long messageOriginalId = weCustomerMessageOriginalService.saveWeCustomerMessageOriginal(customerMessagePushDto);
long messageId = SnowFlakeUtil.nextId();
}
//保存映射信息
int size = weCustomerMessgaeResultService.workerMappingCustomer(customerMessagePushDto, messageId, customers, groups);
//保存微信消息
weCustomerMessageService.saveWeCustomerMessage(messageId, messageOriginalId, customerMessagePushDto, size, customerMessagePushDto.content());
//保存分类消息信息
weCustomerSeedMessageService.saveSeedMessage(customerMessagePushDto, messageId);
private void sendMessage(CustomerMessagePushDto customerMessagePushDto, long messageId, List<WeCustomer> customers,List<WeGroup> groups ) throws ParseException, JsonProcessingException {
//发送群发消息
//调用微信api发送消息
......@@ -146,6 +188,9 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
, DateUtils.getMillionSceondsBydate(customerMessagePushDto.getSettingTime()));
customerMessageTimeTaskMapper.saveWeCustomerMessageTimeTask(timeTask);
}
}
@Override
......@@ -173,8 +218,14 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
customers = weCustomerService.selectWeCustomerAllList(weCustomer);
redisCache.setCacheList(WeConstans.WECUSTOMERS_KEY, customers);
redisCache.expire(WeConstans.WECUSTOMERS_KEY,2 * 60L);
}else{
return customers;
}
return customers;
WeCustomer weCustomer = new WeCustomer();
weCustomer.setUserIds(staffId);
weCustomer.setDepartmentIds(department);
return weCustomerService.selectWeCustomerListNoRel(weCustomer);
} else {
//按条件查询客户
//通过部门id查询所有的员工
......@@ -183,7 +234,7 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
weCustomer.setUserIds(staffId);
weCustomer.setTagIds(tag);
weCustomer.setDepartmentIds(department);
return weCustomerService.selectWeCustomerAllList(weCustomer);
return weCustomerService.selectWeCustomerListNoRel(weCustomer);
}
}
......
......@@ -712,5 +712,10 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
return weCustomerMapper.selectWeCustomerList(weCustomer);
}
@Override
public List<WeCustomer> selectWeCustomerListNoRel(WeCustomer weCustomer) {
return weCustomerMapper.selectWeCustomerListNoRel(weCustomer);
}
}
......@@ -246,7 +246,7 @@ public class WeTaskFissionServiceImpl extends ServiceImpl<WeTaskFissionMapper, W
SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_INHERITABLETHREADLOCAL);
SecurityContextHolder.setContext(context);
weCustomerMessagePushService.addWeCustomerMessagePush(customerMessagePushDto);
} catch (JsonProcessingException | ParseException e) {
} catch (JsonProcessingException | ParseException | CloneNotSupportedException e) {
e.printStackTrace();
log.error("发送任务失败》》》》》》》》》》》params:{},ex:{}", JSONObject.toJSONString(customerMessagePushDto), e);
}
......
......@@ -3,7 +3,118 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeCustomerMapper">
<resultMap type="com.linkwechat.wecom.domain.WeCustomer" id="WeCustomerResultNoRel">
<id property="externalUserid" column="external_userid" />
<result property="name" column="name" />
<result property="avatar" column="avatar" />
<result property="type" column="type" />
<result property="gender" column="gender" />
<result property="unionid" column="unionid" />
<result property="birthday" column="birthday" />
<result property="corpName" column="corp_name" />
<result property="corpFullName" column="corp_full_name" />
<result property="position" column="position" />
<result property="userName" column="user_name" />
<result property="userId" column="user_id" />
<result property="isOpenChat" column="is_open_chat" jdbcType="INTEGER" />
</resultMap>
<select id="selectWeCustomerListNoRel" parameterType="WeCustomer" resultMap="WeCustomerResultNoRel">
SELECT
DISTINCT wc.external_userid,
wc.`name`,
wc.avatar,
wc.type,
wc.gender,
wc.unionid,
wc.birthday,
wc.corp_name,
wc.corp_full_name,
wc.position,
wc.is_open_chat,
wfcr.id as wfcrId,
wfcr.user_id,
wfcr.remark,
wfcr.description,
wfcr.create_time,
wfcr.remark_corp_name,
wfcr.oper_userid,
wfcr.add_way,
wfcr.state,
wfcr.status,
wu.user_name,
(SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department
FROM
we_customer wc
LEFT JOIN we_flower_customer_rel wfcr ON wc.external_userid=wfcr.external_userid
LEFT JOIN we_user wu ON wu.user_id=wfcr.user_id
LEFT JOIN we_flower_customer_tag_rel wfcrf ON wfcrf.flower_customer_rel_id = wfcr.id
LEFT JOIN we_tag wt ON wt.tag_id = wfcrf.tag_id
<where>
<if test="name != null and name !=''">
AND wc.name like concat('%', #{name}, '%')
</if>
<if test="userIds != null and userIds !=''">
<if test="userIds.indexOf(',') != -1">
AND wfcr.user_id in
<foreach item="item" index="index" collection="userIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="userIds.indexOf(',') == -1">
AND wfcr.user_id=#{userIds}
</if>
</if>
<if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
</if>
<if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
AND date_format(wfcr.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
</if>
<if test="tagIds != null and tagIds !=''">
<if test="tagIds.indexOf(',') != -1">
AND wt.tag_id in
<foreach item="item" index="index" collection="tagIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="tagIds.indexOf(',') == -1">
AND wt.tag_id=#{tagIds}
</if>
</if>
<if test="departmentIds != null and departmentIds !=''">
<if test="departmentIds.indexOf(',') != -1">
OR wu.department in
<foreach item="item" index="index" collection="departmentIds.split(',')" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="departmentIds.indexOf(',') == -1">
OR wu.department=#{departmentIds}
</if>
</if>
<if test="status !=null and status !=''">
AND wfcr.status=#{status}
</if>
<if test="isOpenChat !=null ">
AND wc.is_open_chat=#{isOpenChat}
</if>
</where>
ORDER BY wfcr.create_time DESC
</select>
<resultMap type="com.linkwechat.wecom.domain.WeCustomer" id="WeCustomerResult">
<id property="externalUserid" column="external_userid" />
<result property="name" column="name" />
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!