ValhallaGeneralApiServiceImpl.java 5.1 KB
package cn.fw.valhalla.controller.api;

import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.data.base.domain.common.Message;
import cn.fw.valhalla.domain.db.follow.ClueTask;
import cn.fw.valhalla.domain.dto.CustomerDetailDto;
import cn.fw.valhalla.sdk.api.ValhallaGeneralApiService;
import cn.fw.valhalla.sdk.param.CustomerQueryReq;
import cn.fw.valhalla.sdk.param.ReachLogReq;
import cn.fw.valhalla.sdk.result.AccidentFollowerResult;
import cn.fw.valhalla.sdk.result.CustomerClueDeadline;
import cn.fw.valhalla.sdk.result.CustomerSimpleInfoDto;
import cn.fw.valhalla.service.bus.ReachLogBizService;
import cn.fw.valhalla.service.bus.cust.CustomerBizService;
import cn.fw.valhalla.service.bus.follow.ClueApiBizService;
import cn.fw.valhalla.service.bus.follow.FollowApiBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import static cn.fw.common.businessvalidator.Validator.BV;
import static cn.fw.common.web.util.ResultBuilder.success;

/**
 * @author : kurisu
 * @className : ValhallaGeneralApiServiceImpl
 * @description : 通用api实现
 * @date: 2020-11-11 16:01
 */
@Slf4j
@RestController
@RequestMapping("/api/valhalla/general")
public class ValhallaGeneralApiServiceImpl implements ValhallaGeneralApiService {

    private final ReachLogBizService reachLogBizService;
    /**
     * 保有客数据服务
     */
    private final CustomerBizService customerBiz;
    private final FollowApiBizService followApiBizService;
    private final ClueApiBizService clueApiBizService;

    @Autowired
    public ValhallaGeneralApiServiceImpl(final ReachLogBizService reachLogBizService,
                                         final CustomerBizService customerBiz,
                                         final FollowApiBizService followApiBizService,
                                         final ClueApiBizService clueApiBizService) {
        this.reachLogBizService = reachLogBizService;
        this.customerBiz = customerBiz;
        this.followApiBizService = followApiBizService;
        this.clueApiBizService = clueApiBizService;
    }

    @PostMapping("/reach/save")
    @Override
    @ControllerMethod("保存进站记录")
    public Message<Void> saveReachLog(@Valid @RequestBody ReachLogReq reachLogReq) {
        reachLogBizService.saveReachLog(reachLogReq);
        return success();
    }

    @Override
    @PostMapping("/query/customer/list")
    @ControllerMethod("查询保有客档案列表")
    public Message<List<CustomerSimpleInfoDto>> queryCustomList(@Valid @RequestBody CustomerQueryReq customerQueryReq) {
        List<CustomerDetailDto> list = customerBiz.queryCustomList(customerQueryReq);
        List<CustomerSimpleInfoDto> dtoList = new ArrayList<>();
        for (CustomerDetailDto customer : list) {
            CustomerSimpleInfoDto dto = new CustomerSimpleInfoDto();
            BeanUtils.copyProperties(customer, dto);
            dtoList.add(dto);
        }
        return success(dtoList);
    }


    /**
     * 查询车辆最短的一个跟进的截止日期(不包含事故车)
     *
     * @param vin
     * @return
     */
    @GetMapping("/query/customer/clue/deadline")
    @Override
    @ControllerMethod("查询车辆最短的一个跟进的截止日期")
    public Message<CustomerClueDeadline> queryClueDeadline(@RequestParam("vin") final String vin, @RequestParam("groupId") final Long groupId) {
        BV.isNotBlank(vin, () -> "vin不能为空");
        return success(clueApiBizService.queryClueDeadline(vin, groupId));
    }

    /**
     * 查询车辆最短的一个跟进的截止日期(不包含事故车)
     *
     * @param vinList
     * @return
     */
    @GetMapping("/query/customer/clue/batch/deadline")
    @Override
    @ControllerMethod("查询车辆最短的一个跟进的截止日期[批量]")
    public Message<List<CustomerClueDeadline>> queryClueDeadlineBatch(@RequestParam("vinList") final List<String> vinList, @RequestParam("groupId") final Long groupId) {
        BV.isNotEmpty(vinList, () -> "车辆vin不能为空");
        int size = vinList.size();
        BV.isTrue(size <= 1000, () -> "已经超过可查询的最大查询数量[1000]");
        return success(clueApiBizService.queryClueDeadlineBatch(vinList, groupId));
    }


    @Override
    @GetMapping("/query/accident/follower")
    @ControllerMethod("查询进行中的事故车跟进人员")
    public Message<AccidentFollowerResult> queryByPlate(@RequestParam("plateNo") String plateNo, @RequestParam("groupId") Long groupId) {
        ClueTask clueTask = followApiBizService.queryAccidentFollowerByPlate(plateNo, groupId);
        if (Objects.isNull(clueTask)) {
            return success();
        }
        AccidentFollowerResult result = new AccidentFollowerResult();
        result.setUserId(clueTask.getFollowUser());
        result.setUserName(clueTask.getFollowUserName());
        result.setShopId(clueTask.getFollowShop());
        return success(result);
    }
}