客户公海代码测试提交;

1 parent eca6b40e
package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.wecom.domain.WeCustomerSeas;
import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo;
import com.linkwechat.wecom.service.IWeCustomerMessagePushService;
import com.linkwechat.wecom.service.IWeCustomerSeasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* 客户公海相关
......@@ -17,6 +33,175 @@ public class WeCustomerSeasController extends BaseController {
private IWeCustomerSeasService iWeCustomerSeasService;
@Autowired
private IWeCustomerMessagePushService iWeCustomerMessagePushService;
/**
* 客户公海模版下载
* @return
*/
@GetMapping("/importTemplate")
public AjaxResult importTemplate()
{
ExcelUtil<WeCustomerSeas> util = new ExcelUtil<WeCustomerSeas>(WeCustomerSeas.class);
return util.importTemplateExcel( DateUtils.dateTimeNow(DateUtils.YYYY_MM_DD)+"_客户公海");
}
/**
* 导入公海数据
* @param file
* @param weCustomerSea
* @return
*/
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, WeCustomerSeas weCustomerSea) throws Exception {
ExcelUtil<WeCustomerSeas> util = new ExcelUtil<WeCustomerSeas>(WeCustomerSeas.class);
List<WeCustomerSeas> weCustomerSeas = util.importExcel(file.getInputStream());
if(CollectionUtil.isNotEmpty(weCustomerSeas)){
if(StringUtils.isEmpty(weCustomerSea.getAddUserName())&&StringUtils.isEmpty(weCustomerSea.getAddUserId())){
return AjaxResult.error("分配人不可为空!");
}
//过滤字段为空的数据
List<WeCustomerSeas> deduplicationSeas = weCustomerSeas.stream().filter(s -> StringUtils.isNotEmpty(s.getCustomerName())
|| StringUtils.isNotEmpty(s.getPhone())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(deduplicationSeas)){
return AjaxResult.error("导入用户数据不能为空!");
}
//跟根据手机号去重
List<WeCustomerSeas> deduplicationSeasNoRepeat=deduplicationSeas.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(WeCustomerSeas :: getPhone))), ArrayList::new));
Long tabaleExcelId= SnowFlakeUtil.nextId();
List<String> userIds = ListUtil.toList(weCustomerSea.getAddUserId().split(","));
List<String> userNames = ListUtil.toList(weCustomerSea.getAddUserName().split(","));
IntStream.range(0,deduplicationSeasNoRepeat.size()).forEach(i->{
WeCustomerSeas k = deduplicationSeasNoRepeat.get(i);
if(Objects.nonNull(k)){
k.setTagIds(weCustomerSea.getTagIds());
k.setTagNames(weCustomerSea.getTagNames());
k.setAddUserId( userIds.get(Math.floorMod(i, userIds.size())));
k.setAddUserName(userNames.get(Math.floorMod(i, userNames.size())));
k.setTableExcelName(file.getOriginalFilename());
k.setTableExcelId(tabaleExcelId);
}
});
iWeCustomerSeasService.saveBatch(deduplicationSeasNoRepeat);
}else{
return AjaxResult.error("导入用户数据不能为空!");
}
return AjaxResult.success();
}
/**
* 获取公海客户列表
* @param weCustomerSea
* @return
*/
@GetMapping("list")
public TableDataInfo list(WeCustomerSeas weCustomerSea){
startPage();
List<WeCustomerSeas> weCustomerSeas = iWeCustomerSeasService.list(
new LambdaQueryWrapper<WeCustomerSeas>()
.eq(StringUtils.isNotEmpty(weCustomerSea.getPhone()),WeCustomerSeas::getPhone,weCustomerSea.getPhone())
.like(StringUtils.isNotEmpty(weCustomerSea.getCustomerName()),WeCustomerSeas::getCustomerName,weCustomerSea.getCustomerName())
.like(StringUtils.isNotEmpty(weCustomerSea.getAddUserName()),WeCustomerSeas::getAddUserName,weCustomerSea.getAddUserName())
.eq(weCustomerSea.getAddState() !=null ,WeCustomerSeas::getAddState,weCustomerSea.getAddState())
);
return getDataTable(weCustomerSeas);
}
/**
* 删除公海客户
* @param ids
* @return
*/
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
iWeCustomerSeasService.removeByIds(
ListUtil.toList(ids)
);
return AjaxResult.success();
}
/**
* 提醒员工
* @param ids
* @return
*/
@PostMapping("/remidUser/{ids}")
public AjaxResult remidUser(@PathVariable Long[] ids){
List<WeCustomerSeas> weCustomerSeas
= iWeCustomerSeasService.listByIds(ListUtil.toList(ids));
if(CollectionUtil.isNotEmpty(weCustomerSeas)){
weCustomerSeas.stream().collect(Collectors.groupingBy(WeCustomerSeas::getAddUserId)).forEach((k,v)->{
String messageRemindContent="管理员给你分配了"+v.size()+"个客户还未添加,快去复制电话号码添加客户吧,<a href='%s?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect'>点击查看详情</a>";
iWeCustomerMessagePushService.messagePushRemind(messageRemindContent,k);
});
}
return AjaxResult.success();
}
/**
* 获取指定员工所拥有的状态(移动端)
* @param userId
* @param addState
* @return
*/
@GetMapping("/findEmployeeCustomer")
public TableDataInfo findEmployeeCustomer(String userId,Integer addState){
startPage();
List<WeCustomerSeas> weCustomerSeas = iWeCustomerSeasService.list(new LambdaQueryWrapper<WeCustomerSeas>()
.eq(StringUtils.isNotEmpty(userId),WeCustomerSeas::getAddUserId, userId)
.eq(addState != null,WeCustomerSeas::getAddState, addState));
return getDataTable(weCustomerSeas);
}
/**
* 详情头部统计
* @return
*/
@GetMapping("/countCustomerSeas")
public AjaxResult countCustomerSeas(){
return AjaxResult.success(
iWeCustomerSeasService.countCustomerSeas()
);
}
/**
* 导入记录或员工添加统计
* @param groupByType 1:获取导入记录数据 2:员工添加统计
* @return
*/
@GetMapping("/findSeasRecord")
public TableDataInfo findSeasRecord(@RequestParam(defaultValue = "1") Integer groupByType){
startPage();
List<CustomerSeasRecordVo> seasRecord = iWeCustomerSeasService.findSeasRecord(groupByType);
return getDataTable(seasRecord);
}
......
......@@ -100,7 +100,7 @@ public class RuoYiConfig
return "D:/linkWeChat/uploadPath";
}
return "/linkWeChat/uploadPath";
return "/Users/robin/work/sr_project/lw";
}
public void setProfile(String profile)
......
......@@ -9,17 +9,11 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
import com.linkwechat.common.utils.StringUtils;
import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
......@@ -54,6 +48,12 @@ import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.DictUtils;
import com.linkwechat.common.utils.reflect.ReflectUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
/**
* Excel相关处理
......@@ -732,7 +732,8 @@ public class ExcelUtil<T>
*/
public String encodingFilename(String filename)
{
filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
// filename = UUID.randomUUID().toString() + "_" + filename + ".xlsx";
filename = filename + ".xlsx";
return filename;
}
......@@ -933,4 +934,26 @@ public class ExcelUtil<T>
}
return val;
}
public static void downloadExcel(HttpServletResponse httpServletResponse,String fileName) throws Exception {
InputStream inputStream = new ClassPathResource("/excel/seas.xlsx").getInputStream();
//设置响应类型
httpServletResponse.setContentType("multipart/form-data;charset=utf-8");
httpServletResponse.addHeader("Content-Disposition",
" attachment;filename=" + new String(fileName.getBytes(), "iso-8859-1"));
if(Objects.nonNull(inputStream)){
try(ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream()){
IOUtils.copy(inputStream, servletOutputStream);
httpServletResponse.flushBuffer();
}catch (Exception e){
log.error("模版下载失败"+fileName+":"+e.getMessage());
}
}
}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.linkwechat.wecom.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.linkwechat.common.annotation.Excel;
import com.linkwechat.common.core.domain.BaseEntity;
import lombok.Data;
......@@ -17,9 +18,11 @@ public class WeCustomerSeas extends BaseEntity {
private Long id;
//手机号
@Excel(name = "手机号")
private String phone;
//客户备注名称
@Excel(name = "客户名称")
private String customerName;
//标签名,多个使用逗号隔开
......@@ -45,4 +48,6 @@ public class WeCustomerSeas extends BaseEntity {
@TableLogic
private Integer delFlag;
}
package com.linkwechat.wecom.domain.vo;
import lombok.Data;
/**
* 客户公海统计
*/
@Data
public class CustomerSeasCountVo {
//导入客户总数
private Integer importCustomerTotalNum;
//已添加客户数
private Integer addCustomerNum;
//完成率
private Float completionRate;
//等待添加客户数
private Integer waitAddCustomerNum;
//等待通过客户数
private Integer waitPassCustomerNum;
}
package com.linkwechat.wecom.domain.vo;
import lombok.Data;
import java.util.Date;
/**
* 公海导入记录
*/
@Data
public class CustomerSeasRecordVo {
//导入表格名称
private String tableExcelName;
//导入客户总数
private Integer cutomerTotalNum;
//导入时间
private Date createTime;
//分配员工
private String addUserName;
//已添加客户数
private Integer addCustomerNum;
//待添加客户数
private Integer waitAddCustomerNum;
//待通过客户数
private Integer waitPassCustomerNum;
//添加完成率
private Float completionRate;
}
......@@ -2,6 +2,14 @@ package com.linkwechat.wecom.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.linkwechat.wecom.domain.WeCustomerSeas;
import com.linkwechat.wecom.domain.vo.CustomerSeasCountVo;
import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface WeCustomerSeasMapper extends BaseMapper<WeCustomerSeas> {
CustomerSeasCountVo countCustomerSeas();
List<CustomerSeasRecordVo> findSeasRecord(@Param("groupByType") Integer groupByType);
}
......@@ -34,4 +34,12 @@ public interface IWeCustomerMessagePushService {
*/
public List<CustomerMessagePushVo> customerMessagePushs(String sender,String content,String pushType,String beginTime,String endTime);
/**
* 消息推送提醒
* @param messageRemindContent
* @param toUserId
*/
public void messagePushRemind(String messageRemindContent,String toUserId);
}
......@@ -2,6 +2,16 @@ package com.linkwechat.wecom.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeCustomerSeas;
import com.linkwechat.wecom.domain.vo.CustomerSeasCountVo;
import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo;
import java.util.List;
public interface IWeCustomerSeasService extends IService<WeCustomerSeas> {
CustomerSeasCountVo countCustomerSeas();
List<CustomerSeasRecordVo> findSeasRecord(Integer groupByType);
}
......@@ -7,19 +7,25 @@ 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.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.enums.MediaType;
import com.linkwechat.common.enums.MessageType;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeCustomerMessagePushClient;
import com.linkwechat.wecom.client.WeMessagePushClient;
import com.linkwechat.wecom.domain.WeCustomer;
import com.linkwechat.wecom.domain.WeCustomerList;
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.WeMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.CustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.ImageMessageDto;
import com.linkwechat.wecom.domain.dto.message.TextMessageDto;
import com.linkwechat.wecom.domain.vo.CustomerMessagePushVo;
import com.linkwechat.wecom.mapper.WeCustomerMessageTimeTaskMapper;
import com.linkwechat.wecom.service.*;
......@@ -31,10 +37,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -82,6 +85,13 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
@Autowired
private IWeMaterialService materialService;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@Autowired
private WeMessagePushClient weMessagePushClient;
@Override
@Transactional(rollbackFor = Exception.class)
public void addWeCustomerMessagePush(CustomerMessagePushDto customerMessagePushDto) throws JsonProcessingException, ParseException, CloneNotSupportedException {
......@@ -192,6 +202,8 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
return weCustomerMessageOriginalService.customerMessagePushs(sender, content, pushType, beginTime, endTime);
}
/**
* 客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户
*
......@@ -251,4 +263,29 @@ public class WeCustomerMessagePushServiceImpl implements IWeCustomerMessagePushS
}
}
/**
* 员工推送文字消息
* @param messageRemindContent
* @param toUserId
*/
@Override
public void messagePushRemind(String messageRemindContent,String toUserId) {
WeCorpAccount validWeCorpAccount = weCorpAccountService.findValidWeCorpAccount();
if(null != weCorpAccountService){
if(StringUtils.isNotEmpty(validWeCorpAccount.getAgentId())&&
StringUtils.isNotEmpty(validWeCorpAccount.getAgentSecret())){
TextMessageDto textMessageDto = new TextMessageDto();
textMessageDto.setContent(messageRemindContent);
WeMessagePushDto weMessagePushDto = new WeMessagePushDto();
weMessagePushDto.setMsgtype(MessageType.TEXT.getMessageType());
weMessagePushDto.setTouser(toUserId);
weMessagePushDto.setText(textMessageDto);
weMessagePushDto.setAgentid(Integer.valueOf(validWeCorpAccount.getAgentId()));
weMessagePushClient.sendMessageToUser(weMessagePushDto,weMessagePushDto.getAgentid().toString());
}
}
}
}
package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeCustomerSeas;
import com.linkwechat.wecom.domain.vo.CustomerSeasCountVo;
import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo;
import com.linkwechat.wecom.mapper.WeCustomerSeasMapper;
import com.linkwechat.wecom.service.IWeCustomerSeasService;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
public class WeCustomerSeasServiceImpl extends ServiceImpl<WeCustomerSeasMapper, WeCustomerSeas> implements IWeCustomerSeasService {
@Override
public CustomerSeasCountVo countCustomerSeas() {
return this.baseMapper.countCustomerSeas();
}
@Override
public List<CustomerSeasRecordVo> findSeasRecord(Integer groupByType) {
return this.baseMapper.findSeasRecord(groupByType);
}
}
......@@ -5,5 +5,41 @@
<mapper namespace="com.linkwechat.wecom.mapper.WeCustomerSeasMapper">
<select id="countCustomerSeas" resultType="com.linkwechat.wecom.domain.vo.CustomerSeasCountVo">
SELECT
COUNT(*) AS importCustomerTotalNum,
COUNT(IF(add_state=1,true,NULL)) AS addCustomerNum,
IFNULL(ROUND(COUNT(IF(add_state=1,true,NULL))/COUNT(*)*100,2),0) AS completionRate,
COUNT(IF(add_state=0,true,NULL)) AS waitAddCustomerNum,
COUNT(IF(add_state=3,true,NULL)) AS waitPassCustomerNum
FROM
we_customer_seas
</select>
<select id="findSeasRecord" resultType="com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo">
SELECT
table_excel_name,
count(*) as cutomerTotalNum,
create_time,
GROUP_CONCAT(DISTINCT add_user_name) as addUserName,
COUNT(IF(add_state=1,true,NULL)) AS addCustomerNum,
COUNT(IF(add_state=0,true,NULL)) AS waitAddCustomerNum,
COUNT(IF(add_state=3,true,NULL)) AS waitPassCustomerNum,
IFNULL(ROUND(COUNT(IF(add_state=1,true,NULL))/COUNT(*)*100,2),0) AS completionRate
FROM
we_customer_seas
GROUP BY
<choose>
<when test="groupByType==1">
table_excel_id
</when>
<otherwise>
add_user_id
</otherwise>
</choose>
ORDER BY create_time DESC
</select>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!