package cn.estsh.i3plus.core.apiservice.controller;

import cn.estsh.i3plus.icloud.core.sdk.ICoreDemoCloud;
import cn.estsh.i3plus.icloud.wms.sdk.IWmsDemoCloud;
import cn.estsh.i3plus.pojo.base.bean.BaseModelBean;
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
import cn.estsh.i3plus.pojo.platform.bean.SysRole;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.Map;

@RestController
@RequestMapping("/impp")
@Api(description="异常服务测试")
public class DemoExceptionController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DemoExceptionController.class);
    @GetMapping(value="/test-exception")
    @ApiOperation(value="测试异常")
    public ResultBean testException(int type) throws Exception{
        try{
            if(type == 1){
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
                        .setErrorCode(ImppExceptionEnum.SYSTEM_EXCEPTION.getCode())
                        .setErrorDetail("手动抛出异常")
                        .build();
            }else if(type == 2){
                throw new SQLException("测试数据库异常");
            }else {
                return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
            }
        }catch(ImppBusiException busExcep){
            LOGGER.error(busExcep.getErrorMsg() + "：{}",busExcep.getErrorDetail(),busExcep);
            return ResultBean.fail(busExcep);
        }
    }
}
