forked from I3-YF/i3plus-mes-yfai
新增 枚举
parent
eccb916cf7
commit
3059216f3c
@ -0,0 +1,18 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.api.base;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface IMesEnumExtService {
|
||||||
|
|
||||||
|
@ApiOperation("获取所有mes枚举")
|
||||||
|
List<Map<String, Object>> getAllMesEnums();
|
||||||
|
|
||||||
|
@ApiOperation("根据枚举名获取枚举")
|
||||||
|
Map<String, Object> doGetMesEnumByEnumName(String enumName);
|
||||||
|
|
||||||
|
@ApiOperation("通过class获取枚举")
|
||||||
|
Map<String, Object> getEnumByClazzEnum(String enumName, Class clazz);
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.apiservice.controller.base;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.api.base.IMesEnumExtService;
|
||||||
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
||||||
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
||||||
|
import cn.estsh.impp.framework.base.controller.BaseCommonController;
|
||||||
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 广东麦格纳-通用功能服务
|
||||||
|
* @CreateDate: 2021/6/28 下午2:54
|
||||||
|
* @Author: simon.song
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@Api(description = "通用功能服务")
|
||||||
|
@RequestMapping(CommonConstWords.BASE_URL_MES + "/common")
|
||||||
|
public class MesCommonController extends BaseCommonController {
|
||||||
|
@Autowired
|
||||||
|
private IMesEnumExtService enumService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping(value = "/enumlist")
|
||||||
|
@ApiOperation(value = "获取MES系统所有枚举")
|
||||||
|
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 = enumService.getAllMesEnums();
|
||||||
|
return ResultBean.success("查询成功")
|
||||||
|
.setResultList(mapList)
|
||||||
|
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||||
|
} else {
|
||||||
|
map = enumService.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
|
||||||
|
|
||||||
|
import cn.estsh.i3plus.ext.mes.api.base.IMesEnumExtService;
|
||||||
|
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
|
||||||
|
import cn.estsh.i3plus.mes.apiservice.util.EnumUtil;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description:
|
||||||
|
* @CreateDate: 2021/7/6 下午7:09
|
||||||
|
* @Author: simon.song
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class MesEnumExtService implements IMesEnumExtService {
|
||||||
|
@Override
|
||||||
|
public List<Map<String, Object>> getAllMesEnums() {
|
||||||
|
Class innerClazz[] = MesExtEnumUtil.class.getDeclaredClasses();// 获取常量类中的所有内部类
|
||||||
|
|
||||||
|
List<Map<String, Object>> enumList = new ArrayList<>();// 所有枚举
|
||||||
|
Map<String, Object> enumMap;// 枚举类
|
||||||
|
|
||||||
|
for (Class clazz : innerClazz) {
|
||||||
|
enumMap = getEnumByClazzEnum(clazz.getSimpleName(), MesExtEnumUtil.class);
|
||||||
|
enumList.add(enumMap);
|
||||||
|
}
|
||||||
|
return enumList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> doGetMesEnumByEnumName(String enumName) {
|
||||||
|
return getEnumByClazzEnum(enumName, MesExtEnumUtil.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getEnumByClazzEnum(String enumName, Class clz) {
|
||||||
|
return EnumUtil.getEnumByName(clz, enumName);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue