use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class PermissionController method verifyFormPid.
/**
* 操作后的菜单类型是目录的时候 父级必须为目录
* 操作后的菜单类型是菜单的时候,父类必须为目录类型
* 操作后的菜单类型是按钮的时候 父类必须为菜单类型
*/
private void verifyFormPid(SysPermission sysPermission) {
SysPermission parent;
parent = permissionService.getById(sysPermission.getPid());
switch(sysPermission.getType()) {
case 1:
if (parent != null) {
if (parent.getType() != 1) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR);
}
} else if (!"0".equals(sysPermission.getPid())) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_CATALOG_ERROR);
}
break;
case 2:
if (parent == null || parent.getType() != 1) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_MENU_ERROR);
}
if (StringUtils.isEmpty(sysPermission.getUrl())) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL);
}
break;
case 3:
if (parent == null || parent.getType() != 2) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_BTN_ERROR);
}
if (StringUtils.isEmpty(sysPermission.getPerms())) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_PERMS_NULL);
}
if (StringUtils.isEmpty(sysPermission.getUrl())) {
throw new BusinessException(BaseResponseCode.OPERATION_MENU_PERMISSION_URL_NOT_NULL);
}
break;
default:
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class GenUtils method generatorCode.
/**
* 生成代码
*/
public static void generatorCode(Map<String, String> table, List<Map<String, String>> columns, ZipOutputStream zip) {
// 配置信息
Configuration config = getConfig();
boolean hasBigDecimal = false;
// 表信息
TableEntity tableEntity = new TableEntity();
tableEntity.setTableName(table.get("tableName"));
tableEntity.setComments(table.get("tableComment"));
// 表名转换成Java类名
String className = tableToJava(tableEntity.getTableName(), config.getStringArray("tablePrefix"));
tableEntity.setClassName(className);
tableEntity.setClassname(StringUtils.uncapitalize(className));
tableEntity.setClassNameLower(className.toLowerCase());
// 列信息
List<ColumnEntity> columsList = new ArrayList<>();
for (Map<String, String> column : columns) {
ColumnEntity columnEntity = new ColumnEntity();
columnEntity.setColumnName(column.get("columnName"));
columnEntity.setDataType(column.get("dataType"));
columnEntity.setComments(column.get("columnComment"));
columnEntity.setExtra(column.get("extra"));
// 列名转换成Java属性名
String attrName = columnToJava(columnEntity.getColumnName());
columnEntity.setAttrName(attrName);
columnEntity.setAttrname(StringUtils.uncapitalize(attrName));
// 列的数据类型,转换成Java类型
String attrType = config.getString(columnEntity.getDataType(), "unknowType");
columnEntity.setAttrType(attrType);
if (!hasBigDecimal && "BigDecimal".equals(attrType)) {
hasBigDecimal = true;
}
// 是否主键
if ("PRI".equalsIgnoreCase(column.get("columnKey")) && tableEntity.getPk() == null) {
tableEntity.setPk(columnEntity);
}
columsList.add(columnEntity);
}
tableEntity.setColumns(columsList);
// 没主键,则第一个字段为主键
if (tableEntity.getPk() == null) {
tableEntity.setPk(tableEntity.getColumns().get(0));
}
// 设置velocity资源加载器
Properties prop = new Properties();
prop.put("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
Velocity.init(prop);
String mainPath = config.getString("mainPath");
mainPath = StringUtils.isBlank(mainPath) ? "com.company" : mainPath;
// 封装模板数据
Map<String, Object> map = new HashMap<>(15);
map.put("tableName", tableEntity.getTableName());
map.put("comments", tableEntity.getComments());
map.put("pk", tableEntity.getPk());
map.put("className", tableEntity.getClassName());
map.put("classname", tableEntity.getClassname());
map.put("pathName", tableEntity.getClassname().toLowerCase());
map.put("columns", tableEntity.getColumns());
map.put("classNameLower", tableEntity.getClassNameLower());
map.put("hasBigDecimal", hasBigDecimal);
map.put("mainPath", mainPath);
map.put("package", config.getString("package"));
map.put("author", config.getString("author"));
map.put("email", config.getString("email"));
map.put("datetime", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
map.put("identity", IdWorker.getId());
map.put("addId", IdWorker.getId());
map.put("updateId", IdWorker.getId());
map.put("deleteId", IdWorker.getId());
map.put("selectId", IdWorker.getId());
VelocityContext context = new VelocityContext(map);
// 获取模板列表
List<String> templates = getTemplates();
for (String template : templates) {
// 渲染模板
StringWriter sw = new StringWriter();
Template tpl = Velocity.getTemplate(template, "UTF-8");
tpl.merge(context, sw);
try {
// 添加到zip
zip.putNextEntry(new ZipEntry(Objects.requireNonNull(getFileName(template, tableEntity.getClassName(), config.getString("package")))));
IOUtils.write(sw.toString(), zip, "UTF-8");
IOUtils.closeQuietly(sw);
zip.closeEntry();
} catch (IOException e) {
throw new BusinessException("渲染模板失败,表名:" + tableEntity.getTableName());
}
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class AesCipherUtil method enCrypto.
/**
* 加密
* @param str
* @return java.lang.String
* @author dolyw.com
* @date 2018/8/31 16:56
*/
public static String enCrypto(String str) {
try {
// Security.addProvider(Provider.Service);
// Security.addProvider(new com.sun.crypto.provider.SunJCE());
// 实例化支持AES算法的密钥生成器(算法名称命名需按规定,否则抛出异常)
// KeyGenerator 提供对称密钥生成器的功能,支持各种算法
KeyGenerator keygen = KeyGenerator.getInstance("AES");
// 将私钥encryptAESKey先Base64解密后转换为byte[]数组按128位初始化
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(Base64ConvertUtil.decode(encryptAESKey).getBytes());
keygen.init(128, secureRandom);
// SecretKey 负责保存对称密钥 生成密钥
SecretKey desKey = keygen.generateKey();
// 生成Cipher对象,指定其支持的AES算法,Cipher负责完成加密或解密工作
Cipher c = Cipher.getInstance("AES");
// 根据密钥,对Cipher对象进行初始化,ENCRYPT_MODE表示加密模式
c.init(Cipher.ENCRYPT_MODE, desKey);
byte[] src = str.getBytes();
// 该字节数组负责保存加密的结果
byte[] cipherByte = c.doFinal(src);
// 先将二进制转换成16进制,再返回Base64加密后的String
return Base64ConvertUtil.encode(HexConvertUtil.parseByte2HexStr(cipherByte));
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
logger.error("getInstance()方法异常:{}", e.getMessage());
throw new BusinessException("getInstance()方法异常:" + e.getMessage());
} catch (UnsupportedEncodingException e) {
logger.error("Base64加密异常:{}", e.getMessage());
throw new BusinessException("Base64加密异常:" + e.getMessage());
} catch (InvalidKeyException e) {
logger.error("初始化Cipher对象异常:{}", e.getMessage());
throw new BusinessException("初始化Cipher对象异常:" + e.getMessage());
} catch (IllegalBlockSizeException | BadPaddingException e) {
logger.error("加密异常,密钥有误:{}", e.getMessage());
throw new BusinessException("加密异常,密钥有误:" + e.getMessage());
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class SerializableUtil method unserializable.
/**
* 反序列化
* @param bytes
* @return java.lang.Object
* @author dolyw.com
* @date 2018/9/4 15:14
*/
public static Object unserializable(byte[] bytes) {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
bais = new ByteArrayInputStream(bytes);
ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (ClassNotFoundException e) {
logger.error("SerializableUtil工具类反序列化出现ClassNotFoundException异常:{}", e.getMessage());
throw new BusinessException("SerializableUtil工具类反序列化出现ClassNotFoundException异常:" + e.getMessage());
} catch (IOException e) {
logger.error("SerializableUtil工具类反序列化出现IOException异常:{}", e.getMessage());
throw new BusinessException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
} finally {
try {
if (ois != null) {
ois.close();
}
if (bais != null) {
bais.close();
}
} catch (IOException e) {
logger.error("SerializableUtil工具类反序列化出现IOException异常:{}", e.getMessage());
throw new BusinessException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
}
}
}
use of com.jun.plugin.system.common.exception.BusinessException in project jun_springboot_api_service by wujun728.
the class SerializableUtil method serializable.
/**
* 序列化
* @param object
* @return byte[]
* @author dolyw.com
* @date 2018/9/4 15:14
*/
public static byte[] serializable(Object object) {
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
return baos.toByteArray();
} catch (IOException e) {
logger.error("SerializableUtil工具类序列化出现IOException异常:{}", e.getMessage());
throw new BusinessException("SerializableUtil工具类序列化出现IOException异常:" + e.getMessage());
} finally {
try {
if (oos != null) {
oos.close();
}
if (baos != null) {
baos.close();
}
} catch (IOException e) {
logger.error("SerializableUtil工具类反序列化出现IOException异常:{}", e.getMessage());
throw new BusinessException("SerializableUtil工具类反序列化出现IOException异常:" + e.getMessage());
}
}
}
Aggregations