CommonService.java 4.19 KB
package cn.fw.valhalla.service.bus;

import cn.fw.valhalla.common.constant.RoleCode;
import cn.fw.valhalla.domain.db.customer.AccidentPool;
import cn.fw.valhalla.domain.db.customer.Customer;
import cn.fw.valhalla.domain.db.customer.CustomerBaseInfo;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.vo.PostUserVO;
import cn.fw.valhalla.rpc.ehr.EhrRpcService;
import cn.fw.valhalla.rpc.ehr.dto.StaffInfoDTO;
import cn.fw.valhalla.rpc.erp.UserService;
import cn.fw.valhalla.rpc.erp.dto.PostUserDTO;
import cn.fw.valhalla.rpc.order.OrderRpcService;
import cn.fw.valhalla.rpc.pstn.PstnService;
import cn.fw.valhalla.service.bus.cust.CustomerChangeBizService;
import cn.fw.valhalla.service.data.AccidentPoolService;
import cn.fw.valhalla.service.data.CustomerBaseInfoService;
import cn.fw.valhalla.service.data.CustomerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static cn.fw.common.businessvalidator.Validator.BV;

/**
 * @author : kurisu
 * @className : CommonService
 * @description : 公共服务
 * @date: 2020-10-22 11:07
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class CommonService {
    private final UserService userService;
    private final CustomerService customerService;
    private final CustomerBaseInfoService customerBaseInfoService;
    private final OrderRpcService orderRpcService;
    private final PstnService pstnService;
    private final EhrRpcService ehrRpcService;
    private final AccidentPoolService accidentPoolService;
    private final CustomerChangeBizService customerChangeBizService;


    public List<PostUserVO> getUsers(final Long shopId, final Integer type) {
        FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
        BV.notNull(typeEnum, () -> "跟进类型错误");
        List<PostUserDTO> userByRole = userService.getUserByRole(shopId, getRoleCode(typeEnum));
        return userByRole.stream().map(user -> new PostUserVO(user.getUserId(), user.getUserName())).collect(Collectors.toList());
    }

    public void rollBack(String vin, Long groupId) {
        rollBack(vin);
        customerChangeBizService.rollBack(vin, groupId);
    }

    public void rollBack(String vin) {
        //todo 去订单系统校验vin是否是退换车
    }

    /**
     * 通过智能通话系统获取所拨打的电话号码
     *
     * @param userId
     * @param cusId
     * @param accidentCar
     * @return
     */
    public String call(Long userId, Long cusId, Boolean accidentCar) {
        StaffInfoDTO staffInfo = ehrRpcService.queryStaffInfo(userId);
        BV.notNull(staffInfo, () -> "用户身份验证异常,请重试");
        String becallNo;
        if (Boolean.TRUE.equals(accidentCar)) {
            AccidentPool accidentPool = accidentPoolService.getById(cusId);
            BV.notNull(accidentPool, () -> "用户不存在");
            becallNo = accidentPool.getReportMobile();
        } else {
            Customer customer = customerService.queryByIdWithInvalid(cusId);
            BV.notNull(customer, () -> "用户不存在");
            BV.isTrue(customer.getYn(), () -> "此档案已经作废,请主动放弃本次跟进");
            CustomerBaseInfo baseInfo = customerBaseInfoService.getById(customer.getBaseId());
            BV.notNull(baseInfo, () -> "用户不存在");
            becallNo = baseInfo.getMobile();
        }
        BV.isNotBlank(becallNo, () -> "客户电话号码不正确,无法拨打");
        assert staffInfo != null;
        BV.isNotBlank(staffInfo.getMobile(), () -> "用户电话号码不正确,无法拨打");
        String virtualNumber = pstnService.virtualNumber(staffInfo.getMobile(), becallNo, staffInfo.getGroupId());
        BV.isNotBlank(virtualNumber, () -> "号码不正确,无法拨号");
        return virtualNumber;
    }

    private String getRoleCode(FollowTypeEnum followTypeEnum) {
        switch (followTypeEnum) {
            case AC:
                return RoleCode.SGCGJ;
            case IR:
                return RoleCode.XBGJ;
            case FM:
            case RM:
            default:
                return RoleCode.FWGW;
        }
    }
}