10 changed files with 511 additions and 5 deletions
@ -0,0 +1,230 @@ |
|||
package com.kms.warn; |
|||
import cn.hutool.core.date.DateUtil; |
|||
import com.jwtech.util.StringUtil; |
|||
import org.apache.commons.lang.StringUtils; |
|||
/** |
|||
* 一个非常好用的工具类 |
|||
* <dependency> |
|||
* <groupId>org.apache.commons</groupId> |
|||
* <artifactId>commons-lang3</artifactId> |
|||
* <version>3.8</version> |
|||
* </dependency> |
|||
* |
|||
*/ |
|||
|
|||
|
|||
import java.text.SimpleDateFormat; |
|||
import java.util.*; |
|||
|
|||
/** |
|||
* @Description:节假日工具类 |
|||
* @Auther: Work-PC |
|||
* @Date: 2019-02-13 19:50 |
|||
* @Version: 1.0.0 |
|||
*/ |
|||
public class HolidayUtil { |
|||
|
|||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
|||
private static SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|||
|
|||
// public static void main(String[] args) throws Exception {
|
|||
// // 节假日
|
|||
//// String holidays = "2019-01-01,2019-01-04,2019-01-05,2019-01-06,2019-01-07,2019-01-08,2019-01-09,2019-01-10,2019-04-05,2019-04-06,2019-04-07,2019-05-01,2019-06-07,2019-06-08,2019-06-09,2019-09-13,2019-09-14,2019-09-15,2019-10-01,2019-10-02,2019-10-03,2019-10-04,2019-10-05,2019-10-06,2019-10-07";
|
|||
// // 设置工作日
|
|||
// int num = 10;
|
|||
// // 当前时间
|
|||
// String today = sdfs.format(new Date());
|
|||
//
|
|||
// System.out.println("当前,日期为==============" + today);
|
|||
// // num个工作日前
|
|||
// String workDayStart = getWorkDayStart(holidays, today, num);
|
|||
// System.out.println(num + "个工作日前,日期为========" + workDayStart);
|
|||
// // num个工作日后
|
|||
// String workDayEnd = getWorkDayEnd(holidays, today, num);
|
|||
// System.out.println(num + "个工作日后,日期为========" + workDayEnd);
|
|||
// }
|
|||
|
|||
|
|||
/** |
|||
* 获取当前时间之前n个工作日的日期 |
|||
* |
|||
* @param holidays 节假日(日期格式:2019-01-01,2019-01-04,2019-01-05,......) |
|||
* @param (日期格式:2019-01-01 08:08:08) |
|||
* @param num 需要设置的n个工作日 |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static Date getWorkDayStart(String holidays, Date date, int num) throws Exception { |
|||
// 转化为数组
|
|||
String[] dayArr = holidays.split(","); |
|||
List<String> holidayList = new ArrayList<String>(Arrays.asList(dayArr)); |
|||
// 将字符串转换成日期
|
|||
// Date date = sdfs.parse(today);
|
|||
|
|||
// 获取工作日
|
|||
Date workDay = getWorkDay(holidayList, num, date, -1); |
|||
long workTime = getTime(date, workDay) - 1000; // 减1秒
|
|||
|
|||
return new Date(workTime); |
|||
} |
|||
|
|||
/** |
|||
* 获取当前时间之后n个工作日的日期 |
|||
* |
|||
* @param holidays 节假日(日期格式:2019-01-01,2019-01-04,2019-01-05,......) |
|||
* @param (日期格式:2019-01-01 08:08:08) |
|||
* @param num 需要设置的n个工作日 |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static String getWorkDayEnd(String holidays, Date date, int num) throws Exception { |
|||
// 转化为数组
|
|||
String[] dayArr = holidays.split(","); |
|||
List<String> holidayList = new ArrayList<String>(Arrays.asList(dayArr)); |
|||
|
|||
// 将字符串转换成日期
|
|||
// Date date = sdfs.parse(today);
|
|||
|
|||
// 获取工作日
|
|||
Date workDay = getWorkDay(holidayList, num, date, 1); |
|||
// String workDayStr = sdf.format(workDay);
|
|||
long workTime = getTime(date, workDay) + 1000; // 加1秒
|
|||
|
|||
return sdfs.format(new Date(workTime)); |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 获取工作日 |
|||
* |
|||
* @param holidayList 节假日(日期格式:2019-01-01,2019-01-04,2019-01-05,......) |
|||
* @param num 需要设置的n个工作日 |
|||
* @param day 目标日期 |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static Date getWorkDay(List<String> holidayList, int num, Date day, int n) throws Exception { |
|||
int delay = 1; |
|||
while (delay <= num) { |
|||
// 获取前一天或后一天日期
|
|||
Date endDay = getDate(day, n); |
|||
String time = sdf.format(endDay); |
|||
|
|||
//当前日期+1即tomorrow,判断是否是节假日,同时要判断是否是周末,都不是则将scheduleActiveDate日期+1,直到循环num次即可
|
|||
if (!isWeekend(time) && !isHoliday(time, holidayList)) { |
|||
delay++; |
|||
} else if (isWeekend(time)) { |
|||
System.out.println(time + "::是周末"); |
|||
} else if (isHoliday(time, holidayList)) { |
|||
System.out.println(time + "::是节假日"); |
|||
} |
|||
day = endDay; |
|||
} |
|||
return day; |
|||
} |
|||
|
|||
/** |
|||
* yyyy-MM-dd HH:mm:ss格式日期---获取时间戳精确到秒 |
|||
* |
|||
* @param start 开始日期(日期格式:2019-01-01 08:08:08) |
|||
* @param end 结束日期(日期格式:2019-01-01 08:08:08) |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static long getTime(Date start, Date end) throws Exception { |
|||
// if (DateUtil.(start) || StringUtil.isEmpty(end)) {
|
|||
// throw new RuntimeException("today is empty");
|
|||
// }
|
|||
|
|||
long time1 = start.getTime(); |
|||
long time2 = start.getTime(); |
|||
long time3 = end.getTime(); |
|||
|
|||
long time = time3 + (time1 - time2); |
|||
|
|||
return time; |
|||
} |
|||
|
|||
/** |
|||
* 获取前一天或后一天日期 |
|||
* |
|||
* @param date 日期 |
|||
* @param n 判断参数 |
|||
* @return |
|||
*/ |
|||
public static Date getDate(Date date, int n) { |
|||
if (n > 0) { // 获取前一天
|
|||
date = getTomorrow(date); |
|||
} |
|||
if (n < 0) { // 获取后一天
|
|||
date = getYesterday(date); |
|||
} |
|||
return date; |
|||
} |
|||
|
|||
/** |
|||
* 获取后一天的日期 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static Date getTomorrow(Date date) { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(date); |
|||
calendar.add(Calendar.DAY_OF_MONTH, +1); |
|||
date = calendar.getTime(); |
|||
return date; |
|||
} |
|||
|
|||
/** |
|||
* 获取前一天的日期 |
|||
* |
|||
* @param date |
|||
* @return |
|||
*/ |
|||
public static Date getYesterday(Date date) { |
|||
Calendar calendar = Calendar.getInstance(); |
|||
calendar.setTime(date); |
|||
calendar.add(Calendar.DAY_OF_MONTH, -1); |
|||
date = calendar.getTime(); |
|||
return date; |
|||
} |
|||
|
|||
/** |
|||
* 判断是否是周末 |
|||
* |
|||
* @param sdate |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static boolean isWeekend(String sdate) throws Exception { |
|||
Date date = sdf.parse(sdate); |
|||
Calendar cal = Calendar.getInstance(); |
|||
cal.setTime(date); |
|||
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 判断是否是节假日 |
|||
* |
|||
* @param sdate |
|||
* @param list |
|||
* @return |
|||
* @throws Exception |
|||
*/ |
|||
public static boolean isHoliday(String sdate, List<String> list) throws Exception { |
|||
if (list.size() > 0) { |
|||
for (int i = 0; i < list.size(); i++) { |
|||
if (sdate.equals(list.get(i))) { |
|||
return true; |
|||
} |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
package com.kms.warn; |
|||
|
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.scheduling.annotation.EnableAsync; |
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
|||
|
|||
import java.util.concurrent.Executor; |
|||
|
|||
/** |
|||
* 线程池参数配置,多个线程池实现线程池隔离,@Async注解,默认使用系统自定义线程池,可在项目中设置多个线程池,在异步调用的时候,指明需要调用的线程池名称,比如:@Async("taskName") |
|||
**/ |
|||
@EnableAsync |
|||
@Configuration |
|||
public class TaskPoolConfig { |
|||
|
|||
|
|||
/** |
|||
* 自定义线程池 |
|||
* |
|||
* @author: jacklin |
|||
* @since: 2021/11/16 17:41 |
|||
**/ |
|||
@Bean("taskExecutor") |
|||
public Executor taskExecutor() { |
|||
//返回可用处理器的Java虚拟机的数量 12
|
|||
int i = Runtime.getRuntime().availableProcessors(); |
|||
System.out.println("系统最大线程数 : " + i); |
|||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
|||
//核心线程池大小
|
|||
executor.setCorePoolSize(16); |
|||
//最大线程数
|
|||
executor.setMaxPoolSize(20); |
|||
//配置队列容量,默认值为Integer.MAX_VALUE
|
|||
executor.setQueueCapacity(99999); |
|||
//活跃时间
|
|||
executor.setKeepAliveSeconds(60); |
|||
//线程名字前缀
|
|||
executor.setThreadNamePrefix("asyncServiceExecutor -"); |
|||
//设置此执行程序应该在关闭时阻止的最大秒数,以便在容器的其余部分继续关闭之前等待剩余的任务完成他们的执行
|
|||
executor.setAwaitTerminationSeconds(60); |
|||
//等待所有的任务结束后再关闭线程池
|
|||
executor.setWaitForTasksToCompleteOnShutdown(true); |
|||
return executor; |
|||
} |
|||
} |
@ -0,0 +1,59 @@ |
|||
package com.kms.warn; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|||
import com.jianwei.common.mybaitsplus.BeanToWrapper; |
|||
import com.kms.warn.domain.BsSgcJsjdWarnResult; |
|||
import com.kms.warn.service.BsSgcJsjdWarnResultService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class WarnOperate { |
|||
|
|||
@Autowired |
|||
BsSgcJsjdWarnResultService bsSgcJsjdWarnResultService; |
|||
|
|||
/** |
|||
* 发起预警 |
|||
*/ |
|||
public void sendWarn(String proNo,String proCode,WarnType warnType,String warnResult){ |
|||
BsSgcJsjdWarnResult bsSgcJsjdWarnResult = new BsSgcJsjdWarnResult(); |
|||
bsSgcJsjdWarnResult.setProNo(proNo); |
|||
bsSgcJsjdWarnResult.setProCode(proCode); |
|||
bsSgcJsjdWarnResult.setWarnType(warnType.getWarnType()); |
|||
bsSgcJsjdWarnResult.setWarnSubType(warnType.getWarnSubType()); |
|||
bsSgcJsjdWarnResult.setIsHandle("0"); //未处理的
|
|||
QueryWrapper<BsSgcJsjdWarnResult> wrapper = BeanToWrapper.getWrapper(bsSgcJsjdWarnResult); |
|||
BsSgcJsjdWarnResult one = bsSgcJsjdWarnResultService.getOne(wrapper, false); |
|||
if(one==null) { |
|||
bsSgcJsjdWarnResult.setWarnResult(warnResult); |
|||
bsSgcJsjdWarnResult.preInsert(); |
|||
bsSgcJsjdWarnResult.setCreateUid("1"); //系统账号
|
|||
bsSgcJsjdWarnResult.setResultType("1"); //预警
|
|||
bsSgcJsjdWarnResultService.save(bsSgcJsjdWarnResult); |
|||
}else { |
|||
one.setWarnResult(warnResult); |
|||
bsSgcJsjdWarnResultService.updateById(one); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判断是否存在预警 |
|||
* @param proNo |
|||
* @param proCode |
|||
* @param warnType |
|||
* @return |
|||
*/ |
|||
public Boolean isHandle(String proNo,String proCode,WarnType warnType){ |
|||
QueryWrapper<BsSgcJsjdWarnResult> query = Wrappers.query(); |
|||
query.lambda().eq(BsSgcJsjdWarnResult::getProCode,proCode) |
|||
.eq(BsSgcJsjdWarnResult::getProNo,proNo) |
|||
.eq(BsSgcJsjdWarnResult::getWarnType,warnType.getWarnType()) |
|||
.eq(BsSgcJsjdWarnResult::getWarnSubType,warnType.getWarnSubType()) |
|||
.eq(BsSgcJsjdWarnResult::getIsHandle,"0"); //未处理
|
|||
BsSgcJsjdWarnResult one = bsSgcJsjdWarnResultService.getOne(query, false); |
|||
return one==null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,50 @@ |
|||
package com.kms.warn; |
|||
|
|||
|
|||
import com.kms.system.constants.OperationStatus; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Getter |
|||
@AllArgsConstructor |
|||
public enum WarnType { |
|||
|
|||
//标段单次变更金额超过500万元,或单项变更金额超过标段合同价5%
|
|||
SECTION_EXCEED("A001","001","标段单次变更金额超过500万元,或单项变更金额超过标段合同价5%",null), |
|||
//保证金的缴纳时间与施工令时间进行比对,大于20个工作日
|
|||
MARGIN_PAYMENT_TIME("D001","004","保证金的缴纳时间与施工令时间进行比对,大于%个工作日",null), |
|||
//专用账户余额等于小于0
|
|||
SALARY_DEPOSIT("D002","004","专用账户余额为%",null), |
|||
//标段变更次数累计超过20次的,非基本建设程序项目的标段变更次数累计超过10次的
|
|||
SECTION_CHANGES("A003","001","标段变更次数累计%次,超过20次","基本建设程序项目的标段变更次数累计%次,超过10次"); |
|||
|
|||
private String warnType; |
|||
private String warnSubType; |
|||
private String warnResult; |
|||
private String otherResult; |
|||
|
|||
public static Map<String, WarnType> nameMap = new HashMap<String, WarnType>( |
|||
30); |
|||
|
|||
static { |
|||
WarnType[] allValues = WarnType.values(); |
|||
for (WarnType obj : allValues) { |
|||
nameMap.put(obj.getWarnType(), obj); |
|||
} |
|||
} |
|||
|
|||
|
|||
public static WarnType parseByName(String name) { |
|||
return nameMap.get(name); |
|||
} |
|||
|
|||
|
|||
public String replaceString(String warnResult,String target){ |
|||
return warnResult.replaceAll("%",target); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,99 @@ |
|||
package com.kms.warn; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|||
import com.kms.build.domain.BsSgcJsjdBuiChange; |
|||
import com.kms.build.domain.BsSgcJsjdBuiConstrMeas; |
|||
import com.kms.build.domain.BsSgcJsjdBuiGzbzj; |
|||
import com.kms.build.domain.BsSgcJsjdBuiSalaryEnsure; |
|||
import com.kms.build.service.BsSgcJsjdBuiChangeService; |
|||
import com.kms.build.service.BsSgcJsjdBuiConstrMeasService; |
|||
import com.kms.build.service.BsSgcJsjdBuiSalaryEnsureService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.context.annotation.Configuration; |
|||
import org.springframework.scheduling.annotation.Async; |
|||
|
|||
import java.math.BigDecimal; |
|||
import java.nio.charset.StandardCharsets; |
|||
import java.text.ParseException; |
|||
import java.text.SimpleDateFormat; |
|||
import java.util.Date; |
|||
|
|||
@Async |
|||
@Configuration |
|||
public class WarningJudgment<T> { |
|||
|
|||
@Autowired |
|||
WarnOperate warnOperate; |
|||
|
|||
@Autowired |
|||
BsSgcJsjdBuiSalaryEnsureService bsSgcJsjdBuiSalaryEnsureService; |
|||
@Autowired |
|||
BsSgcJsjdBuiConstrMeasService bsSgcJsjdBuiConstrMeasService; |
|||
@Autowired |
|||
BsSgcJsjdBuiChangeService bsSgcJsjdBuiChangeService; |
|||
|
|||
/** |
|||
* 农民工工资保证金预警 |
|||
* @param |
|||
* @param warnType |
|||
*/ |
|||
public void salaryEnsureWarn(BsSgcJsjdBuiSalaryEnsure salaryEnsure, WarnType warnType){ |
|||
String proCode = salaryEnsure.getProCode(); |
|||
String proNo = salaryEnsure.getProNo(); |
|||
BsSgcJsjdBuiConstrMeas one = bsSgcJsjdBuiConstrMeasService.getOne(Wrappers.lambdaQuery(BsSgcJsjdBuiConstrMeas.class) |
|||
.eq(BsSgcJsjdBuiConstrMeas::getProCode, proCode) |
|||
.eq(BsSgcJsjdBuiConstrMeas::getProNo, proNo),false); |
|||
Date reportTime1 = one.getReportTime1(); |
|||
Date createTime = salaryEnsure.getCreateTime(); |
|||
try { |
|||
Date workDayStart = HolidayUtil.getWorkDayStart(null, createTime, 20); |
|||
if(workDayStart.compareTo(reportTime1)>0){ |
|||
warnOperate.sendWarn(proNo,proCode,warnType,warnType.getWarnResult()); |
|||
} |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 农名工工资保证金专用账户预警 |
|||
* @param |
|||
* @param warnType |
|||
*/ |
|||
public void GzbzjWarn(BsSgcJsjdBuiGzbzj bsSgcJsjdBuiGzbzj, WarnType warnType){ |
|||
String proNo = bsSgcJsjdBuiGzbzj.getProNo(); |
|||
String projectCode = bsSgcJsjdBuiGzbzj.getProjectCode(); |
|||
String balance = bsSgcJsjdBuiGzbzj.getBalance(); |
|||
String monthAmountTransferred = bsSgcJsjdBuiGzbzj.getMonthAmountTransferred(); |
|||
BigDecimal subtract = new BigDecimal(balance).subtract(new BigDecimal(monthAmountTransferred)); |
|||
if(subtract.compareTo(new BigDecimal(0))<=0){ //余额小于0
|
|||
warnOperate.sendWarn(proNo,projectCode,warnType, warnType.replaceString(warnType.getWarnResult(),subtract.toString())); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 标段变更预警 |
|||
*/ |
|||
public void ChangeWarn(BsSgcJsjdBuiChange bsSgcJsjdBuiChange,WarnType warnType){ |
|||
String proCode = bsSgcJsjdBuiChange.getProCode(); |
|||
String proNo = bsSgcJsjdBuiChange.getProNo(); |
|||
QueryWrapper<BsSgcJsjdBuiChange> query = Wrappers.query(); |
|||
query.lambda().eq(BsSgcJsjdBuiChange::getProCode,proCode) |
|||
.eq(BsSgcJsjdBuiChange::getProNo,proNo); |
|||
int count = bsSgcJsjdBuiChangeService.count(query); |
|||
if(count>20){ |
|||
warnOperate.sendWarn(proNo,proCode,warnType, warnType.replaceString(warnType.getWarnResult(),String.valueOf(count))); |
|||
return; |
|||
} |
|||
query.lambda().eq(BsSgcJsjdBuiChange::getChangeType,"1"); |
|||
int count1 = bsSgcJsjdBuiChangeService.count(query); |
|||
if(count1>10){ |
|||
warnOperate.sendWarn(proNo,proCode,warnType, warnType.replaceString(warnType.getOtherResult(),String.valueOf(count))); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
Loading…
Reference in new issue