Commit d0a9f2d1 by sunxiwang

员工活码功能完善

1 parent 1fc4e62c
...@@ -96,4 +96,16 @@ public class CommonController { ...@@ -96,4 +96,16 @@ public class CommonController {
FileUtils.writeBytes(downloadPath, response.getOutputStream()); FileUtils.writeBytes(downloadPath, response.getOutputStream());
} }
/**
* 网络资源通用下载
*/
@GetMapping("/common/download/url")
public void webResourceDownload(String url, String name, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, name));
FileUtils.downloadFile(url, response.getOutputStream());
}
} }
package com.linkwechat.web.controller.wecom; package com.linkwechat.web.controller.wecom;
import cn.hutool.core.collection.CollectionUtil;
import com.linkwechat.common.annotation.Log; import com.linkwechat.common.annotation.Log;
import com.linkwechat.common.core.controller.BaseController; import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult; import com.linkwechat.common.core.domain.AjaxResult;
...@@ -7,17 +8,26 @@ import com.linkwechat.common.core.page.TableDataInfo; ...@@ -7,17 +8,26 @@ import com.linkwechat.common.core.page.TableDataInfo;
import com.linkwechat.common.enums.BusinessType; import com.linkwechat.common.enums.BusinessType;
import com.linkwechat.common.exception.wecom.WeComException; import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.common.utils.file.FileUtils;
import com.linkwechat.wecom.domain.WeEmpleCode; import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.WeEmpleCodeUseScop; import com.linkwechat.wecom.domain.WeEmpleCodeUseScop;
import com.linkwechat.wecom.service.IWeEmpleCodeService; import com.linkwechat.wecom.service.IWeEmpleCodeService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 员工活码Controller * 员工活码Controller
...@@ -76,12 +86,12 @@ public class WeEmpleCodeController extends BaseController { ...@@ -76,12 +86,12 @@ public class WeEmpleCodeController extends BaseController {
/** /**
* 批量新增员工活码 * 批量新增员工活码
*/ */
@PreAuthorize("@ss.hasPermi('wecom:code:add')") @PreAuthorize("@ss.hasPermi('wecom:code:batchAdd')")
@Log(title = "批量新增员工活码", businessType = BusinessType.INSERT) @Log(title = "批量新增员工活码", businessType = BusinessType.INSERT)
@PostMapping("/batchAdd") @PostMapping("/batchAdd")
public AjaxResult batchAdd(@RequestBody List<WeEmpleCodeUseScop> weEmpleCodeUseScops) { public AjaxResult batchAdd(@RequestBody WeEmpleCode weEmpleCode) {
try { try {
weEmpleCodeService.insertWeEmpleCodeBatch(weEmpleCodeUseScops); weEmpleCodeService.insertWeEmpleCodeBatch(weEmpleCode);
return AjaxResult.success(); return AjaxResult.success();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -115,4 +125,71 @@ public class WeEmpleCodeController extends BaseController { ...@@ -115,4 +125,71 @@ public class WeEmpleCodeController extends BaseController {
List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList()); List<String> idList = Arrays.stream(StringUtils.split(ids, ",")).collect(Collectors.toList());
return toAjax(weEmpleCodeService.batchRemoveWeEmpleCodeIds(idList)); return toAjax(weEmpleCodeService.batchRemoveWeEmpleCodeIds(idList));
} }
/**
* 获取员工二维码
* @param userIds 员工id
* @param departmentIds 部门id
*/
@PreAuthorize("@ss.hasPermi('wecom:code:qrcode')")
@Log(title = "获取员工二维码", businessType = BusinessType.DELETE)
@GetMapping("/getQrcode")
public AjaxResult getQrcode(String userIds, String departmentIds) {
return AjaxResult.success(weEmpleCodeService.getQrcode(userIds,departmentIds));
}
/**
* 员工活码批量下载
*
* @param ids 员工活码ids
* @param request 请求
* @param response 输出
* @throws Exception
*/
@PreAuthorize("@ss.hasPermi('wecom:code:downloadBatch')")
@Log(title = "员工活码批量下载", businessType = BusinessType.OTHER)
@GetMapping("/downloadBatch")
public void downloadBatch(String ids, HttpServletRequest request, HttpServletResponse response){
List<String> idList = Arrays.stream(Optional.ofNullable(ids).orElse("").split(","))
.filter(StringUtils::isNotEmpty).collect(Collectors.toList());
try {
//通过员工活码id查询活码数据
List<WeEmpleCode> weEmpleCodeLsit = weEmpleCodeService.selectWeEmpleCodeByIds(idList);
//下载文件名称
String downloadFilename = "批量员工活码.zip";
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition",
"attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadFilename));
//zip输出流
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
if (CollectionUtil.isNotEmpty(weEmpleCodeLsit)){
for (WeEmpleCode weEmpleCode : weEmpleCodeLsit){
String qrCode = weEmpleCode.getQrCode();
if (StringUtils.isEmpty(qrCode)){
continue;
}
URL url = new URL(qrCode);
//每个二维码名称
String fileName = weEmpleCode.getUseUserName()+"-"+weEmpleCode.getActivityScene()+".jpg";
zos.putNextEntry(new ZipEntry(fileName));
InputStream fis = url.openConnection().getInputStream();
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
fis.close();
}
}
//关闭zip输出流
zos.flush();
zos.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
} }
package com.linkwechat.common.utils.file; package com.linkwechat.common.utils.file;
import java.io.File; import java.io.*;
import java.io.FileInputStream; import java.net.HttpURLConnection;
import java.io.FileNotFoundException; import java.net.URL;
import java.io.IOException; import java.net.URLConnection;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
...@@ -75,6 +75,70 @@ public class FileUtils extends org.apache.commons.io.FileUtils ...@@ -75,6 +75,70 @@ public class FileUtils extends org.apache.commons.io.FileUtils
} }
/** /**
*
* @param urlPath 下载路径
* @param os 输出流
* @return 返回下载文件
* @throws Exception
*/
public static void downloadFile(String urlPath,OutputStream os){
InputStream inputStream = null;
try {
URL url = new URL(urlPath);
// 连接类的父类,抽象类
URLConnection urlConnection = url.openConnection();
// http的连接类
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
// 设定请求的方法,默认是GET(对于知识库的附件服务器必须是GET,如果是POST会返回405。流程附件迁移功能里面必须是POST,有所区分。)
httpURLConnection.setRequestMethod("GET");
// 设置字符编码
httpURLConnection.setRequestProperty("Charset", "UTF-8");
// 打开到此 URL 引用的资源的通信链接(如果尚未建立这样的连接)。
httpURLConnection.getResponseCode();
inputStream = httpURLConnection.getInputStream();
byte[] b = new byte[1024];
int length;
while ((length = inputStream.read(b)) > 0)
{
os.write(b, 0, length);
}
inputStream.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}finally
{
if (os != null)
{
try
{
os.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
if (inputStream != null)
{
try
{
inputStream.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
}
}
/**
* 删除文件 * 删除文件
* *
* @param filePath 文件 * @param filePath 文件
......
...@@ -108,6 +108,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -108,6 +108,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers("/profile/**").anonymous() .antMatchers("/profile/**").anonymous()
.antMatchers("/common/download**").anonymous() .antMatchers("/common/download**").anonymous()
.antMatchers("/common/download/resource**").anonymous() .antMatchers("/common/download/resource**").anonymous()
.antMatchers("/common/download/url**").anonymous()
.antMatchers("/swagger-ui.html").anonymous() .antMatchers("/swagger-ui.html").anonymous()
.antMatchers("/swagger-resources/**").anonymous() .antMatchers("/swagger-resources/**").anonymous()
.antMatchers("/webjars/**").anonymous() .antMatchers("/webjars/**").anonymous()
......
...@@ -37,7 +37,6 @@ public class WeEmpleCode extends BaseEntity ...@@ -37,7 +37,6 @@ public class WeEmpleCode extends BaseEntity
private String welcomeMsg; private String welcomeMsg;
/** 素材的id */ /** 素材的id */
@TableField(exist = false)
private Long mediaId; private Long mediaId;
/** 0:正常;1:删除; */ /** 0:正常;1:删除; */
......
...@@ -11,16 +11,15 @@ import lombok.Data; ...@@ -11,16 +11,15 @@ import lombok.Data;
@Data @Data
public class WeExternalContactDto extends WeResultDto { public class WeExternalContactDto extends WeResultDto {
//新增联系方式的配置id //系我二维码链接,仅在scene为2时返回
private String qr_code; private String qr_code;
//系我二维码链接,仅在scene为2时返回 //新增联系方式的配置id
private String config_id; private String config_id;
@Data @Data
public static class WeContactWay{ public static class WeContactWay {
//系我二维码链接,仅在scene为2时返回 //系我二维码链接,仅在scene为2时返回
private String config_id; private String config_id;
// 联系方式类型,1-单人, 2-多人 // 联系方式类型,1-单人, 2-多人
......
...@@ -97,13 +97,13 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory ...@@ -97,13 +97,13 @@ public class WeEventChangeExternalContactImpl implements WeCallBackEventFactory
} }
private void addExternalContact(WxCpXmlMessageVO message) { private void addExternalContact(WxCpXmlMessageVO message) {
if (message.getExternalUserId() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId());
}
try { try {
Threads.SINGLE_THREAD_POOL.submit(new Runnable() { Threads.SINGLE_THREAD_POOL.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
if (message.getExternalUserId() != null) {
weCustomerService.getCustomersInfoAndSynchWeCustomer(message.getExternalUserId());
}
//向扫码客户发送欢迎语 //向扫码客户发送欢迎语
if (message.getState() != null && message.getWelcomeCode() != null) { if (message.getState() != null && message.getWelcomeCode() != null) {
log.info("执行发送欢迎语>>>>>>>>>>>>>>>"); log.info("执行发送欢迎语>>>>>>>>>>>>>>>");
......
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.linkwechat.wecom.domain.WeEmpleCode; import com.linkwechat.wecom.domain.WeEmpleCode;
import com.linkwechat.wecom.domain.WeEmpleCodeUseScop; import com.linkwechat.wecom.domain.WeEmpleCodeUseScop;
import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto; import com.linkwechat.wecom.domain.dto.WeEmpleCodeDto;
import com.linkwechat.wecom.domain.dto.WeExternalContactDto;
import java.util.List; import java.util.List;
...@@ -24,6 +25,13 @@ public interface IWeEmpleCodeService extends IService<WeEmpleCode> ...@@ -24,6 +25,13 @@ public interface IWeEmpleCodeService extends IService<WeEmpleCode>
public WeEmpleCode selectWeEmpleCodeById(Long id); public WeEmpleCode selectWeEmpleCodeById(Long id);
/** /**
* 批量查询员工活码
* @param ids 员工活码ID
* @return
*/
public List<WeEmpleCode> selectWeEmpleCodeByIds(List<String> ids);
/**
* 查询员工活码列表 * 查询员工活码列表
* *
* @param weEmpleCode 员工活码 * @param weEmpleCode 员工活码
...@@ -84,8 +92,21 @@ public interface IWeEmpleCodeService extends IService<WeEmpleCode> ...@@ -84,8 +92,21 @@ public interface IWeEmpleCodeService extends IService<WeEmpleCode>
/** /**
* 批量新增员工活码 * 批量新增员工活码
* *
* @param weEmpleCodeUseScops 员工信息 * @param weEmpleCode 员工活码
* @return 结果 * @return 结果
*/ */
public void insertWeEmpleCodeBatch(List<WeEmpleCodeUseScop> weEmpleCodeUseScops); public void insertWeEmpleCodeBatch(WeEmpleCode weEmpleCode);
/**
* 获取员工二维码
* @param userIds 员工id
* @param departmentIds 部门id
*/
public WeExternalContactDto getQrcode(String userIds, String departmentIds);
/**
* 获取员工二维码
* @param userIdArr 员工id
* @param departmentIdArr 部门id
*/
public WeExternalContactDto getQrcode(String[] userIdArr, Long[] departmentIdArr);
} }
...@@ -3,8 +3,8 @@ package com.linkwechat.wecom.service.impl; ...@@ -3,8 +3,8 @@ package com.linkwechat.wecom.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.linkwechat.common.constant.WeConstans; import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.common.utils.SecurityUtils; import com.linkwechat.common.utils.SecurityUtils;
import com.linkwechat.common.utils.SnowFlakeUtil;
import com.linkwechat.common.utils.StringUtils; import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.client.WeExternalContactClient; import com.linkwechat.wecom.client.WeExternalContactClient;
import com.linkwechat.wecom.domain.WeEmpleCode; import com.linkwechat.wecom.domain.WeEmpleCode;
...@@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -21,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -69,6 +66,25 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp ...@@ -69,6 +66,25 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
return weEmpleCode; return weEmpleCode;
} }
@Override
public List<WeEmpleCode> selectWeEmpleCodeByIds(List<String> ids) {
List<WeEmpleCode> weEmpleCodeList = this.baseMapper.selectWeEmpleCodeByIds(ids);
if (weEmpleCodeList != null) {
weEmpleCodeList.forEach(empleCode -> {
List<WeEmpleCodeUseScop> weEmpleCodeUseScopList = empleCode.getWeEmpleCodeUseScops();
if (CollectionUtil.isNotEmpty(weEmpleCodeUseScopList)) {
String useUserName = weEmpleCodeUseScopList.stream().map(WeEmpleCodeUseScop::getBusinessName)
.filter(StringUtils::isNotEmpty).collect(Collectors.joining(","));
empleCode.setUseUserName(useUserName);
String mobile = weEmpleCodeUseScopList.stream().map(WeEmpleCodeUseScop::getMobile)
.filter(StringUtils::isNotEmpty).collect(Collectors.joining(","));
empleCode.setMobile(mobile);
}
});
}
return weEmpleCodeList;
}
/** /**
* 查询员工活码列表 * 查询员工活码列表
* *
...@@ -102,7 +118,7 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp ...@@ -102,7 +118,7 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insertWeEmpleCode(WeEmpleCode weEmpleCode){ public void insertWeEmpleCode(WeEmpleCode weEmpleCode) {
weEmpleCode.setCreateTime(new Date()); weEmpleCode.setCreateTime(new Date());
weEmpleCode.setCreateBy(SecurityUtils.getUsername()); weEmpleCode.setCreateBy(SecurityUtils.getUsername());
addWeEmplCode(weEmpleCode); addWeEmplCode(weEmpleCode);
...@@ -182,52 +198,83 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp ...@@ -182,52 +198,83 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
return this.baseMapper.selectWelcomeMsgByActivityScene(activityScene, userId); return this.baseMapper.selectWelcomeMsgByActivityScene(activityScene, userId);
} }
/**
* 批量新增员工活码
*
* @param weEmpleCode 员工信息
* @return 结果
*/
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insertWeEmpleCodeBatch(List<WeEmpleCodeUseScop> weEmpleCodeUseScops){ public void insertWeEmpleCodeBatch(WeEmpleCode weEmpleCode) {
Optional.ofNullable(weEmpleCodeUseScops).orElseGet(ArrayList::new).forEach(useScops -> { weEmpleCode.setCreateTime(new Date());
weEmpleCode.setCreateBy(SecurityUtils.getUsername());
weEmpleCode.setCodeType(WeConstans.SINGLE_EMPLE_CODE_TYPE);
weEmpleCode.setIsJoinConfirmFriends(Optional.ofNullable(weEmpleCode.getIsJoinConfirmFriends())
.orElse(WeConstans.IS_JOIN_CONFIR_MFRIENDS));
weEmpleCode.setActivityScene(Optional.ofNullable(weEmpleCode.getActivityScene())
.orElse(WeConstans.ONE_PERSON_CODE_GENERATED_BATCH));
Optional.ofNullable(weEmpleCode).map(WeEmpleCode::getWeEmpleCodeUseScops)
.orElseGet(ArrayList::new).forEach(useScops -> {
//机构类型数据返回不执行生成二维码业务 //机构类型数据返回不执行生成二维码业务
if (WeConstans.USE_SCOP_BUSINESSID_TYPE_ORG.equals(useScops.getBusinessIdType())) { if (WeConstans.USE_SCOP_BUSINESSID_TYPE_ORG.equals(useScops.getBusinessIdType())) {
return; return;
} }
weEmpleCode.setId(SnowFlakeUtil.nextId());
List<WeEmpleCodeUseScop> weEmpleCodeUseScopList = new ArrayList<>(); List<WeEmpleCodeUseScop> weEmpleCodeUseScopList = new ArrayList<>();
weEmpleCodeUseScopList.add(useScops); weEmpleCodeUseScopList.add(useScops);
WeEmpleCode weEmpleCode = new WeEmpleCode();
weEmpleCode.setCreateTime(new Date());
weEmpleCode.setCreateBy(SecurityUtils.getUsername());
weEmpleCode.setCodeType(WeConstans.SINGLE_EMPLE_CODE_TYPE);
weEmpleCode.setIsJoinConfirmFriends(WeConstans.IS_JOIN_CONFIR_MFRIENDS);
weEmpleCode.setActivityScene(WeConstans.ONE_PERSON_CODE_GENERATED_BATCH);
weEmpleCode.setWeEmpleCodeUseScops(weEmpleCodeUseScopList); weEmpleCode.setWeEmpleCodeUseScops(weEmpleCodeUseScopList);
addWeEmplCode(weEmpleCode); addWeEmplCode(weEmpleCode);
}); });
} }
@Override
public WeExternalContactDto getQrcode(String userIds, String departmentIds) {
String[] userIdArr = Arrays.stream(userIds.split(","))
.filter(StringUtils::isNotEmpty).toArray(String[]::new);
Long[] departmentIdArr = Arrays.stream(departmentIds.split(","))
.filter(StringUtils::isNotEmpty)
.map(Long::new).toArray(Long[]::new);
return getQrcode(userIdArr,departmentIdArr);
}
@Override
public WeExternalContactDto getQrcode(String[] userIdArr, Long[] departmentIdArr) {
WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay();
//当存在部门id或者用户id大于一个的情况为多人二维码
if (departmentIdArr.length > 0 || userIdArr.length > 1) {
weContactWay.setType(WeConstans.MANY_EMPLE_CODE_TYPE);
} else {
weContactWay.setType(WeConstans.SINGLE_EMPLE_CODE_TYPE);
}
weContactWay.setScene(WeConstans.QR_CODE_EMPLE_CODE_SCENE);
weContactWay.setUser(userIdArr);
weContactWay.setParty(departmentIdArr);
return getQrCode(weContactWay);
}
/** /**
* 新增员工活码 * 新增员工活码
* *
* @param weEmpleCode * @param weEmpleCode
*/ */
private void addWeEmplCode(WeEmpleCode weEmpleCode){ private void addWeEmplCode(WeEmpleCode weEmpleCode) {
List<WeEmpleCodeUseScop> weEmpleCodeUseScops = weEmpleCode.getWeEmpleCodeUseScops(); /*List<WeEmpleCodeUseScop> weEmpleCodeUseScops = weEmpleCode.getWeEmpleCodeUseScops();
List<String> businessIdList = Optional.ofNullable(weEmpleCodeUseScops).orElseGet(ArrayList::new) List<String> businessIdList = Optional.ofNullable(weEmpleCodeUseScops).orElseGet(ArrayList::new)
.stream().map(WeEmpleCodeUseScop::getBusinessId) .stream().map(WeEmpleCodeUseScop::getBusinessId)
.collect(Collectors.toList()); .collect(Collectors.toList());
List<WeEmpleCodeUseScop> weEmpleCodeUseScopList = iWeEmpleCodeUseScopService.listByIds(businessIdList); List<WeEmpleCodeUseScop> weEmpleCodeUseScopList = iWeEmpleCodeUseScopService.listByIds(businessIdList);
if (weEmpleCodeUseScopList != null) { if (CollectionUtil.isNotEmpty(weEmpleCodeUseScopList)) {
throw new WeComException("该员工或部门已经创建,无法重复创建"); throw new WeComException("该员工或部门已经创建,无法重复创建");
} }*/
WeExternalContactDto.WeContactWay weContactWay = getWeContactWay(weEmpleCode); WeExternalContactDto.WeContactWay weContactWay = getWeContactWay(weEmpleCode);
try { WeExternalContactDto qrCode = getQrCode(weContactWay);
WeExternalContactDto weExternalContactDto = weExternalContactClient.addContactWay(weContactWay); if (qrCode != null) {
//新增联系方式的配置id weEmpleCode.setConfigId(qrCode.getConfig_id());
String configId = weExternalContactDto.getConfig_id(); weEmpleCode.setQrCode(qrCode.getQr_code());
//联系我二维码链接
String qrCode = weExternalContactDto.getQr_code();
weEmpleCode.setConfigId(configId);
weEmpleCode.setQrCode(qrCode);
} catch (Exception e) {
e.printStackTrace();
} }
if (this.baseMapper.insertWeEmpleCode(weEmpleCode) == 1) { if (this.baseMapper.insertWeEmpleCode(weEmpleCode) == 1) {
if (CollectionUtil.isNotEmpty(weEmpleCode.getWeEmpleCodeUseScops())) { if (CollectionUtil.isNotEmpty(weEmpleCode.getWeEmpleCodeUseScops())) {
...@@ -241,21 +288,47 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp ...@@ -241,21 +288,47 @@ public class WeEmpleCodeServiceImpl extends ServiceImpl<WeEmpleCodeMapper, WeEmp
} }
} }
/**
* 获取二维码
*
* @param weContactWay
* @return
*/
private WeExternalContactDto getQrCode(WeExternalContactDto.WeContactWay weContactWay) {
try {
return weExternalContactClient.addContactWay(weContactWay);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 企微接口参数生成方法
* @param weEmpleCode 员工活码实体类
* @return 企微接口参数实体类
*/
private WeExternalContactDto.WeContactWay getWeContactWay(WeEmpleCode weEmpleCode) { private WeExternalContactDto.WeContactWay getWeContactWay(WeEmpleCode weEmpleCode) {
WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay(); WeExternalContactDto.WeContactWay weContactWay = new WeExternalContactDto.WeContactWay();
List<WeEmpleCodeUseScop> weEmpleCodeUseScops = weEmpleCode.getWeEmpleCodeUseScops(); List<WeEmpleCodeUseScop> weEmpleCodeUseScops = weEmpleCode.getWeEmpleCodeUseScops();
//根据类型生成相应的活码农 //根据类型生成相应的活码
weContactWay.setConfig_id(weEmpleCode.getConfigId()); weContactWay.setConfig_id(weEmpleCode.getConfigId());
weContactWay.setType(weEmpleCode.getCodeType()); weContactWay.setType(weEmpleCode.getCodeType());
weContactWay.setScene(2); weContactWay.setScene(WeConstans.QR_CODE_EMPLE_CODE_SCENE);
weContactWay.setSkip_verify(weEmpleCode.getIsJoinConfirmFriends()); weContactWay.setSkip_verify(weEmpleCode.getIsJoinConfirmFriends());
weContactWay.setState(weEmpleCode.getActivityScene()); weContactWay.setState(weEmpleCode.getActivityScene());
if (CollectionUtil.isNotEmpty(weEmpleCodeUseScops)) { if (CollectionUtil.isNotEmpty(weEmpleCodeUseScops)) {
String[] userIdArr = weEmpleCodeUseScops.stream().filter(itme -> 2 == itme.getBusinessIdType() && itme.getBusinessId() != null) //员工列表
String[] userIdArr = weEmpleCodeUseScops.stream().filter(itme ->
WeConstans.USE_SCOP_BUSINESSID_TYPE_USER.equals(itme.getBusinessIdType())
&& StringUtils.isNotEmpty(itme.getBusinessId()))
.map(WeEmpleCodeUseScop::getBusinessId).toArray(String[]::new); .map(WeEmpleCodeUseScop::getBusinessId).toArray(String[]::new);
weContactWay.setUser(userIdArr); weContactWay.setUser(userIdArr);
//部门列表
if (!WeConstans.SINGLE_EMPLE_CODE_TYPE.equals(weEmpleCode.getCodeType())) { if (!WeConstans.SINGLE_EMPLE_CODE_TYPE.equals(weEmpleCode.getCodeType())) {
Long[] partyArr = weEmpleCodeUseScops.stream().filter(itme -> 1 == itme.getBusinessIdType() && itme.getBusinessId() != null) Long[] partyArr = weEmpleCodeUseScops.stream().filter(itme ->
WeConstans.USE_SCOP_BUSINESSID_TYPE_ORG.equals(itme.getBusinessIdType())
&& StringUtils.isNotEmpty(itme.getBusinessId()))
.map(item -> Long.valueOf(item.getBusinessId())).collect(Collectors.toList()).toArray(new Long[]{}); .map(item -> Long.valueOf(item.getBusinessId())).collect(Collectors.toList()).toArray(new Long[]{});
weContactWay.setParty(partyArr); weContactWay.setParty(partyArr);
} }
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.linkwechat.wecom.mapper.WeEmpleCodeMapper"> <mapper namespace="com.linkwechat.wecom.mapper.WeEmpleCodeMapper">
<resultMap type="WeEmpleCode" id="WeEmpleCodeResult"> <resultMap type="WeEmpleCode" id="WeEmpleCodeResult">
<result property="id" column="id" /> <result property="id" column="id"/>
<result property="codeType" column="code_type" /> <result property="codeType" column="code_type"/>
<result property="isJoinConfirmFriends" column="is_join_confirm_friends" /> <result property="isJoinConfirmFriends" column="is_join_confirm_friends"/>
<result property="activityScene" column="activity_scene" /> <result property="activityScene" column="activity_scene"/>
<result property="welcomeMsg" column="welcome_msg" /> <result property="welcomeMsg" column="welcome_msg"/>
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by"/>
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time"/>
<result property="delFlag" column="del_flag" /> <result property="delFlag" column="del_flag"/>
<result property="configId" column="config_id" /> <result property="configId" column="config_id"/>
<result property="qrCode" column="qr_code" /> <result property="qrCode" column="qr_code"/>
<result property="mediaId" column="media_id" /> <result property="mediaId" column="media_id"/>
<collection property="weEmpleCodeUseScops" ofType="com.linkwechat.wecom.domain.WeEmpleCodeUseScop"> <collection property="weEmpleCodeUseScops" ofType="com.linkwechat.wecom.domain.WeEmpleCodeUseScop">
<result property="businessId" column="business_id" /> <result property="businessId" column="business_id"/>
<result property="businessName" column="business_name" /> <result property="businessName" column="business_name"/>
<result property="mobile" column="mobile" /> <result property="mobile" column="mobile"/>
</collection> </collection>
<collection property="weEmpleCodeTags" ofType="com.linkwechat.wecom.domain.WeEmpleCodeTag"> <collection property="weEmpleCodeTags" ofType="com.linkwechat.wecom.domain.WeEmpleCodeTag">
<result property="tagId" column="tag_id" /> <result property="tagId" column="tag_id"/>
<result property="tagName" column="tag_name" /> <result property="tagName" column="tag_name"/>
</collection> </collection>
</resultMap> </resultMap>
...@@ -64,17 +64,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -64,17 +64,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wecode.id = wecusn.emple_code_id wecode.id = wecusn.emple_code_id
left join we_emple_code_tag wect on left join we_emple_code_tag wect on
wecode.id = wect.emple_code_id wecode.id = wect.emple_code_id
where 1=1 and wecode.del_flag = 0
</sql> </sql>
<select id="selectWeEmpleCodeList" parameterType="WeEmpleCode" resultMap="WeEmpleCodeResult"> <select id="selectWeEmpleCodeList" parameterType="WeEmpleCode" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/> <include refid="selectWeEmpleCodeLsit"/>
<where> <if test="codeType != null ">and wecode.code_type = #{codeType}</if>
<if test="codeType != null "> and wecode.code_type = #{codeType}</if> <if test="isJoinConfirmFriends != null ">and wecode.is_join_confirm_friends = #{isJoinConfirmFriends}</if>
<if test="isJoinConfirmFriends != null "> and wecode.is_join_confirm_friends = #{isJoinConfirmFriends}</if>
<if test="activityScene != null and activityScene != ''"> <if test="activityScene != null and activityScene != ''">
and wecode.activity_scene like concat('%', #{activityScene}, '%') and wecode.activity_scene like concat('%', #{activityScene}, '%')
</if> </if>
<if test="welcomeMsg != null "> and wecode.welcome_msg = #{welcomeMsg}</if> <if test="welcomeMsg != null ">and wecode.welcome_msg = #{welcomeMsg}</if>
<if test="createBy != null and createBy !=''"> <if test="createBy != null and createBy !=''">
AND wecode.create_by like concat('%', #{createBy}, '%') AND wecode.create_by like concat('%', #{createBy}, '%')
</if> </if>
...@@ -90,26 +90,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -90,26 +90,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="useUserName != null and useUserName !=''"> <if test="useUserName != null and useUserName !=''">
AND wecusn.business_name like concat('%', #{useUserName}, '%') AND wecusn.business_name like concat('%', #{useUserName}, '%')
</if> </if>
</where>
</select> </select>
<select id="selectWeEmpleCodeById" parameterType="Long" resultMap="WeEmpleCodeResult"> <select id="selectWeEmpleCodeById" parameterType="Long" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/> <include refid="selectWeEmpleCodeLsit"/>
<where> <if test="id != null and id !=''">
wecode.id = #{id} and wecode.id = #{id}
</where> </if>
</select> </select>
<select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult"> <select id="selectWeEmpleCodeByIds" parameterType="java.util.ArrayList" resultMap="WeEmpleCodeResult">
<include refid="selectWeEmpleCodeLsit"/> <include refid="selectWeEmpleCodeLsit"/>
<where> <if test="ids != null and ids.size > 0">
<if test="ids != null">
wecode.id in wecode.id in
<foreach collection="ids" item="id" open="(" close=")" separator=","> <foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id} #{id}
</foreach> </foreach>
</if> </if>
</where>
</select> </select>
<insert id="insertWeEmpleCode" parameterType="WeEmpleCode"> <insert id="insertWeEmpleCode" parameterType="WeEmpleCode">
...@@ -182,7 +179,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -182,7 +179,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</update> </update>
<select id="selectWelcomeMsgByActivityScene" parameterType="String" resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto"> <select id="selectWelcomeMsgByActivityScene" parameterType="String"
resultType="com.linkwechat.wecom.domain.dto.WeEmpleCodeDto">
select select
wecode.welcome_msg , wecode.welcome_msg ,
wm.category_id, wm.category_id,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!