离职分配相关bug

1 parent bf5d4b07
...@@ -11,6 +11,7 @@ import com.linkwechat.common.exception.CustomException; ...@@ -11,6 +11,7 @@ import com.linkwechat.common.exception.CustomException;
import com.linkwechat.common.utils.DateUtils; import com.linkwechat.common.utils.DateUtils;
import com.linkwechat.common.utils.SnowFlakeUtil; import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.ValidateUtils;
import com.linkwechat.common.utils.poi.ExcelUtil; import com.linkwechat.common.utils.poi.ExcelUtil;
import com.linkwechat.wecom.domain.WeCustomerSeas; import com.linkwechat.wecom.domain.WeCustomerSeas;
import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo; import com.linkwechat.wecom.domain.vo.CustomerSeasRecordVo;
...@@ -71,8 +72,16 @@ public class WeCustomerSeasController extends BaseController { ...@@ -71,8 +72,16 @@ public class WeCustomerSeasController extends BaseController {
if(StringUtils.isEmpty(weCustomerSea.getAddUserName())&&StringUtils.isEmpty(weCustomerSea.getAddUserId())){ if(StringUtils.isEmpty(weCustomerSea.getAddUserName())&&StringUtils.isEmpty(weCustomerSea.getAddUserId())){
return AjaxResult.error("分配人不可为空!"); return AjaxResult.error("分配人不可为空!");
} }
//过滤不符合规范的手机号
List<WeCustomerSeas> noRuleWeCustomerSeas
= weCustomerSeas.stream().filter(s -> ValidateUtils.isMobile(s.getPhone())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(noRuleWeCustomerSeas)){
return AjaxResult.error("请传入合法手机号!");
}
//过滤字段为空的数据 //过滤字段为空的数据
List<WeCustomerSeas> deduplicationSeas = weCustomerSeas.stream().filter(s -> StringUtils.isNotEmpty(s.getCustomerName()) List<WeCustomerSeas> deduplicationSeas = noRuleWeCustomerSeas.stream().filter(s -> StringUtils.isNotEmpty(s.getCustomerName())
|| StringUtils.isNotEmpty(s.getPhone())).collect(Collectors.toList()); || StringUtils.isNotEmpty(s.getPhone())).collect(Collectors.toList());
if(CollectionUtil.isEmpty(deduplicationSeas)){ if(CollectionUtil.isEmpty(deduplicationSeas)){
return AjaxResult.error("导入用户数据不能为空!"); return AjaxResult.error("导入用户数据不能为空!");
......
package com.linkwechat.common.enums;
/**
* 群分配状态
*/
public enum AllocateGroupStatus {
ALLOCATE_GROUP_STATUS_BJTCG(0,"被接替成功"),
ALLOCATE_GROUP_STATUS_DJT(1,"待接替"),
ALLOCATE_GROUP_STATUS_JTSB(2,"接替失败"),
ALLOCATE_GROUP_STATUS_ZCZT(3,"正常状态");
private Integer key;
private String val;
AllocateGroupStatus(Integer key,String val){
this.key=key;
this.val=val;
}
public Integer getKey() {
return key;
}
public void setKey(Integer key) {
this.key = key;
}
public String getVal() {
return val;
}
public void setVal(String val) {
this.val = val;
}
}
package com.linkwechat.common.utils;
import java.util.regex.Pattern;
public class ValidateUtils {
private static final String REGEX_MOBILE ="((\\+86|0086)?\\s*)((134[0-8]\\d{7})|(((13([0-3]|[5-9]))|(14[5-9])|15([0-3]|[5-9])|(16(2|[5-7]))|17([0-3]|[5-8])|18[0-9]|19(1|[8-9]))\\d{8})|(14(0|1|4)0\\d{7})|(1740([0-5]|[6-9]|[10-12])\\d{7}))";
/**
* 判断是否是手机号
* @param tel 手机号
* @return boolean true:是 false:否
*/
public static boolean isMobile(String tel) {
if (StringUtils.isEmpty(tel)){ return false;}
return Pattern.matches(REGEX_MOBILE, tel);
}
}
package com.linkwechat.common.utils.file;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.mp3.MP3AudioHeader;
import org.jaudiotagger.audio.mp3.MP3File;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import java.io.File;
public class AudioUtil {
/**
* 获取语音文件播放时长(秒) 支持wav 格式
* @param filePath
* @return
*/
public static Float getDuration(String filePath){
try{
File destFile = new File(filePath);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(destFile);
AudioFormat format = audioInputStream.getFormat();
long audioFileLength = destFile.length();
int frameSize = format.getFrameSize();
float frameRate = format.getFrameRate();
float durationInSeconds = (audioFileLength / (frameSize * frameRate));
return durationInSeconds;
}catch (Exception e){
e.printStackTrace();
return 0f;
}
}
/**
* 获取mp3语音文件播放时长(秒) mp3
* @param filePath
* @return
*/
public static Float getMp3Duration(String filePath){
try {
File mp3File = new File(filePath);
MP3File f = (MP3File) AudioFileIO.read(mp3File);
MP3AudioHeader audioHeader = (MP3AudioHeader)f.getAudioHeader();
return Float.parseFloat(audioHeader.getTrackLength()+"");
} catch(Exception e) {
e.printStackTrace();
return 0f;
}
}
/**
* 获取mp3语音文件播放时长(秒)
* @param mp3File
* @return
*/
public static Float getMp3Duration(File mp3File){
try {
//File mp3File = new File(filePath);
MP3File f = (MP3File) AudioFileIO.read(mp3File);
MP3AudioHeader audioHeader = (MP3AudioHeader)f.getAudioHeader();
return Float.parseFloat(audioHeader.getTrackLength()+"");
} catch(Exception e) {
e.printStackTrace();
return 0f;
}
}
/**
* 得到pcm文件的毫秒数
*
* pcm文件音频时长计算
* 同图像bmp文件一样,pcm文件保存的是未压缩的音频信息。 16bits 编码是指,每次采样的音频信息用2个字节保存。可以对比下bmp文件用分别用2个字节保存RGB颜色的信息。 16000采样率 是指 1秒钟采样 16000次。常见的音频是44100HZ,即一秒采样44100次。 单声道: 只有一个声道。
*
* 根据这些信息,我们可以计算: 1秒的16000采样率音频文件大小是 2*16000 = 32000字节 ,约为32K 1秒的8000采样率音频文件大小是 2*8000 = 16000字节 ,约为 16K
*
* 如果已知录音时长,可以根据文件的大小计算采样率是否正常。
* @param filePath
* @return
*/
public static long getPCMDurationMilliSecond(String filePath) {
File file = new File(filePath);
//得到多少秒
long second = file.length() / 32000 ;
long milliSecond = Math.round((file.length() % 32000) / 32000.0 * 1000 ) ;
return second * 1000 + milliSecond;
}
}
...@@ -281,22 +281,5 @@ public class FileUtils extends org.apache.commons.io.FileUtils ...@@ -281,22 +281,5 @@ public class FileUtils extends org.apache.commons.io.FileUtils
} }
/**
* 获取视频或者语音时长
* @param multiFile
* @return
* @throws IOException
*/
public static long getVideoOrVoice(MultipartFile multiFile) throws IOException {
long duration_new =0;
// 将MultipartFile file转换成为File
File f_file = MultipartFileToFile(multiFile);
String path = f_file.getCanonicalPath();
duration_new = VideoUtil.getDuration(path);
f_file.delete();
return duration_new;
}
} }
package com.linkwechat.common.utils.file;
import com.coremedia.iso.IsoFile;
import java.io.IOException;
class VideoUtil{
/**
* 获取视频文件的播放长度(mp4、mov格式)
* @param videoPath
* @return 单位为毫秒
*/
public static long getMp4Duration(String videoPath) throws IOException {
IsoFile isoFile = new IsoFile(videoPath);
long lengthInSeconds =
isoFile.getMovieBox().getMovieHeaderBox().getDuration() /
isoFile.getMovieBox().getMovieHeaderBox().getTimescale();
return lengthInSeconds;
}
/**
* 得到语音或视频文件时长,单位秒
* @param filePath
* @return
* @throws IOException
*/
public static long getDuration(String filePath) throws IOException {
String format = getVideoFormat(filePath);
long result = 0;
if("wav".equals(format)){
result = AudioUtil.getDuration(filePath).intValue();
}else if("mp3".equals(format)){
result = AudioUtil.getMp3Duration(filePath).intValue();
}else if("m4a".equals(format)) {
result = VideoUtil.getMp4Duration(filePath);
}else if("mov".equals(format)){
result = VideoUtil.getMp4Duration(filePath);
}else if("mp4".equals(format)){
result = VideoUtil.getMp4Duration(filePath);
}
return result;
}
/**
* 得到语音或视频文件时长,单位秒
* @param filePath
* @return
* @throws IOException
*/
public static long getDuration(String filePath,String format) throws IOException {
long result = 0;
if("wav".equals(format)){
result = AudioUtil.getDuration(filePath).intValue();
}else if("mp3".equals(format)){
result = AudioUtil.getMp3Duration(filePath).intValue();
}else if("m4a".equals(format)) {
result = VideoUtil.getMp4Duration(filePath);
}else if("mov".equals(format)){
result = VideoUtil.getMp4Duration(filePath);
}else if("mp4".equals(format)){
result = VideoUtil.getMp4Duration(filePath);
}
return result;
}
/**
* 得到文件格式
* @param path
* @return
*/
public static String getVideoFormat(String path){
return path.toLowerCase().substring(path.toLowerCase().lastIndexOf(".") + 1);
}
}
...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.client; ...@@ -2,6 +2,7 @@ package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.*; import com.dtflys.forest.annotation.*;
import com.linkwechat.wecom.domain.dto.*; import com.linkwechat.wecom.domain.dto.*;
import com.linkwechat.wecom.domain.dto.customer.AllocateGroupDto;
import com.linkwechat.wecom.domain.dto.customer.JobExtendsCustomer; import com.linkwechat.wecom.domain.dto.customer.JobExtendsCustomer;
import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor; import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
import com.linkwechat.wecom.interceptor.WeAppAccessTokenInterceptor; import com.linkwechat.wecom.interceptor.WeAppAccessTokenInterceptor;
...@@ -106,7 +107,7 @@ public interface WeUserClient { ...@@ -106,7 +107,7 @@ public interface WeUserClient {
* @return * @return
*/ */
@Request(url="/externalcontact/groupchat/transfer", type = "POST") @Request(url="/externalcontact/groupchat/transfer", type = "POST")
WeResultDto allocateGroup(@JSONBody AllocateWeGroupDto allocateWeGroupDto); AllocateGroupDto allocateGroup(@JSONBody AllocateWeGroupDto allocateWeGroupDto);
/** /**
......
...@@ -41,5 +41,11 @@ public class WeAllocateGroup ...@@ -41,5 +41,11 @@ public class WeAllocateGroup
@JsonFormat(pattern = "yyyy-MM-dd") @JsonFormat(pattern = "yyyy-MM-dd")
private Date allocateTime; private Date allocateTime;
//0:被接替成功 1:待接替 2:接替失败 3:正常状态
private Integer status;
private String errMsg;
} }
...@@ -129,6 +129,9 @@ public class WeGroup extends BaseEntity{ ...@@ -129,6 +129,9 @@ public class WeGroup extends BaseEntity{
@TableField(exist = false) @TableField(exist = false)
private Integer toDayMemberNum; private Integer toDayMemberNum;
@TableLogic @TableLogic
private Integer delFlag=new Integer(0); private Integer delFlag=new Integer(0);
} }
package com.linkwechat.wecom.domain.dto.customer;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import lombok.Data;
import java.util.List;
@Data
public class AllocateGroupDto extends WeResultDto {
private List<FailedChatList> failed_chat_list;
@Data
public static class FailedChatList{
private String chat_id;
private Integer errcode;
private String errmsg;
}
}
...@@ -235,43 +235,45 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto ...@@ -235,43 +235,45 @@ public class WeCustomerServiceImpl extends ServiceImpl<WeCustomerMapper, WeCusto
.eq(WeCustomer::getFirstUserId, weLeaveUserInfoAllocateVo.getHandoverUserid())); .eq(WeCustomer::getFirstUserId, weLeaveUserInfoAllocateVo.getHandoverUserid()));
if (CollectionUtil.isNotEmpty(allocateWeCustomers)) { if (CollectionUtil.isNotEmpty(allocateWeCustomers)) {
//设置客户的接手人
allocateWeCustomers.stream().forEach(k->{
k.setTakeoverUserId(weLeaveUserInfoAllocateVo.getTakeoverUserid());
});
JobExtendsCustomer jobExtendsCustomer = weUserClient.transferCustomer(
AllocateWeCustomerDto.builder()
.external_userid(
(String[]) allocateWeCustomers.stream().map(WeCustomer::getExternalUserid).toArray()
)
.handover_userid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeover_userid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
if(this.remove(new LambdaQueryWrapper<WeCustomer>() if(jobExtendsCustomer.getErrcode().equals(WeConstans.WE_SUCCESS_CODE)){
.eq(WeCustomer::getFirstUserId,weLeaveUserInfoAllocateVo.getHandoverUserid()))){//删除表中相应客户 this.baseMapper.batchAddOrUpdate(allocateWeCustomers);
//记录接受离职表 List<WeAllocateCustomer> weAllocateCustomers=new ArrayList<>();
List<WeAllocateCustomer> weAllocateCustomers = new ArrayList<>(); allocateWeCustomers.stream().forEach(k->{
allocateWeCustomers.stream().forEach(k -> {
weAllocateCustomers.add( weAllocateCustomers.add(
WeAllocateCustomer.builder() WeAllocateCustomer.builder()
.allocateTime(new Date()) .allocateTime(new Date())
.extentType(new Integer(1))
.externalUserid(k.getExternalUserid()) .externalUserid(k.getExternalUserid())
.handoverUserid(weLeaveUserInfoAllocateVo.getHandoverUserid()) .handoverUserid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeoverUserid(weLeaveUserInfoAllocateVo.getTakeoverUserid()) .takeoverUserid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.extentType(weLeaveUserInfoAllocateVo.getExtentType()) .failReason("离职继承")
.build() .build()
);
});
if (CollectionUtil.isNotEmpty(weAllocateCustomers)
&& iWeAllocateCustomerService.saveBatch(weAllocateCustomers)) {
//同步企业微信 );
weUserClient.allocateCustomer(AllocateWeCustomerDto.builder()
.external_userid(
ArrayUtil.toArray(allocateWeCustomers.stream().map(WeCustomer::getExternalUserid).collect(Collectors.toList()), String.class)
)
.handover_userid(weLeaveUserInfoAllocateVo.getHandoverUserid())
.takeover_userid(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build());
iWeAllocateCustomerService.saveBatch(weAllocateCustomers);
} });
} }
} }
......
...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.enums.AllocateGroupStatus;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.Threads; import com.linkwechat.common.utils.Threads;
import com.linkwechat.wecom.annotation.SynchRecord; import com.linkwechat.wecom.annotation.SynchRecord;
...@@ -18,6 +19,7 @@ import com.linkwechat.wecom.domain.WeCustomerAddGroup; ...@@ -18,6 +19,7 @@ import com.linkwechat.wecom.domain.WeCustomerAddGroup;
import com.linkwechat.wecom.domain.WeGroup; import com.linkwechat.wecom.domain.WeGroup;
import com.linkwechat.wecom.domain.WeGroupMember; import com.linkwechat.wecom.domain.WeGroupMember;
import com.linkwechat.wecom.domain.dto.AllocateWeGroupDto; import com.linkwechat.wecom.domain.dto.AllocateWeGroupDto;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import com.linkwechat.wecom.domain.dto.customer.*; import com.linkwechat.wecom.domain.dto.customer.*;
import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo; import com.linkwechat.wecom.domain.vo.WeLeaveUserInfoAllocateVo;
import com.linkwechat.wecom.mapper.WeGroupMapper; import com.linkwechat.wecom.mapper.WeGroupMapper;
...@@ -80,10 +82,20 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl ...@@ -80,10 +82,20 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
@Override @Override
@Transactional @Transactional
public void allocateWeGroup(WeLeaveUserInfoAllocateVo weLeaveUserInfoAllocateVo) { public void allocateWeGroup(WeLeaveUserInfoAllocateVo weLeaveUserInfoAllocateVo) {
List<WeGroup> weGroups List<WeGroup> weGroups
= this.list(new LambdaQueryWrapper<WeGroup>().eq(WeGroup::getOwner, weLeaveUserInfoAllocateVo.getHandoverUserid())); = this.list(new LambdaQueryWrapper<WeGroup>().eq(WeGroup::getOwner, weLeaveUserInfoAllocateVo.getHandoverUserid()));
if (CollectionUtil.isNotEmpty(weGroups)) {
if(CollectionUtil.isNotEmpty(weGroups)){
//同步企业微信端
AllocateGroupDto allocateGroup = weUserClient.allocateGroup(
AllocateWeGroupDto.builder()
.chat_id_list(ArrayUtil.toArray(weGroups.stream().map(WeGroup::getChatId).collect(Collectors.toList()), String.class))
.new_owner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
//构建分配记录
List<WeAllocateGroup> weAllocateGroups = new ArrayList<>(); List<WeAllocateGroup> weAllocateGroups = new ArrayList<>();
//更改本地群主 //更改本地群主
weGroups.stream().forEach(k -> { weGroups.stream().forEach(k -> {
...@@ -91,27 +103,39 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl ...@@ -91,27 +103,39 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
weAllocateGroups.add(WeAllocateGroup.builder() weAllocateGroups.add(WeAllocateGroup.builder()
.allocateTime(new Date()) .allocateTime(new Date())
.chatId(k.getChatId()) .chatId(k.getChatId())
.status(AllocateGroupStatus.ALLOCATE_GROUP_STATUS_BJTCG.getKey())
.newOwner(weLeaveUserInfoAllocateVo.getTakeoverUserid()) .newOwner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.oldOwner(weLeaveUserInfoAllocateVo.getHandoverUserid()) .oldOwner(weLeaveUserInfoAllocateVo.getHandoverUserid())
.build()); .build());
}); });
this.saveOrUpdateBatch(weGroups);
//分配记录保存
if (CollectionUtil.isNotEmpty(weAllocateGroups)) {
if (iWeAllocateGroupService.saveOrUpdateBatch(weAllocateGroups)) {
// //同步企业微信端
weUserClient.allocateGroup(
AllocateWeGroupDto.builder()
.chat_id_list(ArrayUtil.toArray(weAllocateGroups.stream().map(WeAllocateGroup::getChatId).collect(Collectors.toList()), String.class))
.new_owner(weLeaveUserInfoAllocateVo.getTakeoverUserid())
.build()
);
//处理接替失败的群
List<AllocateGroupDto.FailedChatList> failedChatList = allocateGroup.getFailed_chat_list();
if(CollectionUtil.isNotEmpty(failedChatList)){
failedChatList.stream().forEach(k->{
weGroups.stream()
.filter(kk->kk.getChatId().equals(k.getChat_id())).findFirst().get()
.setOwner(weLeaveUserInfoAllocateVo.getHandoverUserid());
WeAllocateGroup weAllocateGroup
= weAllocateGroups.stream().filter(kk -> kk.getChatId().equals(k.getChat_id())).findFirst().get();
if(null != weAllocateGroup){
weAllocateGroup.setStatus(AllocateGroupStatus.ALLOCATE_GROUP_STATUS_JTSB.getKey());
weAllocateGroup.setErrMsg(weAllocateGroup.getErrMsg());
} }
});
} }
if(this.saveOrUpdateBatch(weGroups)){
iWeAllocateGroupService
.saveOrUpdateBatch(weAllocateGroups);
}
} }
} }
...@@ -299,8 +323,8 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl ...@@ -299,8 +323,8 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<List<WeGroup>> lists = Lists.partition(weGroups, 500); List<List<WeGroup>> lists = Lists.partition(weGroups, 500);
for (List<WeGroup> groupList : lists) { for (List<WeGroup> groupList : lists) {
this.baseMapper.insertBatch(groupList); this.baseMapper.insertBatch(groupList);
this.remove(new LambdaQueryWrapper<WeGroup>() // this.remove(new LambdaQueryWrapper<WeGroup>()
.notIn(WeGroup::getChatId, groupList.stream().map(WeGroup::getChatId).collect(Collectors.toList()))); // .notIn(WeGroup::getChatId, groupList.stream().map(WeGroup::getChatId).collect(Collectors.toList())));
} }
}else{ }else{
List<WeGroup> oldWeGroups = this.list(); List<WeGroup> oldWeGroups = this.list();
...@@ -324,13 +348,15 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl ...@@ -324,13 +348,15 @@ public class WeGroupServiceImpl extends ServiceImpl<WeGroupMapper, WeGroup> impl
List<List<WeGroupMember>> lists = Lists.partition(weGroupMembers, 500); List<List<WeGroupMember>> lists = Lists.partition(weGroupMembers, 500);
for (List<WeGroupMember> groupMemberList : lists) { for (List<WeGroupMember> groupMemberList : lists) {
iWeGroupMemberService.remove(
new LambdaQueryWrapper<WeGroupMember>()
.notIn(WeGroupMember::getUserId,groupMemberList.stream().map(WeGroupMember::getUserId).collect(Collectors.toList()))
);
iWeGroupMemberService.insertBatch(groupMemberList); iWeGroupMemberService.insertBatch(groupMemberList);
// iWeGroupMemberService.remove(
// new LambdaQueryWrapper<WeGroupMember>()
// .notIn(WeGroupMember::getUserId,groupMemberList.stream().map(WeGroupMember::getUserId).collect(Collectors.toList()))
//
// );
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!