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

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.vo.PostUserVO;
import cn.fw.valhalla.service.bus.CommonService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

import static cn.fw.common.web.util.ExceptionHandler.handleException;
import static cn.fw.common.web.util.ResultBuilder.failureWithMessage;
import static cn.fw.common.web.util.ResultBuilder.success;
import static cn.fw.valhalla.common.constant.MessageStr.SAVE_FAILURE;

/**
 * @author : kurisu
 * @className : CommonController
 * @description : 公共接口
 * @date: 2020-10-22 11:06
 */
@Slf4j
@RestController
@Authorization(AuthType.APP)
@Validated
@IgnoreAuth
@RequestMapping("/app/common")
public class CommonController {
    private final CommonService commonService;

    @Autowired
    public CommonController(final CommonService commonService) {
        this.commonService = commonService;
    }

    @GetMapping("/staff/list")
    public Message<List<PostUserVO>> list(@NotNull(message = "服务站ID不能为空") final Long shopId,
                                          @NotNull(message = "跟进类型不能为空") final Integer type) {
        final String msg = "查询跟进人员[app/common/staff/list]";
        try {
            log.info("{}: param[shopId: {} type: {}]", msg, shopId, type);
            List<PostUserVO> list = commonService.getUsers(shopId, type);
            return success(list, data -> log.info("{}", data));
        } catch (Exception ex) {
            handleException(ex, e -> log.error("{}失败:param[shopId: {} type: {}]", msg, shopId, type, e));
            return failureWithMessage(SAVE_FAILURE);
        }
    }
}