FollowApiServiceImpl.java 3.76 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.common.utils.StringUtils;
import cn.fw.valhalla.domain.dto.OriginalDataDTO;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.sdk.api.FollowApiService;
import cn.fw.valhalla.sdk.enums.DataTypeEnum;
import cn.fw.valhalla.sdk.param.FollowOriginalParam;
import cn.fw.valhalla.sdk.param.ShouldBeCompletedQuery;
import cn.fw.valhalla.sdk.result.ShouldBeCompletedResult;
import cn.fw.valhalla.service.bus.follow.FollowApiBizService;
import cn.fw.valhalla.service.bus.follow.OriginalDataBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
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 : FollowApiServiceImpl
 * @description : 跟进api
 * @date: 2020-08-14 17:53
 */
@Slf4j
@RestController
@RequestMapping("/api/valhalla/follow")
public class FollowApiServiceImpl implements FollowApiService {

    private final OriginalDataBizService originalDataBizService;
    private final FollowApiBizService followApiBizService;

    @Autowired
    public FollowApiServiceImpl(final OriginalDataBizService originalDataBizService,
                                final FollowApiBizService followApiBizService) {
        this.originalDataBizService = originalDataBizService;
        this.followApiBizService = followApiBizService;
    }

    @Override
    @PostMapping("/origin/save")
    @ControllerMethod("业务元数据保存")
    public Message<Void> saveOriginal(@Valid @RequestBody FollowOriginalParam originalParam) {
        log.info("跟进元数据:[customerId: {} vin:{} plateNo:{} generateTime:{}]",
                originalParam.getCustomerId(), originalParam.getFrameNo(), originalParam.getPlateNo(), originalParam.getGenerateTime());
        String frameNo = originalParam.getFrameNo();
        Long customerId = originalParam.getCustomerId();
        boolean bool = Objects.nonNull(customerId) || StringUtils.isValid(frameNo);
        BV.isTrue(bool, () -> "档案id或者车架号不能为空");
        OriginalDataDTO dataDTO = new OriginalDataDTO();
        BeanUtils.copyProperties(originalParam, dataDTO);
        originalDataBizService.saveOrigin(dataDTO);
        return success();
    }

    @Override
    @GetMapping("/origin/remove")
    @ControllerMethod("业务元数据删除")
    public Message<Void> removeData(@RequestParam("type") Integer type, @RequestParam("detailId") String detailId) {
        DataTypeEnum typeEnum = DataTypeEnum.ofValue(type);
        BV.notNull(typeEnum, "业务类型不正确");
        originalDataBizService.remove(typeEnum, detailId);
        return success();
    }

    @Override
    @GetMapping("/should/ins/completed")
    @ControllerMethod("查询续保跟进应成交台数")
    public Message<List<ShouldBeCompletedResult>> queryInsShouldBeCompleted(@Validated @SpringQueryMap ShouldBeCompletedQuery query) {
        return success(followApiBizService.queryShouldBeCompleted(query, FollowTypeEnum.IR));
    }

    @Override
    @GetMapping("/ins/completed_arr")
    @ControllerMethod("查询续保跟进应成交台数")
    public Message<List<ShouldBeCompletedResult>> queryInsCompletedGuys(@Validated @SpringQueryMap ShouldBeCompletedQuery query) {
        return success(followApiBizService.queryCompletedGuys(query, FollowTypeEnum.IR));
    }
}