package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.base;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IEnumPcnDataService;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "MES_PCN枚举数据")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/enum-data")
public class EnumPcnDataController {
    @Autowired
    private IEnumPcnDataService enumPcnDataService;

    /*************MES_PCN 枚举信息*****start***********/
    @GetMapping(value = "/enumlist")
    @ApiOperation(value = "获取MES_PCN系统所有枚举")
    public ResultBean enumlist(@RequestParam(name = "enumName", required = false) String enumName) {
        List<Map<String, Object>> mapList;
        Map<String, Object> map;
        try {
            if (StringUtils.isEmpty(enumName)) {
                mapList = enumPcnDataService.getAllMesEnums();
                return ResultBean.success("查询成功")
                        .setResultList(mapList)
                        .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
            } else {
                map = enumPcnDataService.doGetMesEnumByEnumName(enumName);
                return ResultBean.success("查询成功")
                        .setResultObject(map)
                        .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
            }

        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
    /*************MES_PCN 枚举信息*****end***********/
}
