生成导购二维码添加店铺人员事件
parent
c7ea9d04f7
commit
cd1e0baa2d
@ -1,16 +0,0 @@
|
||||
//package com.kiisoo.ic.employee.mapper;
|
||||
//
|
||||
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
//import com.kiisoo.ic.employee.entity.PoiStoreStaffDO;
|
||||
//import org.springframework.stereotype.Repository;
|
||||
//
|
||||
///**
|
||||
// * @Description 店铺人员表mapper
|
||||
// * @Author yinliujing
|
||||
// * @Version V1.0.0
|
||||
// * @Date 2020/4/7
|
||||
// */
|
||||
//@Repository
|
||||
//public interface PoiStoreStaffDOMapper extends BaseMapper<PoiStoreStaffDO> {
|
||||
//
|
||||
//}
|
@ -1,87 +1,108 @@
|
||||
//package com.kiisoo.ic.employee.service;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.kiisoo.ic.config.WxCpConfiguration;
|
||||
//import com.kiisoo.ic.employee.entity.PoiStoreStaffDO;
|
||||
//import com.kiisoo.ic.employee.entity.QrCodeDO;
|
||||
//import com.kiisoo.ic.employee.entity.QrCodeVO;
|
||||
////import com.kiisoo.ic.employee.mapper.PoiStoreStaffDOMapper;
|
||||
//import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
||||
//import me.chanjar.weixin.common.error.WxErrorException;
|
||||
//import me.chanjar.weixin.cp.api.WxCpService;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @Description: 推广码业务
|
||||
// * @Auther: yinliujing
|
||||
// * @Date: 2020/4/7 0002 14:06
|
||||
// * @Version: v1
|
||||
// */
|
||||
//@Service
|
||||
//public class QrCodeService {
|
||||
// WxCpService mainService = WxCpConfiguration.getCpService(1000037);
|
||||
// @Autowired
|
||||
// private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
|
||||
//
|
||||
// public QrCodeVO getQrCode(QrCodeDO qrCodeDO) throws Exception {
|
||||
// //获取token
|
||||
// String token = mainService.getAccessToken();
|
||||
// qrCodeDO.setAccess_token(token);
|
||||
// //获取configId
|
||||
// String configId = getConfigId(qrCodeDO);
|
||||
// //获取配置实体
|
||||
// QrCodeVO qrCodeVO = getContactWay(token, configId);
|
||||
// return qrCodeVO;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 配置客户联系「联系我」方式
|
||||
// *
|
||||
// * @param qrCodeDO
|
||||
// * @return
|
||||
// * @throws WxErrorException
|
||||
// */
|
||||
// public String getConfigId(QrCodeDO qrCodeDO) throws WxErrorException {
|
||||
// String url = mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/externalcontact/add_contact_way");
|
||||
// String result = mainService.post(url, qrCodeDO.toJson());
|
||||
// JSONObject parseObject = JSON.parseObject(result);
|
||||
// String configId = parseObject.getString("config_id");
|
||||
// return configId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取企业已配置的「联系我」方式
|
||||
// *
|
||||
// * @param token
|
||||
// * @param configId
|
||||
// * @return
|
||||
// * @throws WxErrorException
|
||||
// */
|
||||
// public QrCodeVO getContactWay(String token, String configId) throws WxErrorException {
|
||||
// String url = mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/externalcontact/get_contact_way");
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("config_id", configId);
|
||||
// map.put("access_token", token);
|
||||
// String result = mainService.post(url, JSON.toJSONString(map));
|
||||
// JSONObject parseObject = JSON.parseObject(result);
|
||||
// QrCodeVO qrCodeVO = JSONObject.parseObject(parseObject.getString("contact_way"), QrCodeVO.class);
|
||||
// return qrCodeVO;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 添加店铺人员表
|
||||
// * @return
|
||||
// * @throws WxErrorException
|
||||
// */
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public int saveStoreStaff(PoiStoreStaffDO poiStoreStaffDO) throws Exception {
|
||||
// return poiStoreStaffDOMapper.insert(poiStoreStaffDO);
|
||||
// }
|
||||
//}
|
||||
package com.kiisoo.ic.employee.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.kiisoo.ic.config.WxCpConfiguration;
|
||||
import com.kiisoo.ic.employee.entity.QrCodeDO;
|
||||
import com.kiisoo.ic.employee.entity.QrCodeVO;
|
||||
import com.kiisoo.ic.store.entity.PoiStoreStaff;
|
||||
import com.kiisoo.ic.store.mapper.PoiStoreStaffDOMapper;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 推广码业务
|
||||
* @Auther: yinliujing
|
||||
* @Date: 2020/4/7 0002 14:06
|
||||
* @Version: v1
|
||||
*/
|
||||
@Service
|
||||
public class QrCodeService {
|
||||
WxCpService mainService = WxCpConfiguration.getCpService(1000037);
|
||||
@Autowired
|
||||
private PoiStoreStaffDOMapper poiStoreStaffDOMapper;
|
||||
|
||||
public QrCodeVO getQrCode(QrCodeDO qrCodeDO) throws Exception {
|
||||
//获取token
|
||||
String token = mainService.getAccessToken();
|
||||
qrCodeDO.setAccess_token(token);
|
||||
//获取configId
|
||||
String configId = getConfigId(qrCodeDO);
|
||||
//获取配置实体
|
||||
QrCodeVO qrCodeVO = getContactWay(token, configId);
|
||||
//添加店铺人员
|
||||
saveStoreStaff( parseStoreStaff(qrCodeDO,qrCodeVO));
|
||||
return qrCodeVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置客户联系「联系我」方式
|
||||
*
|
||||
* @param qrCodeDO
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public String getConfigId(QrCodeDO qrCodeDO) throws WxErrorException {
|
||||
String url = mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/externalcontact/add_contact_way");
|
||||
String result = mainService.post(url, qrCodeDO.toJson());
|
||||
JSONObject parseObject = JSON.parseObject(result);
|
||||
String configId = parseObject.getString("config_id");
|
||||
return configId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业已配置的「联系我」方式
|
||||
*
|
||||
* @param token
|
||||
* @param configId
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public QrCodeVO getContactWay(String token, String configId) throws WxErrorException {
|
||||
String url = mainService.getWxCpConfigStorage().getApiUrl("/cgi-bin/externalcontact/get_contact_way");
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("config_id", configId);
|
||||
map.put("access_token", token);
|
||||
String result = mainService.post(url, JSON.toJSONString(map));
|
||||
JSONObject parseObject = JSON.parseObject(result);
|
||||
QrCodeVO qrCodeVO = JSONObject.parseObject(parseObject.getString("contact_way"), QrCodeVO.class);
|
||||
return qrCodeVO;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*封装需要添加的店铺人员实体
|
||||
* 前台传的实体参数
|
||||
* 企业微信返回的实体
|
||||
*/
|
||||
public PoiStoreStaff parseStoreStaff(QrCodeDO qrCodeDO,QrCodeVO qrCodeVO) throws Exception {
|
||||
PoiStoreStaff poiStoreStaff = new PoiStoreStaff();
|
||||
BeanUtils.copyProperties(qrCodeDO,poiStoreStaff);
|
||||
poiStoreStaff.setType(qrCodeDO.getRole());
|
||||
poiStoreStaff.setEpWechatQrCode(qrCodeVO.getQr_code());
|
||||
poiStoreStaff.setEpWechatConfigId(qrCodeVO.getConfig_id());
|
||||
return poiStoreStaff;
|
||||
}
|
||||
/**
|
||||
* 添加店铺人员表
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void saveStoreStaff(PoiStoreStaff poiStoreStaffDO) throws Exception {
|
||||
QueryWrapper<PoiStoreStaff> storeStaff = new QueryWrapper<>();
|
||||
storeStaff.eq("user_id",poiStoreStaffDO.getUserId()).eq("store_id",poiStoreStaffDO.getStoreId()).last("limit 1");
|
||||
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectOne(storeStaff);
|
||||
if (null == poiStoreStaff){
|
||||
poiStoreStaffDOMapper.insert(poiStoreStaffDO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue