BiMatterController.java 11.3 KB
package cn.com.glsx.dj.controller;

import cn.com.glsx.dj.converter.BiMatterConvert;
import cn.com.glsx.dj.peanalysis.dto.analysis.*;
import cn.com.glsx.dj.peanalysis.enums.BiErrorEnum;
import cn.com.glsx.dj.peanalysis.remote.BiAnalyseBackgroundRemote;
import cn.com.glsx.dj.request.biAnalyse.*;
import cn.com.glsx.dj.response.LoginUserInfoResponse;
import cn.com.glsx.dj.response.bianalysis.MerchantBiMatterResp;
import cn.com.glsx.dj.response.bianalysis.MerchantOperatorDetailResp;
import cn.com.glsx.dj.response.bianalysis.MyMerchantBiMatterResp;
import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import cn.hutool.core.bean.BeanUtil;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Optional;

/**
 * BI事项处理控制器
 * @author yangwei
 * @version 1.0
 * @since 2025/12/22 11:12
 */
@Slf4j
@Api("BI事项处理控制器")
@RequiredArgsConstructor
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
public class BiMatterController {

    private final BiMatterConvert biMatterConvert;
    private final BiAnalyseBackgroundRemote biAnalyseBackgroundRemote;

    @ApiOperation("bi事项管理-新增待跟进事项")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.merchant.bi.matter.add", needInSession = NeedInSessionType.YES)
    public RopResponse<Boolean> merchantBiMatterAdd(MerchantBiMatterAddReq request) {
        try {
            LoginUserInfoResponse loginUserDTO = Optional.ofNullable(CommonUtil.getLoginUserInfo())
                    .orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST));

            MerchantBiMatterAddDTO merchantBiMatterAddDTO = BeanUtil.copyProperties(request, MerchantBiMatterAddDTO.class);
            merchantBiMatterAddDTO.setCreator(loginUserDTO.getName());
            merchantBiMatterAddDTO.setCreatorUnique(loginUserDTO.getUuid());
            RpcResponse<Boolean> response = biAnalyseBackgroundRemote.merchantBiMatterAdd(merchantBiMatterAddDTO);
            if (response.isFailed()) {
                throw new RpcServiceException(response.getError(), response.getMessage());
            }

            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.matter.add occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.matter.add error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), "业务异常");
        }
    }

    @ApiOperation("BI-事项管理处理")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.merchant.bi.matter.handle", needInSession = NeedInSessionType.YES)
    public RopResponse<Boolean> merchantBiMatterHandle(MerchantBiMatterHandleReq request) {
        try {
            LoginUserInfoResponse loginUserDTO = Optional.ofNullable(CommonUtil.getLoginUserInfo())
                    .orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST));

            String userName = loginUserDTO.getName();
            String uuid = loginUserDTO.getUuid();

            MerchantBiMatterHandleDTO merchantBiMatterHandleDTO = BeanUtil.copyProperties(request, MerchantBiMatterHandleDTO.class);
            merchantBiMatterHandleDTO.setOperator(userName);
            merchantBiMatterHandleDTO.setOperatorUniqueKey(uuid);
            RpcResponse<Boolean> rpcResponse = biAnalyseBackgroundRemote.merchantBiMatterHandle(merchantBiMatterHandleDTO);
            if (rpcResponse.isFailed()) {
                throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
            }

            return RopResponse.success(rpcResponse.getResult());
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.matter.handle occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.matter.handle occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), DefaultErrorEnum.SERVICE_ERROR.getDisplayName());

        }
    }

    @ApiOperation("BI-获取指定店铺的区域运营与线上运营")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.merchant.bi.operator", needInSession = NeedInSessionType.YES)
    public RopResponse<MerchantOperatorDetailResp> findMerchantOperator(MerchantOperatorReq request) {
        try {
            MerchantOperatorDTO merchantOperatorDTO = BeanUtil.copyProperties(request, MerchantOperatorDTO.class);
            RpcResponse<MerchantOperatorDetailDTO> rpcResponse = biAnalyseBackgroundRemote.findMerchantOperator(merchantOperatorDTO);
            if (rpcResponse.isFailed()) {
                throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
            }

            MerchantOperatorDetailDTO merchantOperatorDetailDTO = rpcResponse.getResult();
            MerchantOperatorDetailResp merchantOperatorDetailResp = BeanUtil.copyProperties(merchantOperatorDetailDTO, MerchantOperatorDetailResp.class);
            return RopResponse.success(merchantOperatorDetailResp);
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.operator occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.operator occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), DefaultErrorEnum.SERVICE_ERROR.getDisplayName());
        }
    }

    @ApiOperation("BI-我的事项列表")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.my.merchant.bi.matter.page", needInSession = NeedInSessionType.YES)
    public RopResponse<RpcPagination<MyMerchantBiMatterResp>> myMerchantBiMatterPage(MyMerchantBiMatterQryReq request) {
        try {
            LoginUserInfoResponse loginUserDTO = Optional.ofNullable(CommonUtil.getLoginUserInfo())
                    .orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST));
            String uuid = loginUserDTO.getUuid();

            RpcPagination<MyMerchantBiMatterQryDTO> rpcPagination = CommonUtil.getRpcPagination(MyMerchantBiMatterQryDTO.class);
            MyMerchantBiMatterQryDTO condition = BeanUtil.copyProperties(request, MyMerchantBiMatterQryDTO.class);
            condition.setOperator(uuid);
            rpcPagination.setCondition(condition);

            RpcResponse<RpcPagination<MyMerchantBiMatterDTO>> rpcPaginationRpcResponse = biAnalyseBackgroundRemote.myMerchantBiMatterPage(rpcPagination);
            if (rpcPaginationRpcResponse.isFailed()) {
                throw new RpcServiceException(rpcPaginationRpcResponse.getError(), rpcPaginationRpcResponse.getMessage());
            }

            RpcPagination<MyMerchantBiMatterDTO> rpcPaginationDTO = rpcPaginationRpcResponse.getResult();
            RpcPagination<MyMerchantBiMatterResp> resultPage = biMatterConvert.MyMerchantBiMatterDto2ResponsePage(rpcPaginationDTO);
            return RopResponse.success(resultPage);
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.my.merchant.bi.matter.page occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.my.merchant.bi.matter.page occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), DefaultErrorEnum.SERVICE_ERROR.getDisplayName());
        }
    }

    @ApiOperation("BI-事项管理详情")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.merchant.bi.operator.detail", needInSession = NeedInSessionType.YES)
    public RopResponse<MerchantBiMatterResp> biMatterOperatorDetail(MerchantBiMatterSingleIdReq request) {
        try {
            MerchantBiMatterSingleIdDTO merchantBiMatterSingleIdDTO = BeanUtil.copyProperties(request, MerchantBiMatterSingleIdDTO.class);
            RpcResponse<MerchantBiMatterDTO> rpcResponse = biAnalyseBackgroundRemote.biMatterOperatorDetail(merchantBiMatterSingleIdDTO);
            if (rpcResponse.isFailed()) {
                throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
            }

            MerchantBiMatterDTO merchantBiMatterDTO = rpcResponse.getResult();
            MerchantBiMatterResp merchantBiMatterResp = BeanUtil.copyProperties(merchantBiMatterDTO, MerchantBiMatterResp.class);
            return RopResponse.success(merchantBiMatterResp);
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.operator.detail occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.bi.operator.detail occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), DefaultErrorEnum.SERVICE_ERROR.getDisplayName());
        }
    }

    @ApiOperation("BI-我的事项未处理数量")
    @ServiceMethod(method = "dj.api.smartcarlife.business.analysis.merchant.unhandle.count", needInSession = NeedInSessionType.YES)
    public RopResponse<Integer> getMyBiMatterUnHandleCount(AbstractRopRequest request) {
        try {
            LoginUserInfoResponse loginUserDTO = Optional.ofNullable(CommonUtil.getLoginUserInfo())
                    .orElseThrow(() -> new RpcServiceException(BiErrorEnum.LOGIN_USER_NOT_EXIST));
            String uuid = loginUserDTO.getUuid();

            RpcResponse<Integer> rpcResponse = biAnalyseBackgroundRemote.getMyBiMatterUnHandleCount(uuid);
            if (rpcResponse.isFailed()) {
                throw new RpcServiceException(rpcResponse.getError(), rpcResponse.getMessage());
            }

            Integer unHandleCount = rpcResponse.getResult();
            return RopResponse.success(unHandleCount);
        } catch (RpcServiceException e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.unhandle.count occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), e.getMessage());
        } catch (Exception e) {
            log.info("dj.api.smartcarlife.business.analysis.merchant.unhandle.count occur error!", e);
            return RopResponse.error(DefaultErrorEnum.SERVER_ERROR.getValue(), DefaultErrorEnum.SERVICE_ERROR.getDisplayName());
        }
    }
}