StrategyInfoController.java 16.5 KB
package cn.com.glsx.dj.strategy.controller;

import cn.com.glsx.dj.mindworkplate.dto.ConversationBatchDTO;
import cn.com.glsx.dj.mindworkplate.model.warning.LearningEffectAnalysisDTO;
import cn.com.glsx.dj.mindworkplate.model.warning.LearningEffectAnalysisRequest;
import cn.com.glsx.dj.mindworkplate.remote.MonitoringRemote;
import cn.com.glsx.dj.smartcarlife.dto.LoginUserDTO;
import cn.com.glsx.dj.smartcarlife.dto.StaffInfoDTO;
import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.dj.strategy.dto.BatchInsertStrategyInfo;
import cn.com.glsx.dj.strategy.dto.MerchantBusinessInfo;
import cn.com.glsx.dj.strategy.dto.MerchantBusinessOverview;
import cn.com.glsx.dj.strategy.dto.ShopMerchantOperatorReqDTO;
import cn.com.glsx.dj.strategy.dto.ShopMerchantOperatorRespDTO;
import cn.com.glsx.dj.strategy.enums.StrategyDataSourceEnum;
import cn.com.glsx.dj.strategy.model.StrategyInfo;
import cn.com.glsx.dj.strategy.remote.StrategyInfoRemote;
import cn.com.glsx.dj.strategy.request.*;
import cn.com.glsx.dj.strategy.uitl.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.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse;
import com.rop.annotation.IgnoreSignType;
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.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
@Api("策略中心-策略信息")
public class StrategyInfoController {

    @Autowired
    private StrategyInfoRemote strategyInfoRemote;

    @Autowired
    private StaffInfoRemote staffInfoRemote;

    @Autowired
    private MonitoringRemote monitoringRemote;


