CommonController.java 5.05 KB
package cn.fw.valhalla.controller.app;

import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.data.base.domain.common.Message;
import cn.fw.security.auth.client.annotation.Authorization;
import cn.fw.security.auth.client.annotation.IgnoreAuth;
import cn.fw.security.auth.client.enums.AuthType;
import cn.fw.valhalla.common.utils.DateUtil;
import cn.fw.valhalla.domain.vo.PostUserVO;
import cn.fw.valhalla.service.bus.CommonService;
import cn.fw.valhalla.service.bus.CustomerImportBizService;
import cn.fw.valhalla.service.bus.LeaveNeedDoBizService;
import cn.fw.valhalla.service.bus.follow.FollowBizService;
import cn.fw.valhalla.service.bus.pub.PubStandBizService;
import cn.fw.valhalla.service.report.CustomerRetentionRatioBizService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import static cn.fw.common.web.util.ResultBuilder.success;

/**
 * @author : kurisu
 * @className : CommonController
 * @description : 公共接口
 * @date: 2020-10-22 11:06
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/common")
public class CommonController {
    private final CommonService commonService;
    private final LeaveNeedDoBizService leaveNeedDoBizService;
    private final CustomerImportBizService customerImportBizService;
    private final CustomerRetentionRatioBizService customerRetentionRatioBizService;
    private final FollowBizService followBizService;
    private final PubStandBizService pubStandBizService;


    @GetMapping("/staff/list")
    @IgnoreAuth
    @ControllerMethod("查询人员")
    public Message<List<PostUserVO>> list(@NotNull(message = "服务站ID不能为空") final Long shopId) {
        List<PostUserVO> list = commonService.getUsers(shopId);
        return success(list);
    }

    @GetMapping("/leave/add")
    @Authorization(AuthType.NONE)
    @ControllerMethod("添加离职待分配数据")
    public Message<Void> add(@NotNull(message = "服务站ID不能为空") final Long shopId,
                             @NotNull(message = "用户ID不能为空") final Long userId) {
        leaveNeedDoBizService.add(userId, shopId);
        return success();
    }

    @GetMapping("/import/deal")
    @Authorization(AuthType.NONE)
    @ControllerMethod("处理导入的档案数据")
    public Message<Void> dealImport() {
        customerImportBizService.integrated();
        return success();
    }

    @GetMapping("/import/apportion")
    @Authorization(AuthType.NONE)
    @ControllerMethod("导入的档案分配顾问")
    public Message<Void> apportion() {
        customerImportBizService.apportion();
        return success();
    }

    @GetMapping("/crr/extracting")
    @Authorization(AuthType.NONE)
    @ControllerMethod("保有客保持率抽取")
    public Message<Void> crrExtracting(String date) {
        Date nowDate = new Date();
        if (StringUtils.isNotBlank(date) && NumberUtils.isDigits(date)) {
            LocalDateTime localDateTime = Instant.ofEpochMilli(NumberUtils.toLong(date)).atZone(ZoneId.systemDefault()).toLocalDateTime();
            nowDate = DateUtil.localDateTime2Date(localDateTime);
        }
        customerRetentionRatioBizService.extracting(DateUtil.startDate(nowDate));
        return success();
    }

    /**
     * 交车后取消订单时回滚档案
     *
     * @param vin
     * @return
     */
    @GetMapping("/customer/rollback")
    @Authorization(AuthType.NONE)
    @ControllerMethod("交车后取消订单时回滚档案")
    public Message<Void> customerRollback(@NotBlank(message = "车架号不能为空") String vin,
                                          @RequestParam(defaultValue = "2", required = false, name = "groupId") Long groupId) {
        commonService.rollBack(vin, groupId);
        return success();
    }

    @GetMapping("/clue/manual/create")
    @Authorization(AuthType.NONE)
    @ControllerMethod("处理续保数据缺失")
    public Message<Integer> createNextClue(Long groupId) {
        if (Objects.isNull(groupId)) {
            groupId = 2L;
        }
        commonService.createClue(groupId);
        return success();
    }

    @GetMapping("/clue/manual/start")
    @Authorization(AuthType.NONE)
    @ControllerMethod("手动开始任务")
    public Message<Integer> manualStartClue() {
        followBizService.manualStartClue();
        return success();
    }

    @PutMapping("/stand/sync")
    @IgnoreAuth
    @ControllerMethod("同步站岗队列")
    public Message<Void> syncStand(Long groupId) {
        if (Objects.isNull(groupId)) {
            groupId = 2L;
        }
        pubStandBizService.syncQueue(groupId);
        return success();
    }
}