ProjectGroupController.java 11 KB
package cn.com.glsx.dj.strategy.controller;

import cn.com.glsx.dj.strategy.dto.projectgroup.*;
import cn.com.glsx.dj.strategy.remote.ProjectGroupRemote;
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;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 项目组管理控制器。
 */
@Slf4j
@ServiceMethodBean(version = "1.0.0", needInSession = NeedInSessionType.YES)
@Api("项目组管理")
public class ProjectGroupController {

    @Autowired
    private ProjectGroupRemote projectGroupRemote;

    @ApiOperation("项目组分页列表")
    @ServiceMethod(method = "dj.api.strategy.project.group.list", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    public RopResponse<RpcPagination<ProjectGroupListDTO>> pageProjectGroup(ProjectGroupQueryRequest request) {
        try {
            RpcPagination<ProjectGroupQueryDTO> pagination = CommonUtil.getRpcPagination(ProjectGroupQueryDTO.class);
            RpcResponse<RpcPagination<ProjectGroupListDTO>> response = projectGroupRemote.pageProjectGroup(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.project.group.list exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询项目组详情")
    @ServiceMethod(method = "dj.api.strategy.project.group.detail")
    public RopResponse<ProjectGroupDetailDTO> getProjectGroupDetail(ProjectGroupIdRequest request) {
        try {
            ProjectGroupIdDTO dto = CommonUtil.convertRequest(ProjectGroupIdDTO.class);
            RpcResponse<ProjectGroupDetailDTO> response = projectGroupRemote.getProjectGroupDetail(dto);
            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.project.group.detail rpcServiceException", e);
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.detail exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("保存项目组(支持编辑)")
    @ServiceMethod(method = "dj.api.strategy.project.group.save")
    public RopResponse<Boolean> saveProjectGroup(ProjectGroupSaveRequest request) {
        try {
            ProjectGroupSaveDTO dto = CommonUtil.convertRequest(ProjectGroupSaveDTO.class);
            dto.setOperator(resolveOperator());
            RpcResponse<Boolean> response = projectGroupRemote.saveProjectGroup(dto);
            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.project.group.save rpcServiceException", e);
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.save exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("删除项目组")
    @ServiceMethod(method = "dj.api.strategy.project.group.delete")
    public RopResponse<Boolean> deleteProjectGroup(ProjectGroupIdRequest request) {
        try {
            ProjectGroupIdDTO dto = CommonUtil.convertRequest(ProjectGroupIdDTO.class);
            dto.setOperator(resolveOperator());
            RpcResponse<Boolean> response = projectGroupRemote.deleteProjectGroup(dto);
            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.project.group.delete rpcServiceException", e);
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.delete exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("项目组门店分页列表")
    @ServiceMethod(method = "dj.api.strategy.project.group.store.list", needInSession = NeedInSessionType.NO, ignoreSign = IgnoreSignType.YES)
    public RopResponse<RpcPagination<ProjectGroupStoreDTO>> pageProjectGroupStore(ProjectGroupStoreQueryRequest request) {
        try {
            RpcPagination<ProjectGroupStoreQueryDTO> pagination = CommonUtil.getRpcPagination(ProjectGroupStoreQueryDTO.class);
            RpcResponse<RpcPagination<ProjectGroupStoreDTO>> response = projectGroupRemote.pageProjectGroupStore(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.project.group.store.list exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    /* 异步导入项目组门店的接口放在rop-dj-smartcarlife */
    @ApiOperation("批量新增项目组门店")
    @ServiceMethod(method = "dj.api.strategy.project.group.store.add")
    public RopResponse<Boolean> addProjectGroupStores(ProjectGroupStoreBatchAddRequest request) {
        try {
            ProjectGroupStoreBatchAddDTO dto = CommonUtil.convertRequest(ProjectGroupStoreBatchAddDTO.class);
            dto.setOperator(resolveOperator());
            RpcResponse<Boolean> response = projectGroupRemote.addProjectGroupStores(dto);
            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.project.group.store.add rpcServiceException", e);
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.store.add exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("删除项目组门店")
    @ServiceMethod(method = "dj.api.strategy.project.group.store.delete")
    public RopResponse<Boolean> deleteProjectGroupStore(ProjectGroupStoreDeleteRequest request) {
        try {
            ProjectGroupStoreDeleteDTO dto = CommonUtil.convertRequest(ProjectGroupStoreDeleteDTO.class);
            dto.setOperator(resolveOperator());
            RpcResponse<Boolean> response = projectGroupRemote.deleteProjectGroupStore(dto);
            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.project.group.store.delete rpcServiceException", e);
            return RopResponse.error(e);
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.store.delete exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询预警类型列表")
    @ServiceMethod(method = "dj.api.strategy.project.group.warning.meta.types")
    public RopResponse<List<WarningTypeOptionDTO>> listWarningTypes(ProjectGroupQueryRequest request) {
        try {
            RpcResponse<List<WarningTypeOptionDTO>> response = projectGroupRemote.listWarningTypes();
            if (response.hasError()) {
                log.error(response.getMessage());
                return RopResponse.error(response.getError(), response.getMessage());
            }
            return RopResponse.success(response.getResult().stream()
                    .filter(item -> Objects.equals(item.getShowType(), 0)).collect(Collectors.toList()));
        } catch (Exception e) {
            log.error("dj.api.strategy.project.group.warning.meta.types exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询应用业务列表")
    @ServiceMethod(method = "dj.api.strategy.project.group.warning.meta.bizs")
    public RopResponse<List<BizOptionDTO>> listBizs(ProjectGroupQueryRequest request) {
        try {
            RpcResponse<List<BizOptionDTO>> response = projectGroupRemote.listBizs();
            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.project.group.warning.meta.bizs exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    @ApiOperation("查询指标列表")
    @ServiceMethod(method = "dj.api.strategy.project.group.warning.meta.metrics")
    public RopResponse<List<MetricOptionDTO>> listMetrics(ProjectGroupMetricQueryRequest request) {
        try {
            ProjectGroupMetricQueryDTO dto = CommonUtil.convertRequest(ProjectGroupMetricQueryDTO.class);
            RpcResponse<List<MetricOptionDTO>> response = projectGroupRemote.listMetrics(dto);
            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.project.group.warning.meta.metrics exception", e);
            return RopResponse.error(e.getMessage());
        }
    }

    /**
     * 获取当前操作人。
     *
     * @return 操作人
     */
    private String resolveOperator() {
        String userName = CommonUtil.getUserName();
        return userName == null ? CommonUtil.getAccountName() : userName;
    }
}