    @ApiOperation("策略分页列表")
    @ServiceMethod(method = "dj.api.strategy.info.page", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    public RopResponse<RpcPagination<StrategyInfo>> strategyInfoPage(StaffInfoPageRequest request) {
        try {
            RpcPagination<StrategyInfo> pagination = CommonUtil.getRpcPagination(StrategyInfo.class);
            RpcResponse<RpcPagination<StrategyInfo>> response = strategyInfoRemote.selectStrategyInfoPage(pagination);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (Exception e) {
            log.error("=====dj.api.strategy.info.page exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("创建策略")
    @ServiceMethod(method = "dj.api.strategy.info.batch.create")
    public RopResponse<Boolean> batchCreate(BatchInsertStrategyInfoRequest request) {
        try {
            BatchInsertStrategyInfo batchInsertStrategyInfo = CommonUtil.convertRequest(BatchInsertStrategyInfo.class);
            LoginUserDTO loginUser = CommonUtil.getLoginUser();
            //String accountName = loginUser.getLoginAccout();
            batchInsertStrategyInfo.setCreatedBy(loginUser.getUserName());
            batchInsertStrategyInfo.setCreatedUUid(loginUser.getUuid());
            batchInsertStrategyInfo.getStrategyInfo().setDataSource(StrategyDataSourceEnum.STRATEGY_CENTER.getValue());
            RpcResponse<Boolean> response = strategyInfoRemote.batchCreate(batchInsertStrategyInfo);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.info.batch.create rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.info.batch.create exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("删除策略")
    @ServiceMethod(method = "dj.api.strategy.info.delete")
    public RopResponse<Boolean> delete(DeleteStrategyRequest request) {
        try {
            String accountName = CommonUtil.getAccountName();
            StrategyInfo strategyInfo = CommonUtil.convertRequest(StrategyInfo.class);
            strategyInfo.setUpdatedBy(accountName);
            RpcResponse<Boolean> response = strategyInfoRemote.delete(strategyInfo);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.info.delete rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.info.delete exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询驻店员工/区域运营/飞行督导列表")
    @ServiceMethod(method = "dj.api.strategy.staff.page")
    public RopResponse<RpcPagination<StaffInfoDTO>> listStaffWithPage(StaffInfoSearchRequest request) {
        try {
            RpcPagination<StaffInfoDTO> pagination = CommonUtil.getRpcPagination(StaffInfoDTO.class);
            RpcResponse<RpcPagination<StaffInfoDTO>> response = staffInfoRemote.listMultipleRolesStaffWithPage(pagination);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.staff.page rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.staff.page exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询驻店员工(已按手机号去重)")
    @ServiceMethod(method = "dj.api.strategy.staff.page.distinct.phone")
    public RopResponse<RpcPagination<StaffInfoDTO>> listStaffWithPageDistinctPhone(StaffInfoSearchRequest request) {
        try {
            RpcPagination<StaffInfoDTO> pagination = CommonUtil.getRpcPagination(StaffInfoDTO.class);
            RpcResponse<RpcPagination<StaffInfoDTO>> response = staffInfoRemote.listStaffWithPageDistinctPhone(pagination);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.staff.page.distinct.phone rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.staff.page.distinct.phone exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询门店展业时间线")
    @ServiceMethod(method = "dj.api.strategy.merchant.timeline")
    public RopResponse<MerchantBusinessOverview> listStrategyMerchantTimeline(MerchantBusinessRequest request) {
        try {
            MerchantBusinessInfo merchantBusinessInfo = CommonUtil.convertRequest(MerchantBusinessInfo.class);
            RpcResponse<MerchantBusinessOverview> response = strategyInfoRemote.listStrategyMerchantTimeline(merchantBusinessInfo);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }

            /*MerchantBusinessOverview result = response.getResult();
            List<StrategyMerchantTimelineTest> collect = result.getTimelineList().stream().map(el -> {
                StrategyMerchantTimelineTest strategyMerchantTimelineTest = BeanUtil.copyProperties(el, StrategyMerchantTimelineTest.class);
                strategyMerchantTimelineTest.setNodeDateStr(DateUtil.format(strategyMerchantTimelineTest.getNodeDate(), DatePattern.NORM_DATE_PATTERN));
                strategyMerchantTimelineTest.setNoteTypeStr(MerchantNodeTypeEnum.getDisplayName(el.getNodeType()));
                return strategyMerchantTimelineTest;
            }).collect(Collectors.toList());
            log.info("时间线{}", JSONUtil.toJsonStr(collect));*/
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.merchant.timeline rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.merchant.timeline exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("停止门店展业")
    @ServiceMethod(method = "dj.api.strategy.merchant.stop.business")
    public RopResponse<Boolean> stopMerchantBusiness(MerchantBusinessRequest request) {
        try {
            MerchantBusinessInfo merchantBusinessInfo = CommonUtil.convertRequest(MerchantBusinessInfo.class);
            String accountName = CommonUtil.getAccountName();
            merchantBusinessInfo.setUpdatedBy(accountName);
            RpcResponse<Boolean> response = strategyInfoRemote.stopMerchantBusiness(merchantBusinessInfo);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.merchant.stop.business rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.merchant.stop.business exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }


    @ApiOperation("查询策略详情(学习、课程、带教申请、协同类策略:人员更换评估/商务政策更新评估/多品类拓张/流量问题改善)")
    @ServiceMethod(method = "dj.api.strategy.info.queryStrategyInfoById",needInSession = NeedInSessionType.YES)
    public RopResponse<StrategyInfo> queryStrategyInfoById(StrategyInfoQueryRequest request) {
        try {
            RpcResponse<StrategyInfo> response = strategyInfoRemote.queryStrategyInfoById(request.getId());
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.info.queryStrategyInfoById rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.info.queryStrategyInfoById exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("策略中心-策略详细-查询录音记录概览(学习前后传状态)")
    @ServiceMethod(method = "dj.api.strategy.monitor.findRecordStaticByCondition", needInSession = NeedInSessionType.YES)
    public RopResponse<ConversationBatchDTO> findRecordStaticByCondition(
        LearningEffectAnalysisRecordRopRequest req) {
        try {
            LearningEffectAnalysisRequest request = CommonUtil.convertRequest(LearningEffectAnalysisRequest.class);

            RpcResponse<ConversationBatchDTO> response = monitoringRemote.findRecordStaticByCondition(request);
            if (response.isSuccess()) {
                return RopResponse.success(response.getResult());
            }
            return RopResponse.error(response.getMessage());
        } catch (Exception e) {
            log.error("接口异常", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("策略中心-策略详细-查询录音记录")
    @ServiceMethod(method = "dj.api.strategy.monitor.getRecordPageListByCondition", needInSession = NeedInSessionType.YES)
    public RopResponse<RpcPagination<ConversationBatchDTO>> getRecordPageListByCondition(
        LearningEffectAnalysisRecordPageRopRequest request) {
        try {
            RpcPagination<LearningEffectAnalysisRequest> pagination = CommonUtil.getRpcPagination(LearningEffectAnalysisRequest.class);

            RpcResponse<RpcPagination<ConversationBatchDTO>> response = monitoringRemote.getRecordPageListByCondition(pagination);
            if (response.isSuccess()) {
                return RopResponse.success(response.getResult());
            }
            return RopResponse.error(response.getMessage());
        } catch (Exception e) {
            log.error("接口异常", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("策略中心-选择策略录音记录")
    @ServiceMethod(method = "dj.api.strategy.monitor.getRecordAllPageListByCondition", needInSession = NeedInSessionType.YES)
    public RopResponse<RpcPagination<ConversationBatchDTO>> getRecordAllPageListByCondition(LearningRecordRopRequest req) {
        try {

            RpcPagination<LearningEffectAnalysisRequest> pagination = CommonUtil.getRpcPagination(LearningEffectAnalysisRequest.class);

            RpcResponse<RpcPagination<ConversationBatchDTO>> response = monitoringRemote.getRecordPageListByCondition(pagination);
            if (response.isSuccess()) {
                return RopResponse.success(response.getResult());
            }
            return RopResponse.error(response.getMessage());
        } catch (Exception e) {
            log.error("接口异常", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("策略中心-策略详细查询学习前后的指标")
    @ServiceMethod(method = "dj.api.strategy.monitor.findLearningEffectAnalysis", needInSession = NeedInSessionType.YES)
    public RopResponse<LearningEffectAnalysisDTO> findLearningEffectAnalysis(LearningEffectAnalysisZbRopRequest req) {
        try {
            LearningEffectAnalysisRequest request = CommonUtil.convertRequest(LearningEffectAnalysisRequest.class);

            RpcResponse<LearningEffectAnalysisDTO> response = monitoringRemote.findLearningEffectAnalysis(request);
            if (response.isSuccess()) {
                return RopResponse.success(response.getResult());
            }
            return RopResponse.error(response.getMessage());
        } catch (Exception e) {
            log.error("接口异常", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询当前门店+业务下的全部区域运营")
    @ServiceMethod(method = "dj.api.strategy.shop.merchant.operators", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    public RopResponse<List<ShopMerchantOperatorRespDTO>> listShopMerchantOperators(ShopMerchantOperatorRequest request) {
        try {
            ShopMerchantOperatorReqDTO reqDTO = CommonUtil.convertRequest(ShopMerchantOperatorReqDTO.class);
            RpcResponse<List<ShopMerchantOperatorRespDTO>> response = strategyInfoRemote.listShopMerchantOperators(reqDTO);
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult());
        } catch (RpcServiceException e) {
            log.error("=====dj.api.strategy.shop.merchant.operators rpcServiceException:{}", e.getMessage());
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("=====dj.api.strategy.shop.merchant.operators exception:{}", e.getMessage(), e);
            return RopResponse.error(e.getMessage());
        }
    }
}