Commit 196c0ba2 authored by libin's avatar libin

客服悠

parent c9e4a480
package com.xxfc.platform.im.model; package com.xxfc.platform.im.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.mongodb.morphia.annotations.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field; import org.springframework.data.mongodb.core.mapping.Field;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Table;
/** /**
* @author libin * @author libin
* @version 1.0 * @version 1.0
...@@ -18,10 +23,14 @@ import org.springframework.data.mongodb.core.mapping.Field; ...@@ -18,10 +23,14 @@ import org.springframework.data.mongodb.core.mapping.Field;
@Builder(toBuilder = true) @Builder(toBuilder = true)
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Entity
@Table(name = "customer_service")
@Document(collection = "customer_service") @Document(collection = "customer_service")
public class CustomerService { public class CustomerService {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Id @Id
@javax.persistence.Id
@GeneratedValue(generator = "JDBC")
private String id; private String id;
/** /**
* 客服名称 * 客服名称
...@@ -35,21 +44,25 @@ public class CustomerService { ...@@ -35,21 +44,25 @@ public class CustomerService {
* App id * App id
*/ */
@Field("app_user_id") @Field("app_user_id")
@Column(name = "app_user_id")
private Integer appUserId; private Integer appUserId;
/** /**
* im id * im id
*/ */
@Field("im_user_id") @Field("im_user_id")
@Column(name = "im_user_id")
private Integer imUserId; private Integer imUserId;
/** /**
* 区域id * 区域id
*/ */
@Field("area_id") @Field("area_id")
@Column(name = "area_id")
private Integer areaId; private Integer areaId;
/** /**
* 区域名称 * 区域名称
*/ */
@Field("area_name") @Field("area_name")
@Column(name = "area_name")
private String areaName; private String areaName;
/** /**
* 问候语句 * 问候语句
...@@ -67,12 +80,15 @@ public class CustomerService { ...@@ -67,12 +80,15 @@ public class CustomerService {
* 是事删除 true:删除状态 1:正常 * 是事删除 true:删除状态 1:正常
*/ */
@Field("is_del") @Field("is_del")
@Column(name = "is_del")
private Boolean isDel; private Boolean isDel;
@Field("create_time") @Field("create_time")
@Column(name = "create_time")
private Long createTime; private Long createTime;
@Field("update_time") @Field("update_time")
@Column(name = "update_time")
private Long updateTime; private Long updateTime;
} }
...@@ -2,12 +2,12 @@ package com.xxfc.platform.im.biz; ...@@ -2,12 +2,12 @@ package com.xxfc.platform.im.biz;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.constant.UserConstant; import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.exception.BaseException; import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.BaseResponse; import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.mongodb.client.result.UpdateResult;
import com.xxfc.platform.im.dto.CustomerServiceDTO; import com.xxfc.platform.im.dto.CustomerServiceDTO;
import com.xxfc.platform.im.model.CustomerService; import com.xxfc.platform.im.entity.CustomerService;
import com.xxfc.platform.im.mapper.CustomerServiceMapper;
import com.xxfc.platform.im.model.User; import com.xxfc.platform.im.model.User;
import com.xxfc.platform.im.repos.CustomerServiceRepository; import com.xxfc.platform.im.repos.CustomerServiceRepository;
import com.xxfc.platform.im.vo.CustomerServiceVO; import com.xxfc.platform.im.vo.CustomerServiceVO;
...@@ -21,7 +21,6 @@ import org.springframework.data.mongodb.core.MongoTemplate; ...@@ -21,7 +21,6 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.Instant; import java.time.Instant;
...@@ -39,7 +38,7 @@ import static org.springframework.data.mongodb.core.query.Update.update; ...@@ -39,7 +38,7 @@ import static org.springframework.data.mongodb.core.query.Update.update;
*/ */
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerServiceBiz { public class CustomerServiceBiz extends BaseBiz<CustomerServiceMapper,CustomerService> {
private final static String INIT_PASSWORD="12345678"; private final static String INIT_PASSWORD="12345678";
......
package com.xxfc.platform.im.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.msg.BaseResponse;
import com.xxfc.platform.im.dto.CustomerServiceDTO;
import com.xxfc.platform.im.entity.CustomerService;
import com.xxfc.platform.im.model.User;
import com.xxfc.platform.im.repos.CustomerServiceRepository;
import com.xxfc.platform.im.vo.CustomerServiceVO;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.core.query.Update.update;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/5 9:49
*/
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerServiceMGBiz {
private final static String INIT_PASSWORD="12345678";
private final static String NICK_PRE_NAME="XXKF";
private final CustomerServiceRepository customerServiceRepository;
private final MongoTemplate mongoTemplate;
private final UserBiz userBiz;
public CustomerServiceVO findById(String id){
CustomerServiceVO customerServiceVO = new CustomerServiceVO();
customerServiceRepository.findById(id).ifPresent(customerService -> {
BeanUtils.copyProperties(customerService,customerServiceVO);
});
Map<Integer, User> imMap = userBiz.findAllByImUserIds(Arrays.asList(customerServiceVO.getImUserId()));
User user = imMap.get(customerServiceVO.getImUserId());
customerServiceVO.setPassword(user.getPassword());
return customerServiceVO;
}
/**
* 添加客服
* @param customerServiceDTO
*/
public void addCustomerService(CustomerServiceDTO customerServiceDTO){
CustomerService customerService = new CustomerService();
BeanUtils.copyProperties(customerServiceDTO,customerService);
customerService.setCreateTime(Instant.now().toEpochMilli());
customerService.setName(String.format("%s%s",NICK_PRE_NAME,customerServiceDTO.getTelphone()));
customerService.setIsDel(false);
Map<String,Object> imMap = new HashMap<>(2);
imMap.put("telephone",customerServiceDTO.getTelphone());
imMap.put("password",INIT_PASSWORD);
imMap.put("nickname",customerService.getName());
BaseResponse imResponse = userBiz.register(imMap);
String imResult = imResponse.getMessage();
JSONObject jsonObject = JSON.parseObject(imResult);
Map<String,Object> data = (Map<String, Object>) jsonObject.get("data");
Object userId = data.get("userId");
if (Objects.isNull(userId)){
throw new BaseException("注册失败");
}
customerService.setImUserId((Integer)userId);
customerServiceRepository.save(customerService);
}
/**
* 1: mongoTemplate.find(Query.query(Criteria.where("isDel").is(false)), CustomerService.class);
*
* 2. customerServiceRepository.findByIsDelEquals(false);
* @return
*/
public List<CustomerServiceVO> findAll() {
List<CustomerServiceVO> customerServiceVOS = new ArrayList<>();
CustomerService customer_service = new CustomerService();
Example<CustomerService> customerServiceExample = Example.of(customer_service, ExampleMatcher.matchingAll());
List<CustomerService> customerServices = customerServiceRepository.findAll(customerServiceExample);
CustomerServiceVO customerServiceVO;
if (CollectionUtils.isNotEmpty(customerServices)){
List<Integer> imUserIds = customerServices.stream().map(CustomerService::getImUserId).collect(Collectors.toList());
Map<Integer, User> imMap = userBiz.findAllByImUserIds(imUserIds);
for (CustomerService customerService : customerServices) {
customerServiceVO = new CustomerServiceVO();
BeanUtils.copyProperties(customerService,customerServiceVO);
User user = imMap.get(customerService.getImUserId());
if (Objects.nonNull(user)){
customerServiceVO.setPassword(user.getPassword());
}
customerServiceVOS.add(customerServiceVO);
}
}
return customerServiceVOS;
}
/**
* 删除客服
* @param id
* @param imUserId
*/
public void updateCustomerServiceIsDelToTrue(String id,Integer imUserId){
Query query = query(Criteria.where("_id").is(id));
Update update = update("is_del", true).set("update_time",Instant.now().toEpochMilli());
mongoTemplate.updateFirst(query, update, Map.class, "customer_service");
userBiz.deleteById(imUserId);
}
}
package com.xxfc.platform.im.mapper;
import com.xxfc.platform.im.entity.CustomerService;
import tk.mybatis.mapper.common.Mapper;
/**
* @author libin
* @version 1.0
* @description
* @data 2019/9/9 9:55
*/
public interface CustomerServiceMapper extends Mapper<CustomerService> {
}
package com.xxfc.platform.im.repos; package com.xxfc.platform.im.repos;
import com.xxfc.platform.im.model.CustomerService; import com.xxfc.platform.im.entity.CustomerService;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query; import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
......
package com.xxfc.platform.im.rest; package com.xxfc.platform.im.rest;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.im.biz.CustomerServiceBiz; import com.xxfc.platform.im.biz.CustomerServiceMGBiz;
import com.xxfc.platform.im.vo.CustomerServiceVO; import com.xxfc.platform.im.vo.CustomerServiceVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -22,17 +22,17 @@ import java.util.List; ...@@ -22,17 +22,17 @@ import java.util.List;
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("/app/unauth/customer_service") @RequestMapping("/app/unauth/customer_service")
public class CustomerServiceController { public class CustomerServiceController {
private final CustomerServiceBiz customerServiceBiz; private final CustomerServiceMGBiz customerServiceMGBiz;
@GetMapping("/list") @GetMapping("/list")
public ObjectRestResponse<List<CustomerServiceVO>> findAll(){ public ObjectRestResponse<List<CustomerServiceVO>> findAll(){
List<CustomerServiceVO> customerServiceVOS = customerServiceBiz.findAll(); List<CustomerServiceVO> customerServiceVOS = customerServiceMGBiz.findAll();
return ObjectRestResponse.succ(customerServiceVOS); return ObjectRestResponse.succ(customerServiceVOS);
} }
@GetMapping("/{id}") @GetMapping("/{id}")
public ObjectRestResponse<CustomerServiceVO> findById(@PathVariable(value = "id") String id){ public ObjectRestResponse<CustomerServiceVO> findById(@PathVariable(value = "id") String id){
CustomerServiceVO customerServiceVO = customerServiceBiz.findById(id); CustomerServiceVO customerServiceVO = customerServiceMGBiz.findById(id);
return ObjectRestResponse.succ(customerServiceVO); return ObjectRestResponse.succ(customerServiceVO);
} }
......
package com.xxfc.platform.im.rest.admin; package com.xxfc.platform.im.rest.admin;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.im.biz.CustomerServiceBiz; import com.xxfc.platform.im.biz.CustomerServiceMGBiz;
import com.xxfc.platform.im.biz.UserBiz; import com.xxfc.platform.im.biz.UserBiz;
import com.xxfc.platform.im.dto.CustomerServiceDTO; import com.xxfc.platform.im.dto.CustomerServiceDTO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -19,14 +19,14 @@ import org.springframework.web.bind.annotation.*; ...@@ -19,14 +19,14 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/admin/customer_service") @RequestMapping("/admin/customer_service")
public class CustomerServiceAdminController { public class CustomerServiceAdminController {
private final CustomerServiceBiz customerServiceBiz; private final CustomerServiceMGBiz customerServiceMGBiz;
private final UserBiz userBiz; private final UserBiz userBiz;
@PostMapping("/add") @PostMapping("/add")
public ObjectRestResponse<Void> addCustomerService(@RequestBody CustomerServiceDTO customerServiceDTO){ public ObjectRestResponse<Void> addCustomerService(@RequestBody CustomerServiceDTO customerServiceDTO){
customerServiceBiz.addCustomerService(customerServiceDTO); customerServiceMGBiz.addCustomerService(customerServiceDTO);
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
...@@ -40,7 +40,7 @@ public class CustomerServiceAdminController { ...@@ -40,7 +40,7 @@ public class CustomerServiceAdminController {
@DeleteMapping("/delete/{id}/{imUserId}") @DeleteMapping("/delete/{id}/{imUserId}")
public ObjectRestResponse<Void> deleteCustomerService(@PathVariable(value = "id") String id, public ObjectRestResponse<Void> deleteCustomerService(@PathVariable(value = "id") String id,
@PathVariable(value = "imUserId") Integer imUserId){ @PathVariable(value = "imUserId") Integer imUserId){
customerServiceBiz.updateCustomerServiceIsDelToTrue(id,imUserId); customerServiceMGBiz.updateCustomerServiceIsDelToTrue(id,imUserId);
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment