规则设置

main
FOAM 2024-09-18 16:08:42 +08:00
parent b113920e3a
commit 277842c569
12 changed files with 859 additions and 2 deletions

View File

@ -0,0 +1,26 @@
package com.youchain;
import java.util.regex.Pattern;
public class EmailValidator {
// 正则表达式规则来源于https://howtodoinjava.com/java/regex/java-email-address-validation-regex/
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
private static final Pattern pattern = Pattern.compile(EMAIL_PATTERN);
public static boolean validate(String email) {
if (email == null) {
return false;
}
return pattern.matcher(email).matches();
}
public static void main(String[] args) {
// 测试电子邮件格式是否正确
System.out.println(validate("houjl@youchain56.com")); // true
System.out.println(validate("example.test@sub.test.com")); // true
System.out.println(validate("example.test.com")); // false
System.out.println(validate("example#test@test.com")); // false
}
}

View File

@ -0,0 +1,159 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.domain;
import com.youchain.base.BaseEntity;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import io.swagger.annotations.ApiModelProperty;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author houjianlan
* @date 2024-09-13
**/
@Entity
@Data
@Table(name="sys_rule_configure")
public class RuleConfigure extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "`id`")
@ApiModelProperty(value = "id")
private Long id;
@Column(name = "`rule_type`")
@NotBlank
@ApiModelProperty(value = "规则类型")
private String ruleType;
@Column(name = "`sql_content`")
@NotBlank
@ApiModelProperty(value = "SQL内容")
private String sqlContent;
@Column(name = "`description`")
@ApiModelProperty(value = "描述")
private String description;
@Column(name = "`beyj`")
@ApiModelProperty(value = "是否发邮件")
private Boolean beyj=false;
@Column(name = "`yj_des`")
@ApiModelProperty(value = "邮件备注")
private String yjDes;
@Column(name = "`yj_sjr`")
@ApiModelProperty(value = "邮件收件人")
private String yjSjr;
@Column(name = "`betc`")
@ApiModelProperty(value = "是否弹窗")
private Boolean betc=false;
@Column(name = "`tc_msg`")
@ApiModelProperty(value = "弹窗消息")
private String tcMsg;
@Column(name = "`beys`")
@ApiModelProperty(value = "颜色标记")
private Boolean beys=false;
@Column(name = "`ys_flg`")
@ApiModelProperty(value = "标记颜色值")
private String ysFlg;
@Column(name = "`ys_field`")
@ApiModelProperty(value = "标记颜色字段")
private String ysField;
@Column(name = "`gs_content`")
@ApiModelProperty(value = "格式校验正则表达式")
private String gsContent;
@Column(name = "`bekz1`")
@ApiModelProperty(value = "扩展1标记")
private Boolean bekz1=false;
@Column(name = "`kz1_msg`")
@ApiModelProperty(value = "扩展1消息")
private String kz1Msg;
@Column(name = "`kz1_content`")
@ApiModelProperty(value = "扩展1内容")
private String kz1Content;
@Column(name = "`bekz2`")
@ApiModelProperty(value = "扩展2标记")
private Boolean bekz2=false;
@Column(name = "`kz2_msg`")
@ApiModelProperty(value = "扩展2消息")
private String kz2Msg;
@Column(name = "`kz2_content`")
@ApiModelProperty(value = "扩展2内容")
private String kz2Content;
@Column(name = "`bekz3`")
@ApiModelProperty(value = "扩展3标记")
private Boolean bekz3=false;
@Column(name = "`kz3_msg`")
@ApiModelProperty(value = "扩展3消息")
private String kz3Msg;
@Column(name = "`kz3_content`")
@ApiModelProperty(value = "扩展3内容")
private String kz3Content;
@Column(name = "`bekz4`")
@ApiModelProperty(value = "扩展4标记")
private Boolean bekz4=false;
@Column(name = "`kz4_msg`")
@ApiModelProperty(value = "扩展4消息")
private String kz4Msg;
@Column(name = "`kz4_content`")
@ApiModelProperty(value = "扩展4内容")
private String kz4Content;
@Column(name = "`bekz5`")
@ApiModelProperty(value = "扩展5标记")
private Boolean bekz5=false;
@Column(name = "`kz5_msg`")
@ApiModelProperty(value = "扩展5消息")
private String kz5Msg;
@Column(name = "`kz5_content`")
@ApiModelProperty(value = "扩展5内容")
private String kz5Content;
public void copy(RuleConfigure source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.repository;
import com.youchain.basicdata.domain.RuleConfigure;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2024-09-14
**/
public interface RuleConfigureRepository extends JpaRepository<RuleConfigure, Long>, JpaSpecificationExecutor<RuleConfigure> {
}

View File

@ -0,0 +1,99 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.rest;
import com.youchain.annotation.Log;
import com.youchain.basicdata.domain.RuleConfigure;
import com.youchain.basicdata.service.RuleConfigureService;
import com.youchain.basicdata.service.dto.RuleConfigureQueryCriteria;
import com.youchain.exception.BadRequestException;
import com.youchain.modules.quartz.task.TestTask;
import com.youchain.utils.RegexUtils;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2024-09-14
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "RuleConfigure管理")
@RequestMapping("/api/ruleConfigure")
public class RuleConfigureController {
private final RuleConfigureService ruleConfigureService;
private final TestTask testTask;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('ruleConfigure:list')")
public void exportRuleConfigure(HttpServletResponse response, RuleConfigureQueryCriteria criteria) throws Exception {
ruleConfigureService.download(ruleConfigureService.queryAll(criteria), response);
}
@GetMapping
@Log("查询RuleConfigure")
@ApiOperation("查询RuleConfigure")
@PreAuthorize("@el.check('ruleConfigure:list')")
public ResponseEntity<Object> queryRuleConfigure(RuleConfigureQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(ruleConfigureService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增RuleConfigure")
@ApiOperation("新增RuleConfigure")
@PreAuthorize("@el.check('ruleConfigure:add')")
public ResponseEntity<Object> createRuleConfigure(@Validated @RequestBody RuleConfigure resources){
if(resources.getBeyj()){
RegexUtils.emailRegex(resources.getYjSjr());
}
return new ResponseEntity<>(ruleConfigureService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改RuleConfigure")
@ApiOperation("修改RuleConfigure")
@PreAuthorize("@el.check('ruleConfigure:edit')")
public ResponseEntity<Object> updateRuleConfigure(@Validated @RequestBody RuleConfigure resources){
if(resources.getBeyj()){
RegexUtils.emailRegex(resources.getYjSjr());
}
ruleConfigureService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@DeleteMapping
@Log("删除RuleConfigure")
@ApiOperation("删除RuleConfigure")
@PreAuthorize("@el.check('ruleConfigure:del')")
public ResponseEntity<Object> deleteRuleConfigure(@RequestBody Long[] ids) {
ruleConfigureService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -204,8 +204,8 @@ public class StockController {
@PostMapping(value = "/stockMsg")
@AnonymousAccess
public ResponseEntity<Object> stockMsg(String msg) {
String stockMsg = stockService.stockMsg(msg);
public ResponseEntity<Object> stockMsg() {
String stockMsg = stockService.stockMsg();
return new ResponseEntity<>(stockMsg, HttpStatus.OK);
}

View File

@ -0,0 +1,83 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.service;
import com.youchain.basicdata.domain.RuleConfigure;
import com.youchain.basicdata.service.dto.RuleConfigureDto;
import com.youchain.basicdata.service.dto.RuleConfigureQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @website https://eladmin.vip
* @description
* @author houjianlan
* @date 2024-09-14
**/
public interface RuleConfigureService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(RuleConfigureQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<RuleConfigureDto>
*/
List<RuleConfigureDto> queryAll(RuleConfigureQueryCriteria criteria);
/**
* ID
* @param id ID
* @return RuleConfigureDto
*/
RuleConfigureDto findById(Long id);
/**
*
* @param resources /
* @return RuleConfigureDto
*/
RuleConfigureDto create(RuleConfigure resources);
/**
*
* @param resources /
*/
void update(RuleConfigure resources);
/**
*
* @param ids /
*/
void deleteAll(Long[] ids);
/**
*
* @param all
* @param response /
* @throws Exception /
*/
void download(List<RuleConfigureDto> all, HttpServletResponse response) throws Exception;
}

View File

@ -0,0 +1,125 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://eladmin.vip
* @description /
* @author houjianlan
* @date 2024-09-14
**/
@Data
public class RuleConfigureDto implements Serializable {
private Long id;
/** 规则类型 */
private String ruleType;
/** SQL内容 */
private String sqlContent;
/** 描述 */
private String description;
/** 是否发邮件 */
private Boolean beyj;
/** 邮件备注 */
private String yjDes;
/** 邮件收件人 */
private String yjSjr;
/** 是否弹窗 */
private Boolean betc;
/** 弹窗消息 */
private String tcMsg;
/** 颜色标记 */
private Boolean beys;
/** 标记颜色值 */
private String ysFlg;
/** 标记颜色字段 */
private String ysField;
/** 格式校验正则表达式 */
private String gsContent;
/** 扩展1标记 */
private Boolean bekz1;
/** 扩展1消息 */
private String kz1Msg;
/** 扩展1内容 */
private String kz1Content;
/** 扩展2标记 */
private Boolean bekz2;
/** 扩展2消息 */
private String kz2Msg;
/** 扩展2内容 */
private String kz2Content;
/** 扩展3标记 */
private Boolean bekz3;
/** 扩展3消息 */
private String kz3Msg;
/** 扩展3内容 */
private String kz3Content;
/** 扩展4标记 */
private Boolean bekz4;
/** 扩展4消息 */
private String kz4Msg;
/** 扩展4内容 */
private String kz4Content;
/** 扩展5标记 */
private Boolean bekz5;
/** 扩展5消息 */
private String kz5Msg;
/** 扩展5内容 */
private String kz5Content;
/** 创建人 */
private String createBy;
/** 更新人 */
private String updateBy;
/** 创建时间 */
private Timestamp createTime;
/** 更新时间 */
private Timestamp updateTime;
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.service.dto;
import lombok.Data;
import java.util.List;
import com.youchain.annotation.Query;
/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2024-09-14
**/
@Data
public class RuleConfigureQueryCriteria{
/** 精确 */
@Query
private String ruleType;
/** 模糊 */
@Query(type = Query.Type.INNER_LIKE)
private String sqlContent;
}

View File

@ -0,0 +1,134 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.service.impl;
import com.youchain.basicdata.domain.RuleConfigure;
import com.youchain.utils.FileUtil;
import com.youchain.utils.PageUtil;
import com.youchain.utils.QueryHelp;
import com.youchain.utils.ValidationUtil;
import lombok.RequiredArgsConstructor;
import com.youchain.basicdata.repository.RuleConfigureRepository;
import com.youchain.basicdata.service.RuleConfigureService;
import com.youchain.basicdata.service.dto.RuleConfigureDto;
import com.youchain.basicdata.service.dto.RuleConfigureQueryCriteria;
import com.youchain.basicdata.service.mapstruct.RuleConfigureMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @website https://eladmin.vip
* @description
* @author houjianlan
* @date 2024-09-14
**/
@Service
@RequiredArgsConstructor
public class RuleConfigureServiceImpl implements RuleConfigureService {
private final RuleConfigureRepository ruleConfigureRepository;
private final RuleConfigureMapper ruleConfigureMapper;
@Override
public Map<String,Object> queryAll(RuleConfigureQueryCriteria criteria, Pageable pageable){
Page<RuleConfigure> page = ruleConfigureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(ruleConfigureMapper::toDto));
}
@Override
public List<RuleConfigureDto> queryAll(RuleConfigureQueryCriteria criteria){
return ruleConfigureMapper.toDto(ruleConfigureRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Transactional
public RuleConfigureDto findById(Long id) {
RuleConfigure ruleConfigure = ruleConfigureRepository.findById(id).orElseGet(RuleConfigure::new);
ValidationUtil.isNull(ruleConfigure.getId(),"RuleConfigure","id",id);
return ruleConfigureMapper.toDto(ruleConfigure);
}
@Override
@Transactional(rollbackFor = Exception.class)
public RuleConfigureDto create(RuleConfigure resources) {
return ruleConfigureMapper.toDto(ruleConfigureRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(RuleConfigure resources) {
RuleConfigure ruleConfigure = ruleConfigureRepository.findById(resources.getId()).orElseGet(RuleConfigure::new);
ValidationUtil.isNull( ruleConfigure.getId(),"RuleConfigure","id",resources.getId());
ruleConfigure.copy(resources);
ruleConfigureRepository.save(ruleConfigure);
}
@Override
public void deleteAll(Long[] ids) {
for (Long id : ids) {
ruleConfigureRepository.deleteById(id);
}
}
@Override
public void download(List<RuleConfigureDto> all, HttpServletResponse response) throws Exception {
List<Map<String, Object>> list = new ArrayList<>();
for (RuleConfigureDto ruleConfigure : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("规则类型", ruleConfigure.getRuleType());
map.put("SQL内容", ruleConfigure.getSqlContent());
map.put("描述", ruleConfigure.getDescription());
map.put("是否发邮件", ruleConfigure.getBeyj());
map.put("邮件备注", ruleConfigure.getYjDes());
map.put("邮件收件人", ruleConfigure.getYjSjr());
map.put("是否弹窗", ruleConfigure.getBetc());
map.put("弹窗消息", ruleConfigure.getTcMsg());
map.put("颜色标记", ruleConfigure.getBeys());
map.put("标记颜色值", ruleConfigure.getYsFlg());
map.put("标记颜色字段", ruleConfigure.getYsField());
map.put("格式校验正则表达式", ruleConfigure.getGsContent());
map.put("扩展1标记", ruleConfigure.getBekz1());
map.put("扩展1消息", ruleConfigure.getKz1Msg());
map.put("扩展1内容", ruleConfigure.getKz1Content());
map.put("扩展2标记", ruleConfigure.getBekz2());
map.put("扩展2消息", ruleConfigure.getKz2Msg());
map.put("扩展2内容", ruleConfigure.getKz2Content());
map.put("扩展3标记", ruleConfigure.getBekz3());
map.put("扩展3消息", ruleConfigure.getKz3Msg());
map.put("扩展3内容", ruleConfigure.getKz3Content());
map.put("扩展4标记", ruleConfigure.getBekz4());
map.put("扩展4消息", ruleConfigure.getKz4Msg());
map.put("扩展4内容", ruleConfigure.getKz4Content());
map.put("扩展5标记", ruleConfigure.getBekz5());
map.put("扩展5消息", ruleConfigure.getKz5Msg());
map.put("扩展5内容", ruleConfigure.getKz5Content());
map.put("创建人", ruleConfigure.getCreateBy());
map.put("更新人", ruleConfigure.getUpdateBy());
map.put("创建时间", ruleConfigure.getCreateTime());
map.put("更新时间", ruleConfigure.getUpdateTime());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.basicdata.service.mapstruct;
import com.youchain.base.BaseMapper;
import com.youchain.basicdata.domain.RuleConfigure;
import com.youchain.basicdata.service.dto.RuleConfigureDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://eladmin.vip
* @author houjianlan
* @date 2024-09-14
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface RuleConfigureMapper extends BaseMapper<RuleConfigureDto, RuleConfigure> {
}

View File

@ -0,0 +1,102 @@
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.youchain.modules.quartz.task;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.youchain.annotation.AnonymousAccess;
import com.youchain.basicdata.domain.Point;
import com.youchain.basicdata.domain.RuleConfigure;
import com.youchain.basicdata.domain.Stock;
import com.youchain.basicdata.repository.RuleConfigureRepository;
import com.youchain.basicdata.service.StockService;
import com.youchain.businessdata.domain.PickDetail;
import com.youchain.businessdata.domain.Task;
import com.youchain.businessdata.service.TaskService;
import com.youchain.utils.BaseStatus;
import com.youchain.utils.BizStatus;
import com.youchain.utils.Email.EmailUtils;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.SQLQuery;
import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Liu Xue
* @date 2019-01-08
*/
@Slf4j
@Component("testTask")
@Service
public class TestTask {
@Autowired
private EntityManager entityManager;
@Autowired
private RuleConfigureRepository ruleConfigureRepository;
@Autowired
private StockService stockService;
private static int MAX_TASK_COUNT = 4;
public static int MAX_HS_COUNT = 4;
//限制时间
private static long TIMEOUT_MS = 600000; // 10分钟以毫秒为单位
private long lastTaskTime = System.currentTimeMillis();
// @Bean(autowire = Autowire.BY_NAME,value = "testTask")
@AnonymousAccess
public synchronized void reminderRules() {
System.out.println("执行一次定时任务");
List<RuleConfigure> ruleConfigures= ruleConfigureRepository.findAll();
System.out.println("执行一次定时任务2");
for(RuleConfigure ruleConfigure:ruleConfigures) {
String sql=ruleConfigure.getSqlContent();
List taskList= entityManager.createNativeQuery(sql)
.unwrap(SQLQuery.class)
.setResultTransformer(
AliasToEntityMapResultTransformer.INSTANCE
)
.list();
if(taskList.size()>0){
stockService.stockMsg(ruleConfigure.getTcMsg());
EmailUtils.sendNodecrypPwd("预警提醒",ruleConfigure.getYjDes(),ruleConfigure.getYjSjr().split(";"));
}
}
}
public static void main(String[] args) throws JsonProcessingException {
}
}

View File

@ -0,0 +1,32 @@
package com.youchain.utils;
import cn.hutool.core.util.RandomUtil;
import com.youchain.exception.BadRequestException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Component
@Slf4j
public class RegexUtils {
public static void emailRegex(String input){
if(input==null){
throw new BadRequestException("邮件收件人必填");
}
String[] emails=input.split(";");
for(int i=0;i<emails.length;i++){
String email=emails[i];
String regex = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(email);
if (!matcher.matches()) {
throw new BadRequestException(email+"请输入正确的邮件格式!");
}
}
}
}