| | |
| | | import com.zy.crm.common.web.BaseController; |
| | | import com.zy.crm.manager.entity.Rule; |
| | | import com.zy.crm.manager.service.RuleService; |
| | | import com.zy.crm.manager.utils.RuleUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | if (Cools.isEmpty(rule.getRuleConnectorType())){ |
| | | rule.setRuleConnectorType(1); |
| | | } |
| | | /* |
| | | * 定义一个规则:头:String ruleHeader;体: String ruleBody;连接符:String ruleConnector;连接符是否启用(0:启用;1:不启用。:Integer ruleConnectorType;规则方式(默认1:当前日期时间戳):Integer ruleType; |
| | | * 根据规则自动生成 |
| | | * */ |
| | | rule.setRulePreview(RuleUtils.rule(rule)); |
| | | ruleService.insert(rule); |
| | | return R.ok(); |
| | | } |
| | |
| | | if (Cools.isEmpty(rule) || null==rule.getId()){ |
| | | return R.error(); |
| | | } |
| | | if (Cools.isEmpty(rule.getRuleConnector())){ |
| | | rule.setRuleConnector("-"); |
| | | rule.setRuleConnectorType(1); |
| | | } |
| | | if (Cools.isEmpty(rule.getRuleConnectorType())){ |
| | | rule.setRuleConnectorType(1); |
| | | } |
| | | rule.setRulePreview(RuleUtils.rule(rule)); |
| | | ruleService.updateById(rule); |
| | | return R.ok(); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.annotations.TableId; |
| | | import com.baomidou.mybatisplus.annotations.TableName; |
| | | import com.baomidou.mybatisplus.enums.IdType; |
| | | import com.core.common.Cools; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.crm.system.entity.User; |
| | | import com.zy.crm.system.service.UserService; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | |
| | | this.ruleStandby2 = ruleStandby2; |
| | | } |
| | | |
| | | public String getRuleConnectorType$(){ |
| | | if (null == this.ruleConnectorType){ return null; } |
| | | switch (this.ruleConnectorType){ |
| | | case 1: |
| | | return "不启用"; |
| | | case 0: |
| | | return "启用"; |
| | | default: |
| | | return String.valueOf(this.ruleConnectorType); |
| | | } |
| | | } |
| | | |
| | | public String getRuleConnector$(){ |
| | | if (null == this.ruleConnectorType){ return null; } |
| | | switch (this.ruleConnector){ |
| | | case "-": |
| | | return "默认'-'"; |
| | | default: |
| | | return String.valueOf(this.ruleConnectorType); |
| | | } |
| | | } |
| | | |
| | | // Rule rule = new Rule( |
| | | // null, // 规则方式(默认1:当前日期时间戳)[非空] |
| | | // null, // 规则头[非空] |
| | |
| | | package com.zy.crm.manager.utils; |
| | | |
| | | import com.zy.crm.manager.entity.Rule; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Random; |
| | | import java.util.concurrent.ThreadLocalRandom; |
| | | |
| | | |
| | | /* |
| | | * 定义一个规则:头:String ruleHeader;体: String ruleBody;连接符:String ruleConnector;连接符是否启用(0:启用;1:不启用。:Integer ruleConnectorType;规则方式(默认1:当前日期时间戳):Integer ruleType; |
| | | * 根据规则自动生成 |
| | | * Created by Monkey D. Luffy on 2023.08.22. |
| | | * */ |
| | | public class RuleUtils { |
| | | private String ruleHeader; |
| | | private String ruleBody; |
| | |
| | | |
| | | // 添加头部 |
| | | sb.append(ruleHeader); |
| | | |
| | | // 根据规则方式生成日期时间戳或随机字符串 |
| | | String ruleValue = ""; |
| | | if (ruleType == 1) { |
| | | ruleValue = String.valueOf(System.currentTimeMillis()); |
| | | } else if (ruleType == 2) { |
| | | ruleValue = generateRandomString(10); // 生成长度为10的随机字符串 |
| | | } else if (ruleType == 3) { |
| | | ruleValue = generateCustomTimestamp(); // 自定义生成日期时间戳的逻辑 |
| | | } |
| | | |
| | | // 添加规则值到字符串体 |
| | | sb.append(ruleBody); |
| | | sb.append(ruleValue); |
| | | |
| | | // 添加连接符(如果启用) |
| | | if (ruleConnectorType == 0) { |
| | | sb.append(ruleConnector); |
| | | } |
| | | |
| | | // 根据规则方式生成日期时间戳或随机字符串 |
| | | String ruleValue = ""; |
| | | switch (ruleType) { |
| | | case 1: |
| | | ruleValue = String.valueOf(System.currentTimeMillis()); |
| | | break; |
| | | case 2: |
| | | ruleValue = generateRandomString(10); // 生成长度为10的随机字符串 |
| | | break; |
| | | case 3: |
| | | ruleValue = generateCustomTimestamp(); // 自定义生成日期时间戳的逻辑 |
| | | break; |
| | | } |
| | | |
| | | // 添加规则值到字符串体 |
| | | sb.append(ruleBody); |
| | | // 添加连接符(如果启用) |
| | | if (ruleConnectorType == 0) { |
| | | sb.append(ruleConnector); |
| | | } |
| | | sb.append(ruleValue); |
| | | |
| | | return sb.toString(); |
| | | } |
| | |
| | | String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; |
| | | StringBuilder sb = new StringBuilder(); |
| | | |
| | | Random random = new Random(); |
| | | for (int i = 0; i < length; i++) { |
| | | int index = random.nextInt(characters.length()); |
| | | int index = ThreadLocalRandom.current().nextInt(characters.length()); |
| | | char randomChar = characters.charAt(index); |
| | | sb.append(randomChar); |
| | | } |
| | |
| | | private String generateCustomTimestamp() { |
| | | // 自定义生成日期时间戳的逻辑 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | return now.format(formatter);// 返回生成的自定义日期时间戳 |
| | | return now.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);// 返回生成的自定义日期时间戳 |
| | | } |
| | | |
| | | public static String rule(Rule rule){ |
| | | String ruleHeader = rule.getRuleHeader(); |
| | | String ruleBody = rule.getRuleBody(); |
| | | String ruleConnector = rule.getRuleConnector(); |
| | | int ruleConnectorType = rule.getRuleConnectorType(); |
| | | int ruleType = rule.getRuleType(); |
| | | |
| | | RuleUtils generator = new RuleUtils(ruleHeader, ruleBody, ruleConnector, ruleConnectorType, ruleType); |
| | | String generatedString = generator.generateString(); |
| | | return generatedString; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String ruleHeader = "Header: "; |
| | | String ruleBody = "Timestamp: "; |
| | | String ruleHeader = "HEADER"; |
| | | String ruleBody = "TIMESTAMP"; |
| | | String ruleConnector = "-"; |
| | | int ruleConnectorType = 0; |
| | | int ruleConnectorType = 1; |
| | | int ruleType = 1; |
| | | |
| | | RuleUtils generator = new RuleUtils(ruleHeader, ruleBody, ruleConnector, ruleConnectorType, ruleType); |
| | |
| | | cellMinWidth: 50, |
| | | height: 'full-120', |
| | | cols: [[ |
| | | {type: 'checkbox'} |
| | | ,{field: 'id', align: 'center',title: 'ID'} |
| | | ,{field: 'ruleType', align: 'center',title: '规则方式(默认1:当前日期时间戳)'} |
| | | ,{field: 'ruleHeader', align: 'center',title: '规则头'} |
| | | ,{field: 'ruleBody', align: 'center',title: '规则体'} |
| | | ,{field: 'ruleConnector', align: 'center',title: '连接符(默认“-”)'} |
| | | ,{field: 'ruleConnectorType', align: 'center',title: '连接符是否启用(0:启用;1:不启用。默认1)'} |
| | | ,{field: 'ruleMemo', align: 'center',title: '备注'} |
| | | ,{field: 'rulePreview', align: 'center',title: '预览'} |
| | | ,{field: 'ruleStandby1', align: 'center',title: '备用字段1'} |
| | | ,{field: 'ruleStandby2', align: 'center',title: '备用字段2'} |
| | | // {type: 'checkbox'}, |
| | | {field: 'id', align: 'center',title: 'ID',width: 80, hide:true} |
| | | ,{field: 'ruleType', align: 'center',title: '规则方式', hide:false} |
| | | ,{field: 'ruleHeader', align: 'center',title: '规则头', hide:false} |
| | | ,{field: 'ruleBody', align: 'center',title: '规则体', hide:false} |
| | | ,{field: 'ruleConnector', align: 'center',title: '连接符', hide:false} |
| | | ,{field: 'ruleConnectorType$', align: 'center',title: '连接符是否启用', hide:false} |
| | | ,{field: 'ruleMemo', align: 'center',title: '备注', hide:false} |
| | | ,{field: 'rulePreview', align: 'center',title: '预览',width: 350, hide:false} |
| | | // ,{field: 'ruleStandby1', align: 'center',title: '备用字段1'} |
| | | // ,{field: 'ruleStandby2', align: 'center',title: '备用字段2'} |
| | | |
| | | ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120} |
| | | ]], |