ValhallaGeneralApiServiceImpl.java 2.59 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.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.CustomerSimpleInfoDto;
import cn.fw.valhalla.service.bus.ReachLogBizService;
import cn.fw.valhalla.service.bus.cust.CustomerBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

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;

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

    @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);
    }
}