diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/BytesUtils.java b/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/BytesUtils.java new file mode 100644 index 0000000..000b395 --- /dev/null +++ b/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/BytesUtils.java @@ -0,0 +1,63 @@ + +package com.ebts.common.utils.md5; + +import com.google.common.primitives.Bytes; + +import java.util.LinkedList; + +/** + * Byte工具 + * + * @author yinzhennan + * @version V1.0 + * @since 2020-08-27 09:28 + */ +public class BytesUtils { + + public static final int FF = 0xFF; + + public static byte[] long2bytes(long v) { + byte[] ret = new byte[]{0, 0, 0, 0, 0, 0, 0, 0}; + long2bytes(v, ret); + return ret; + } + + public static byte[] trim(byte[] bytes) { + LinkedList linkedList = new LinkedList<>(Bytes.asList(bytes)); + while(linkedList.getFirst() == 0){ + linkedList.remove(0); + } + return Bytes.toArray(linkedList); + } + + public static long bytes2Long(byte[] input){ + final int size = input.length; + if(size > 8){ + throw new IllegalArgumentException("输入参数最多8位"); + } + int unsigned = input[0] & FF; + long value = 0; + value = value | unsigned; + // 循环读取每个字节通过移位运算完成long的8个字节拼装 + for(int i=1;i< size;++i){ + unsigned = input[i] & FF; + value = value << 8 | unsigned; + } + return value; + } + + private static void long2bytes(long v, byte[] b) { + long2bytes(v, b, 0); + } + + private static void long2bytes(long v, byte[] b, int off) { + b[off + 7] = (byte)((int)v); + b[off + 6] = (byte)((int)(v >>> 8)); + b[off + 5] = (byte)((int)(v >>> 16)); + b[off + 4] = (byte)((int)(v >>> 24)); + b[off + 3] = (byte)((int)(v >>> 32)); + b[off + 2] = (byte)((int)(v >>> 40)); + b[off + 1] = (byte)((int)(v >>> 48)); + b[off + 0] = (byte)((int)(v >>> 56)); + } +} diff --git a/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/Md5Obfuscator.java b/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/Md5Obfuscator.java new file mode 100644 index 0000000..3e8530d --- /dev/null +++ b/ebts/ebts-common/src/main/java/com/ebts/common/utils/md5/Md5Obfuscator.java @@ -0,0 +1,61 @@ +package com.ebts.common.utils.md5; + +import com.ebts.common.config.MD5Config; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.util.DigestUtils; + +import java.util.Arrays; +import java.util.Base64; + +/** + * @author: Clay + * @date: 2022/1/5 15:07 + * @description:IdObfuscator + * @email: clay@hchyun.com + */ +public class Md5Obfuscator { + + /** + * 校验等级 1-16,等级越高,密级越高(没什么卵用),encode结果越长 + */ + private static final int VALID_LEVEL = 16; + + /** + * 编码 + */ + public static String encode(String id){ + byte[] idBytes; + if (id == null| "".equals(id)){ + return null; + } + try { + idBytes = BytesUtils.long2bytes(Long.parseLong(id)); + }catch (Exception e){ + return id; + } + idBytes = BytesUtils.trim(idBytes); + final byte[] md5 = DigestUtils.md5Digest(ArrayUtils.addAll(idBytes, MD5Config.getSecretKey().getBytes())); + final byte[] combine = ArrayUtils.addAll(Arrays.copyOf(md5, VALID_LEVEL), idBytes); + return Base64.getUrlEncoder().encodeToString(combine).replaceAll("=", ""); + } + + /** + * 解码 + */ + public static String decode(String raw){ + if (raw == null | "".equals(raw)){ + return null; + } + final byte[] bytes = Base64.getUrlDecoder().decode(raw); + final byte[] md5ValidBytes = Arrays.copyOfRange(bytes, 0, VALID_LEVEL); + final byte[] idBytes = Arrays.copyOfRange(bytes, VALID_LEVEL, bytes.length); + //验证 + final byte[] md5 = DigestUtils.md5Digest(ArrayUtils.addAll(idBytes, MD5Config.getSecretKey().getBytes())); + for (int i = 0; i < md5ValidBytes.length; i++) { + if (md5ValidBytes[i] != md5[i]){ + } + } + + return String.valueOf(BytesUtils.bytes2Long(idBytes)); + } +} diff --git a/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm b/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm index 9f8b5d5..0af5f9b 100644 --- a/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm +++ b/ebts/ebts-generator/src/main/resources/vm/java/controller.java.vm @@ -60,7 +60,7 @@ public class ${ClassName}Controller extends EBTSController { @ApiOperation("查询${functionName}列表") @PreAuthorize("@ebts.hasPermi('${permissionPrefix}:list')") @PostMapping("/list") - public Serializable list(@Validated @RequestBody ${ClassName} ${className}) { + public Serializable list(@RequestBody ${ClassName} ${className}) { startPage(${className}.getPageInfo()); ServerResult> genServerResult = ${className}Service.select${ClassName}List(${className}); if (genServerResult.isStart()) { @@ -81,7 +81,7 @@ public class ${ClassName}Controller extends EBTSController { @PreAuthorize("@ebts.hasPermi('${permissionPrefix}:export')") @Log(title = "${functionName}", businessType = BusinessType.EXPORT) @PostMapping("/export") - public AjaxResult export(@Validated @RequestBody ${ClassName} ${className}) { + public AjaxResult export(@RequestBody ${ClassName} ${className}) { ServerResult> genServerResult = ${className}Service.select${ClassName}List(${className}); ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}. class); if (genServerResult.isStart()) { diff --git a/ebts/ebts-generator/src/main/resources/vm/vue/index.vue.vm b/ebts/ebts-generator/src/main/resources/vm/vue/index.vue.vm index 94093f2..6180d88 100644 --- a/ebts/ebts-generator/src/main/resources/vm/vue/index.vue.vm +++ b/ebts/ebts-generator/src/main/resources/vm/vue/index.vue.vm @@ -551,7 +551,7 @@ export default { #set($comment=$column.columnComment) #end $column.javaField: [ - { required: true, message: "${comment}不能为空}", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }, + { required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }, #if($column.isRegular != 1) { pattern: /${column.regular}/, message: '${column.columnComment}格式有误', trigger:"blur"}, #end diff --git a/ebts/ebts-system/src/main/java/com/ebts/system/entity/SysFile.java b/ebts/ebts-system/src/main/java/com/ebts/system/entity/SysFile.java index 58bb610..7040dd6 100644 --- a/ebts/ebts-system/src/main/java/com/ebts/system/entity/SysFile.java +++ b/ebts/ebts-system/src/main/java/com/ebts/system/entity/SysFile.java @@ -2,6 +2,7 @@ package com.ebts.system.entity; import com.ebts.common.annotation.Excel; import com.ebts.common.core.entity.BaseEntity; +import com.ebts.system.utils.FtpUtils; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -158,6 +159,9 @@ public class SysFile extends BaseEntity { public void setIsPublic(String isPublic) { this.isPublic = isPublic; + if ("1".equals(isPublic)&&("jpg".equals(fileType)||"png".equals(fileType))){ + this.setRemark(FtpUtils.getResources()+fileAddr+"/"+mapping); + } } public String getIsPublic() {