package com.persagy.proxy.calculation.controller;

import cn.hutool.core.util.StrUtil;
import com.persagy.dmp.common.exception.BusinessException;
import com.persagy.proxy.adm.constant.AdmCommonConstant;
import com.persagy.proxy.adm.constant.AdmRelationTypeEnum;
import com.persagy.proxy.adm.constant.BusinessErrorRwdCode;
import com.persagy.proxy.adm.request.AdmResponse;
import com.persagy.proxy.adm.utils.AdmContextUtil;
import com.persagy.proxy.calculation.service.AdmCalcSpecialService;
import com.persagy.proxy.common.entity.InstanceUrlParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/***
 * Description: 机电管网系统关系计算
 * @author : lijie
 * @date :2021/9/14 23:15
 * Update By lijie 2021/9/14 23:15
 */
@RestController
@RequestMapping("/calc_special/")
@RequiredArgsConstructor
public class AdmCalcSpecialController {

    private final AdmCalcSpecialService admCalcSpecialService;

    /***
     * Description: 管网系统设备分块  +  计算流向
     * @param relationType : 关系类型
     * @return : com.persagy.proxy.adm.request.AdmResponse
     * @author : lijie
     * @date :2021/9/29 11:12
     * Update By lijie 2021/9/29 11:12
     */
    @PostMapping("sys-block")
    public AdmResponse sysBolck(@RequestParam("relationType") String relationType) throws Exception {
        // 组装上下文条件
        InstanceUrlParam context = AdmContextUtil.toDmpContext();
        Map<String, AdmRelationTypeEnum> relationTypeMap = AdmRelationTypeEnum.getRelationTypeMap();
        if (!relationTypeMap.containsKey(relationType)){
            throw new BusinessException(BusinessErrorRwdCode.A7201.getCode(),BusinessErrorRwdCode.A7201.getDesc());
        }
        return admCalcSpecialService.sysBlock(context, relationTypeMap.get(relationType));
    }
    /***
     * Description: 管网计算
     * @return : com.persagy.proxy.adm.request.AdmResponse
     * @author : lijie
     * @date :2021/9/29 11:58
     * Update By lijie 2021/9/29 11:58
     */
    @GetMapping("calcNetworks")
    public AdmResponse calcNetworks() throws Exception {
        // 组装上下文条件
        InstanceUrlParam context = AdmContextUtil.toDmpContext();
        return admCalcSpecialService.calcNetworks(context);
    }


}
