FollowController.java 5.74 KB
package cn.fw.valhalla.controller.app;

import cn.fw.common.page.AppPage;
import cn.fw.common.web.annotation.ControllerMethod;
import cn.fw.common.web.auth.LoginAuthBean;
import cn.fw.common.web.auth.annotation.CurrentUser;
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.domain.dto.FollowAttachmentDTO;
import cn.fw.valhalla.domain.enums.FollowTypeEnum;
import cn.fw.valhalla.domain.query.FollowQueryVO;
import cn.fw.valhalla.domain.vo.follow.CustomerClueHistoryVO;
import cn.fw.valhalla.domain.vo.follow.FollowDetailVO;
import cn.fw.valhalla.domain.vo.follow.FollowRecordVO;
import cn.fw.valhalla.domain.vo.follow.FollowTodoListVO;
import cn.fw.valhalla.service.bus.follow.FollowBizService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
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 : FollowController
 * @description : 跟进控制器
 * @date: 2020-08-15 16:23
 */
@Slf4j
@RestController
@Authorization(AuthType.APP)
@Validated
@RequestMapping("/app/follow")
public class FollowController {
    private final FollowBizService followBizService;

    @Autowired
    public FollowController(final FollowBizService followBizService) {
        this.followBizService = followBizService;
    }


    @GetMapping("/todo/list")
    @ControllerMethod("分页查询跟进待办列表")
    @Deprecated
    public Message<AppPage<FollowTodoListVO>> todoList(@CurrentUser LoginAuthBean currentUser, final FollowQueryVO queryVO) {
        BV.notNull(queryVO.getType(), "跟进类型不正确");
        AppPage<FollowTodoListVO> page = followBizService.todoList(queryVO, currentUser);
        return success(page);
    }

    @GetMapping("/todo/detail")
    @ControllerMethod("查询跟进待办详情")
    public Message<FollowDetailVO> todoDetail(@NotNull(message = "跟进记录id不能为空") final Long id) {
        FollowDetailVO detailVO = followBizService.todoDetail(id);
        return success(detailVO);
    }

    @GetMapping("/approve/detail")
    @IgnoreAuth
    @ControllerMethod("查询跟进战败审批详情")
    public Message<FollowDetailVO> approveDetail(final Long recordId, final Long taskId, final Integer type) {
        FollowDetailVO detailVO = followBizService.approveDetail(recordId, taskId, type);
        return success(detailVO);
    }

    @GetMapping("/todo/record")
    @IgnoreAuth
    @ControllerMethod("查询跟进历史记录")
    public Message<List<FollowRecordVO>> todoRecord(@NotNull(message = "跟进任务id不能为空") final Long taskId) {
        return success(followBizService.todoRecord(taskId));
    }

    @GetMapping("/sms/template")
    @IgnoreAuth
    @ControllerMethod("查询短信模板")
    public Message<String> getSmsTemplate(@CurrentUser LoginAuthBean currentUser, @NotNull(message = "跟进类型不能为空") final Integer type) {
        Message<String> message = success();
        message.setData(followBizService.smsTemplate(currentUser.getUserId(), type));
        return message;
    }

    @PostMapping("/defeat")
    @ControllerMethod("主动战败")
    public Message<Void> defeat(@CurrentUser LoginAuthBean currentUser,
                                final Long id,
                                final String reason,
                                final Long taskId) {
        if (Objects.isNull(id)) {
            followBizService.defeat(taskId, currentUser, reason);
        } else {
            followBizService.defeat(currentUser, reason, id, null);
        }
        return success();
    }

    @PostMapping("/todo/complete")
    @ControllerMethod("完成跟进待办")
    public Message<Void> complete(@CurrentUser LoginAuthBean currentUser,
                                  @NotNull(message = "跟进记录id不能为空") final Long id,
                                  @NotNull(message = "跟进类型不能为空") final Integer type) {
        FollowTypeEnum typeEnum = FollowTypeEnum.ofValue(type);
        BV.notNull(typeEnum, "跟进类型不正确");
        followBizService.completeRecord(id, typeEnum, currentUser);
        return success();
    }

    @PostMapping("/todo/upload")
    @ControllerMethod("上传跟进凭证")
    public Message<Void> upload(@CurrentUser LoginAuthBean currentUser, @RequestBody @Valid final FollowAttachmentDTO dto) {
        BV.notNull(dto.getFollowType(), "跟进类型不正确");
        followBizService.uploadAtt(dto, currentUser);
        return success();
    }

    @GetMapping("/customer/clue/list")
    @IgnoreAuth
    @ControllerMethod("查询档案跟进线索历史列表")
    public Message<List<CustomerClueHistoryVO>> clueHistory(@CurrentUser LoginAuthBean currentUser,
                                                            @NotNull(message = "档案id不能为空") final Long customerId) {
        List<CustomerClueHistoryVO> list = followBizService.clueHistoryList(currentUser.getGroupId(), customerId);
        return success(list);
    }

    @GetMapping("/customer/clue/record")
    @IgnoreAuth
    @ControllerMethod("查询跟进线索的跟进历史记录")
    public Message<List<FollowRecordVO>> clueRecord(@NotNull(message = "线索id不能为空") final Long clueId, @NotNull(message = "跟进类型不能为空") final Integer type) {
        return success(followBizService.queryHistoryByClueId(clueId, type));
    }
}