大屏接口

master
yechenhao 6 years ago
parent 15d434a2c6
commit d98ab38f6f

@ -128,14 +128,14 @@ public class CustomerService {
insertCustomer.setCreateTime(opCustomer.getCreateTime());
if (null != opCustomer) {
//存在--1.处理客户导购关系。
sellerCustomerRelation(opCustomer, customerDTO.getStaffCode(),opCustomer.getCreateTime(), poiStore.getId(), poiStoreStaff.getUserId());
sellerCustomerRelation(opCustomer, opCustomer.getCreateTime(), poiStore.getId(), poiStoreStaff.getUserId());
return opCustomer.getId();
} else {
insertCustomer.setCreateBy(Constants.SYS_OPERATION);
//不存在
opCustomerDOMapper.insert(insertCustomer);
//添加关系
sellerCustomerRelation(insertCustomer, customerDTO.getStaffCode(),insertCustomer.getCreateTime(), poiStore.getId(), poiStoreStaff.getUserId());
sellerCustomerRelation(insertCustomer, insertCustomer.getCreateTime(), poiStore.getId(), poiStoreStaff.getUserId());
return insertCustomer.getId();
}
}
@ -229,7 +229,7 @@ public class CustomerService {
if (poiStoreStaff != null) {
//存在--1.处理客户导购关系。
try {
sellerCustomerRelation(insertCustomer, turnBackDTOS.getEaCode(),sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
return;
@ -255,7 +255,7 @@ public class CustomerService {
if (poiStoreStaff != null) {
//添加关系
try {
sellerCustomerRelation(insertCustomer, turnBackDTOS.getEaCode(),sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
sellerCustomerRelation(insertCustomer, sdf.parse(turnBackDTOS.getJoinTime()), poiStore.getStoreId(), poiStoreStaff.getId());
}catch (Exception e) {
log.error(insertCustomer.toString(),e);
return;
@ -331,13 +331,10 @@ public class CustomerService {
* @param staffCode Code
*/
@Transactional(rollbackFor = Exception.class)
public void sellerCustomerRelation(OpCustomer opCustomer, String staffCode,Date joinTime, long shopId, long sellerId) {
QueryWrapper<PoiStoreStaff> staf = new QueryWrapper<PoiStoreStaff>();
staf.eq("staff_code", staffCode).eq("status", 1).ne("user_id", 0).last("limit 1");
PoiStoreStaff poiStoreStaff = poiStoreStaffDOMapper.selectOne(staf);
public void sellerCustomerRelation(OpCustomer opCustomer, Date joinTime, long shopId, long sellerId) {
QueryWrapper<OpSellerCustomerRelation> wrapper1 = new QueryWrapper<>();
wrapper1.eq("customer_id", opCustomer.getId()).eq("user_id", poiStoreStaff.getId()).eq("store_id", shopId).last("limit 1");
//一个客户只能添加一个店的店长微信,所以根据店铺判断即可
wrapper1.eq("customer_id", opCustomer.getId()).eq("store_id", shopId).last("limit 1");
OpSellerCustomerRelation opSellerCustomerRelation = opSellerCustomerRelationDOMapper.selectOne(wrapper1);
if (null == opSellerCustomerRelation) {
//不存在就添加
@ -362,6 +359,16 @@ public class CustomerService {
insertRelation.setType(2);
}
opSellerCustomerRelationDOMapper.insert(insertRelation);
}else{
//可能是同步过来的数据,此时已经存在的话,用有导购的代替
opSellerCustomerRelation.setCreateTime(joinTime);
opSellerCustomerRelation.setUpdateTime(new Date());
opSellerCustomerRelation.setCustomerId(opCustomer.getId());
opSellerCustomerRelation.setStoreId(shopId);
opSellerCustomerRelation.setUserId(sellerId);
opSellerCustomerRelation.setCreateBy(Constants.SYS_OPERATION);
opSellerCustomerRelation.setUpdateBy(Constants.SYS_OPERATION);
opSellerCustomerRelationDOMapper.updateById(opSellerCustomerRelation);
}
}

@ -96,4 +96,6 @@ public interface OpSellerCustomerRelationDOMapper extends BaseMapper<OpSellerCus
@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
@Param("type") Integer type);
Long selectSellerCustomerRelation(@Param("customerId") Long customerId, @Param("userId") Long userId, @Param("storeId") Long storeId);
}

@ -510,6 +510,7 @@ public class EmployeeService {
turnBackDTO.setEaCode(poiStoreStaff.getStaffCode());
}
}else{
//todo 绑定在标签导购上,后续删除
turnBackDTO.setEaCode(tagName);
}
}
@ -522,7 +523,7 @@ public class EmployeeService {
}
}
}
//type 1 微信type 2 企业微信
turnBackDTO.setType(externalContact.getType());
turnBackDTO.setUserId(cpUserId);
turnBackDTO.setName(externalContact.getName());

@ -1,10 +1,17 @@
package com.kiisoo.ic.wx.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kiisoo.ic.config.WxCpConfiguration;
import com.kiisoo.ic.customer.entity.OpCustomer;
import com.kiisoo.ic.customer.mapper.OpCustomerDOMapper;
import com.kiisoo.ic.customer.mapper.OpSellerCustomerRelationDOMapper;
import com.kiisoo.ic.department.entity.DepartmentDO;
import com.kiisoo.ic.employee.entity.CpUserCustomerRelationDO;
import com.kiisoo.ic.employee.entity.EmployeeDO;
import com.kiisoo.ic.employee.entity.PrivilageCpUserDO;
import com.kiisoo.ic.employee.mapper.PrivilageCpUserDOMapper;
import com.kiisoo.ic.store.mapper.PrivilageCpUserStoreDOMapper;
import com.kiisoo.ic.tag.entity.TagDO;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.error.WxErrorException;
@ -12,6 +19,7 @@ import me.chanjar.weixin.cp.api.*;
import me.chanjar.weixin.cp.bean.*;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.File;
@ -36,6 +44,18 @@ public class QWMailListManageService {
private WxCpService wxCpService;
@Autowired
private PrivilageCpUserStoreDOMapper privilageCpUserStoreDOMapper;
@Autowired
private PrivilageCpUserDOMapper privilageCpUserDOMapper;
@Autowired
private OpSellerCustomerRelationDOMapper opSellerCustomerRelationDOMapper;
@Autowired
private OpCustomerDOMapper opCustomerDOMapper;
/**
*
*/
@ -254,12 +274,39 @@ public class QWMailListManageService {
}
public List<WxCpUserExternalContactInfo> getCustomer(String cpUserId) throws WxErrorException {
List<WxCpUserExternalContactInfo> customers = new ArrayList<>();
//查询店铺id——店铺ID存在说明该账号的客户都绑在店上不存在则说明绑在账号上
Long storeId = privilageCpUserStoreDOMapper.selectOneByCpUserId(cpUserId);
//账号一定存在不存在则返回null
QueryWrapper<PrivilageCpUserDO> cpQw = new QueryWrapper<>();
cpQw.eq("cp_user_id",cpUserId).last("limit 1");
PrivilageCpUserDO privilageCpUserDO = privilageCpUserDOMapper.selectOne(cpQw);
if (privilageCpUserDO == null){
return null;
}
//获取第三方接口方法
List<WxCpUserExternalContactInfo> customers = null;
wxCpService = WxCpConfiguration.getCpService(applicationid);
WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
List<String> customerStrs = externalContactService.listExternalContacts(cpUserId);
//查询客户列表为空则直接返回
if (CollectionUtils.isNotEmpty(customerStrs)){
customers = new ArrayList<>();
for (String customerStr:customerStrs){
//查询该客户id的关系是否存在
QueryWrapper<OpCustomer> customerQueryWrapper = new QueryWrapper<>();
customerQueryWrapper.eq("external_userid",customerStr).last("limit 1");
OpCustomer opCustomer = opCustomerDOMapper.selectOne(customerQueryWrapper);
//客户都不存在则直接下一步
if (opCustomer != null){
Long relationId = opSellerCustomerRelationDOMapper.selectSellerCustomerRelation(opCustomer.getId(), privilageCpUserDO.getId(), storeId);
//关系存在则不查询明细
if (relationId != null){
continue;
}
}
WxCpUserExternalContactInfo contactDetail = externalContactService.getContactDetail(customerStr);
customers.add(contactDetail);

@ -210,4 +210,19 @@
</if>
GROUP BY t4.id order by t1.create_time desc
</select>
<select id="selectSellerCustomerRelation" resultType="java.lang.Long">
select t1.id from op_seller_customer_relation t1
where t1.customer_id = #{customerId}
<choose>
<when test="store_id != null">
and t1.store_id = #{storeId}
</when>
<otherwise>
t1.user_id = #{userId} and t1.type = 3 and t1.store_id = 0
</otherwise>
</choose>
limit 1
</select>
</mapper>

@ -9,7 +9,9 @@
select customer_user_id as customerUserId,cp_user_id as cpUserId,cp_id as cpId from op_cp_user_customer_relation
where customer_user_id = #{customerUserId}
and cp_user_id = #{cpUserId}
and cp_id = #{cpId}
<if test="cpId !=null and cpId !=''">
and cp_id = #{cpId}
</if>
limit 1
</select>

Loading…
Cancel
Save