Commit 65c9ab23 authored by libin's avatar libin

客服悠

parent 196c0ba2
...@@ -18,7 +18,7 @@ import lombok.NoArgsConstructor; ...@@ -18,7 +18,7 @@ import lombok.NoArgsConstructor;
public class CustomerServiceDTO { public class CustomerServiceDTO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String id; private Long id;
/** /**
* 客服名称 * 客服名称
......
...@@ -31,7 +31,7 @@ public class CustomerService { ...@@ -31,7 +31,7 @@ public class CustomerService {
@Id @Id
@javax.persistence.Id @javax.persistence.Id
@GeneratedValue(generator = "JDBC") @GeneratedValue(generator = "JDBC")
private String id; private Long id;
/** /**
* 客服名称 * 客服名称
*/ */
...@@ -76,6 +76,10 @@ public class CustomerService { ...@@ -76,6 +76,10 @@ public class CustomerService {
* 客服电话 * 客服电话
*/ */
private String telphone; private String telphone;
/**
* 登录密码
*/
private String password;
/** /**
* 是事删除 true:删除状态 1:正常 * 是事删除 true:删除状态 1:正常
*/ */
......
...@@ -20,7 +20,7 @@ import java.io.Serializable; ...@@ -20,7 +20,7 @@ import java.io.Serializable;
public class CustomerServiceVO implements Serializable { public class CustomerServiceVO implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String id; private Long id;
/** /**
* 客服名称 * 客服名称
......
...@@ -5,30 +5,21 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,30 +5,21 @@ import com.alibaba.fastjson.JSONObject;
import com.github.wxiaoqi.security.common.biz.BaseBiz; 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.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.im.dto.CustomerServiceDTO; import com.xxfc.platform.im.dto.CustomerServiceDTO;
import com.xxfc.platform.im.entity.CustomerService; import com.xxfc.platform.im.entity.CustomerService;
import com.xxfc.platform.im.mapper.CustomerServiceMapper; import com.xxfc.platform.im.mapper.CustomerServiceMapper;
import com.xxfc.platform.im.model.User;
import com.xxfc.platform.im.repos.CustomerServiceRepository;
import com.xxfc.platform.im.vo.CustomerServiceVO; import com.xxfc.platform.im.vo.CustomerServiceVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; 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 org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;
import java.time.Instant; import java.time.Instant;
import java.util.*; 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 * @author libin
...@@ -38,95 +29,139 @@ import static org.springframework.data.mongodb.core.query.Update.update; ...@@ -38,95 +29,139 @@ import static org.springframework.data.mongodb.core.query.Update.update;
*/ */
@Service @Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired)) @RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class CustomerServiceBiz extends BaseBiz<CustomerServiceMapper,CustomerService> { public class CustomerServiceBiz extends BaseBiz<CustomerServiceMapper, CustomerService> {
private final static String INIT_PASSWORD="12345678";
private final static String NICK_PRE_NAME="XXKF"; private final static String INIT_PASSWORD = "12345678";
private final CustomerServiceRepository customerServiceRepository; private final static String NICK_PRE_NAME = "XXKF";
private final MongoTemplate mongoTemplate;
private final UserBiz userBiz; private final UserBiz userBiz;
public CustomerServiceVO findById(String id){ public CustomerServiceVO findById(Long id) {
CustomerServiceVO customerServiceVO = new CustomerServiceVO(); CustomerServiceVO customerServiceVO = new CustomerServiceVO();
customerServiceRepository.findById(id).ifPresent(customerService -> { CustomerService customerService = mapper.selectByPrimaryKey(id);
BeanUtils.copyProperties(customerService,customerServiceVO); BeanUtils.copyProperties(customerService, customerServiceVO);
}); return 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 * @param customerServiceDTO
*/ */
public void addCustomerService(CustomerServiceDTO customerServiceDTO){ public void addCustomerService(CustomerServiceDTO customerServiceDTO) {
CustomerService customerService = new CustomerService(); CustomerService customerService = new CustomerService();
BeanUtils.copyProperties(customerServiceDTO,customerService); BeanUtils.copyProperties(customerServiceDTO, customerService);
customerService.setCreateTime(Instant.now().toEpochMilli());
customerService.setName(String.format("%s%s",NICK_PRE_NAME,customerServiceDTO.getTelphone())); if (Objects.isNull(customerServiceDTO.getId())){
customerService.setIsDel(false); customerService.setCreateTime(Instant.now().toEpochMilli());
customerService.setName(String.format("%s%s", NICK_PRE_NAME, customerServiceDTO.getTelphone()));
Map<String,Object> imMap = new HashMap<>(2); customerService.setIsDel(false);
imMap.put("telephone",customerServiceDTO.getTelphone()); customerService.setPassword(INIT_PASSWORD);
imMap.put("password",INIT_PASSWORD); Map<String, Object> imMap = new HashMap<>(2);
imMap.put("nickname",customerService.getName()); imMap.put("telephone", customerServiceDTO.getTelphone());
BaseResponse imResponse = userBiz.register(imMap); imMap.put("password", INIT_PASSWORD);
String imResult = imResponse.getMessage(); imMap.put("nickname", customerService.getName());
JSONObject jsonObject = JSON.parseObject(imResult); BaseResponse imResponse = userBiz.register(imMap);
Map<String,Object> data = (Map<String, Object>) jsonObject.get("data"); String imResult = imResponse.getMessage();
Object userId = data.get("userId"); JSONObject jsonObject = JSON.parseObject(imResult);
if (Objects.isNull(userId)){ Map<String, Object> data = (Map<String, Object>) jsonObject.get("data");
throw new BaseException("注册失败"); Object userId = data.get("userId");
if (Objects.isNull(userId)) {
throw new BaseException("注册失败");
}
customerService.setImUserId((Integer) userId);
mapper.insertSelective(customerService);
}else {
customerService.setUpdateTime(Instant.now().toEpochMilli());
if (!StringUtils.isEmpty(customerServiceDTO.getPassword())){
userBiz.updatePasswordByPhone(customerServiceDTO.getTelphone(),customerServiceDTO.getPassword());
}
mapper.updateByPrimaryKeySelective(customerService);
} }
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() { public List<CustomerServiceVO> findAll() {
List<CustomerServiceVO> customerServiceVOS = new ArrayList<>(); List<CustomerServiceVO> customerServiceVOS = new ArrayList<>();
CustomerService customer_service = new CustomerService(); Example example = new Example(CustomerService.class);
Example<CustomerService> customerServiceExample = Example.of(customer_service, ExampleMatcher.matchingAll()); Example.Criteria criteria = example.createCriteria();
List<CustomerService> customerServices = customerServiceRepository.findAll(customerServiceExample); criteria.andEqualTo("isDel", 0);
List<CustomerService> customerServices = mapper.selectByExample(example);
CustomerServiceVO customerServiceVO;
if (CollectionUtils.isNotEmpty(customerServices)){ if (CollectionUtils.isNotEmpty(customerServices)) {
List<Integer> imUserIds = customerServices.stream().map(CustomerService::getImUserId).collect(Collectors.toList()); CustomerServiceVO customerServiceVO;
Map<Integer, User> imMap = userBiz.findAllByImUserIds(imUserIds); for (CustomerService customerService : customerServices) {
for (CustomerService customerService : customerServices) { customerServiceVO = new CustomerServiceVO();
customerServiceVO = new CustomerServiceVO(); BeanUtils.copyProperties(customerService, customerServiceVO);
BeanUtils.copyProperties(customerService,customerServiceVO); customerServiceVOS.add(customerServiceVO);
User user = imMap.get(customerService.getImUserId()); }
if (Objects.nonNull(user)){ }
customerServiceVO.setPassword(user.getPassword());
}
customerServiceVOS.add(customerServiceVO);
}
}
return customerServiceVOS; return customerServiceVOS;
} }
/** /**
* 删除客服 * 删除客服
*
* @param id * @param id
* @param imUserId * @param imUserId
*/ */
public void updateCustomerServiceIsDelToTrue(String id,Integer imUserId){ public void updateCustomerServiceIsDelToTrue(Long id, Integer imUserId) {
Query query = query(Criteria.where("_id").is(id)); CustomerService customerService = new CustomerService();
Update update = update("is_del", true).set("update_time",Instant.now().toEpochMilli()); customerService.setId(id);
mongoTemplate.updateFirst(query, update, Map.class, "customer_service"); customerService.setIsDel(true);
customerService.setUpdateTime(Instant.now().toEpochMilli());
mapper.updateByPrimaryKeySelective(customerService);
userBiz.deleteById(imUserId); userBiz.deleteById(imUserId);
} }
public void updatePasswordByPhone(String telphone, String password) {
Example example = new Example(CustomerService.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("telphone",telphone);
CustomerService customerService = new CustomerService();
customerService.setPassword(password);
customerService.setUpdateTime(Instant.now().toEpochMilli());
mapper.updateByExampleSelective(customerService,example);
}
public PageDataVO<CustomerServiceVO> findCustomerServiceWithPage(Integer page, Integer limit) {
PageDataVO<CustomerServiceVO> dataVO = new PageDataVO<>();
Example example = new Example(CustomerService.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("is_del",false);
PageDataVO<CustomerService> pageDataVO = PageDataVO.pageInfo(page,limit,()->mapper.selectByExample(example));
List<CustomerService> data = pageDataVO.getData();
if (CollectionUtils.isEmpty(data)){
return dataVO;
}
List<CustomerServiceVO> customerServiceVOS = new ArrayList<>();
CustomerServiceVO customerServiceVO;
for (CustomerService customerService : data) {
customerServiceVO = new CustomerServiceVO();
BeanUtils.copyProperties(customerService,customerServiceVO);
customerServiceVOS.add(customerServiceVO);
}
dataVO.setPageSize(pageDataVO.getPageSize());
dataVO.setPageNum(pageDataVO.getPageNum());
dataVO.setTotalPage(pageDataVO.getTotalPage());
dataVO.setTotalCount(pageDataVO.getTotalCount());
dataVO.setData(customerServiceVOS);
return dataVO;
}
public CustomerServiceDTO findCustomerServiceById(Long id) {
CustomerServiceDTO customerServiceDTO = new CustomerServiceDTO();
CustomerService customerService = mapper.selectByPrimaryKey(id);
BeanUtils.copyProperties(customerService,customerService);
return customerServiceDTO;
}
} }
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.biz.CustomerServiceMGBiz;
import com.xxfc.platform.im.vo.CustomerServiceVO; import com.xxfc.platform.im.vo.CustomerServiceVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -23,16 +24,19 @@ import java.util.List; ...@@ -23,16 +24,19 @@ import java.util.List;
@RequestMapping("/app/unauth/customer_service") @RequestMapping("/app/unauth/customer_service")
public class CustomerServiceController { public class CustomerServiceController {
private final CustomerServiceMGBiz customerServiceMGBiz; private final CustomerServiceMGBiz customerServiceMGBiz;
private final CustomerServiceBiz customerServiceBiz;
@GetMapping("/list") @GetMapping("/list")
public ObjectRestResponse<List<CustomerServiceVO>> findAll(){ public ObjectRestResponse<List<CustomerServiceVO>> findAll(){
List<CustomerServiceVO> customerServiceVOS = customerServiceMGBiz.findAll(); // List<CustomerServiceVO> customerServiceVOS = customerServiceMGBiz.findAll();
List<CustomerServiceVO> customerServiceVOS = customerServiceBiz.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") Long id){
CustomerServiceVO customerServiceVO = customerServiceMGBiz.findById(id); // CustomerServiceVO customerServiceVO = customerServiceMGBiz.findById(id);
CustomerServiceVO customerServiceVO = customerServiceBiz.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.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.im.biz.CustomerServiceBiz;
import com.xxfc.platform.im.biz.CustomerServiceMGBiz; 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 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;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -21,12 +24,27 @@ public class CustomerServiceAdminController { ...@@ -21,12 +24,27 @@ public class CustomerServiceAdminController {
private final CustomerServiceMGBiz customerServiceMGBiz; private final CustomerServiceMGBiz customerServiceMGBiz;
private final CustomerServiceBiz customerServiceBiz;
private final UserBiz userBiz; private final UserBiz userBiz;
@GetMapping("/page")
public ObjectRestResponse<PageDataVO<CustomerServiceVO>> findCustomerServiceWithPage(@RequestParam(value = "page") Integer page,
@RequestParam(value = "limit") Integer limit) {
PageDataVO<CustomerServiceVO> pageDataVO = customerServiceBiz.findCustomerServiceWithPage(page,limit);
return ObjectRestResponse.succ(pageDataVO);
}
@GetMapping("/{id}")
public ObjectRestResponse<CustomerServiceDTO> findCustomerService(@PathVariable(value = "id") Long id){
CustomerServiceDTO customerServiceDTO = customerServiceBiz.findCustomerServiceById(id);
return ObjectRestResponse.succ(customerServiceDTO);
}
@PostMapping("/add") @PostMapping("/add")
public ObjectRestResponse<Void> addCustomerService(@RequestBody CustomerServiceDTO customerServiceDTO){ public ObjectRestResponse<Void> addCustomerService(@RequestBody CustomerServiceDTO customerServiceDTO){
customerServiceMGBiz.addCustomerService(customerServiceDTO); // customerServiceMGBiz.addCustomerService(customerServiceDTO);
customerServiceBiz.addCustomerService(customerServiceDTO);
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
...@@ -34,13 +52,15 @@ public class CustomerServiceAdminController { ...@@ -34,13 +52,15 @@ public class CustomerServiceAdminController {
public ObjectRestResponse<Void> updateCustomerService(@PathVariable(value = "telphone") String telphone, public ObjectRestResponse<Void> updateCustomerService(@PathVariable(value = "telphone") String telphone,
@PathVariable(value = "password") String password){ @PathVariable(value = "password") String password){
userBiz.updatePasswordByPhone(telphone,password); userBiz.updatePasswordByPhone(telphone,password);
customerServiceBiz.updatePasswordByPhone(telphone,password);
return ObjectRestResponse.succ(); return ObjectRestResponse.succ();
} }
@DeleteMapping("/delete/{id}/{imUserId}") @DeleteMapping("/delete/{id}/{imUserId}")
public ObjectRestResponse<Void> deleteCustomerService(@PathVariable(value = "id") String id, public ObjectRestResponse<Void> deleteCustomerService(@PathVariable(value = "id") Long id,
@PathVariable(value = "imUserId") Integer imUserId){ @PathVariable(value = "imUserId") Integer imUserId){
customerServiceMGBiz.updateCustomerServiceIsDelToTrue(id,imUserId); // customerServiceMGBiz.updateCustomerServiceIsDelToTrue(id,imUserId);
customerServiceBiz.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