package cn.com.ctop.performanceappraisal.service.impl;

import cn.com.ctop.common.module.utils.ResultMapUtils;
import cn.com.ctop.common.module.utils.StatusCode;
import cn.com.ctop.performanceappraisal.entity.OptimizerConfig;
import cn.com.ctop.performanceappraisal.entity.OptimizerRoleInfo;
import cn.com.ctop.performanceappraisal.mapper.OptimizerRoleInfoMapper;
import cn.com.ctop.performanceappraisal.service.IOptimizerConfigService;
import cn.com.ctop.performanceappraisal.service.IOptimizerRoleInfoService;
import cn.com.ctop.performanceappraisal.service.IPerformanceService;
import cn.com.ctop.performanceappraisal.vo.OptimizerCostDetailVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 优化师角色关系表
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-12-17
 */
@Service
public class OptimizerRoleInfoServiceImpl extends ServiceImpl<OptimizerRoleInfoMapper, OptimizerRoleInfo> implements IOptimizerRoleInfoService {
    @Autowired
    private IPerformanceService performanceService;
    @Autowired
    private IOptimizerConfigService optimizerConfigService;

    @Override
    public Map<String, Object> getManagerDetail(String appType, String orgCode) {
        Map<String, Object> result = new HashMap<>();
        try {
            //1：查询媒体任务
            OptimizerCostDetailVO totalCostVo = performanceService.getOptimizerTotalCost(appType);
            OptimizerConfig config = optimizerConfigService.getEnabledConfigByMediaType(appType, orgCode);
            //查询经理所属人员任务完成信息列表
            result = performanceService.getMemberPerformanceByUserId(config, totalCostVo);
            ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS.getCode());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            ResultMapUtils.setResultMap(result, StatusCode.COMMON_SERVER_ERROR.getCode());
            return result;
        }
    }
}
