Browse Source

预警

dev_kxc
ljf 1 year ago
parent
commit
aa2b22f756
  1. 2
      jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiAttendanceInformationController.java
  2. 11
      jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiChangeController.java
  3. 9
      jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiGzbzjController.java
  4. 9
      jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiSalaryEnsureController.java
  5. 1
      jwtech-system/src/main/java/com/kms/build/domain/BsSgcJsjdBuiDjjgd.java
  6. 230
      jwtech-system/src/main/java/com/kms/warn/HolidayUtil.java
  7. 46
      jwtech-system/src/main/java/com/kms/warn/TaskPoolConfig.java
  8. 59
      jwtech-system/src/main/java/com/kms/warn/WarnOperate.java
  9. 50
      jwtech-system/src/main/java/com/kms/warn/WarnType.java
  10. 99
      jwtech-system/src/main/java/com/kms/warn/WarningJudgment.java

2
jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiAttendanceInformationController.java

@ -165,7 +165,7 @@ public class BsSgcJsjdBuiAttendanceInformationController extends BaseController
@ApiOperation("农民工人员考勤信息模板生成")
public AjaxResult tagTemplate() {
ExcelUtil<BsSgcJsjdBuiAttendanceInformationExcel> util = new ExcelUtil<>(BsSgcJsjdBuiAttendanceInformationExcel.class);
return util.importTemplateExcel("农民工人员考勤信息导入模板");
return util.exportExcel(null,"农民工人员考勤信息导入模板");
}
}

11
jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiChangeController.java

@ -11,6 +11,8 @@ import com.kms.build.service.BsSgcJsjdBuiChangeService;
import com.kms.common.utils.BaseEntityUtils;
import com.kms.warn.WarnType;
import com.kms.warn.WarningJudgment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -46,6 +48,9 @@ public class BsSgcJsjdBuiChangeController extends BaseController
@Autowired
private BsSgcJsjdBuiChangeService bsSgcJsjdBuiChangeService;
@Autowired
WarningJudgment warningJudgment;
/**
* 查询变更信息管理列表
*/
@ -88,7 +93,11 @@ public class BsSgcJsjdBuiChangeController extends BaseController
public AjaxResult add(@RequestBody BsSgcJsjdBuiChange bsSgcJsjdBuiChange)
{
BaseEntityUtils.preInsert(bsSgcJsjdBuiChange);
return toAjax(bsSgcJsjdBuiChangeService.save(bsSgcJsjdBuiChange));
boolean save = bsSgcJsjdBuiChangeService.save(bsSgcJsjdBuiChange);
if(save){
warningJudgment.ChangeWarn(bsSgcJsjdBuiChange, WarnType.SECTION_CHANGES);
}
return toAjax(save);
}
/**

9
jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiGzbzjController.java

@ -11,6 +11,8 @@ import com.kms.build.service.BsSgcJsjdBuiGzbzjService;
import com.kms.common.utils.BaseEntityUtils;
import com.kms.warn.WarnType;
import com.kms.warn.WarningJudgment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -46,6 +48,9 @@ public class BsSgcJsjdBuiGzbzjController extends BaseController
@Autowired
private BsSgcJsjdBuiGzbzjService bsSgcJsjdBuiGzbzjService;
@Autowired
WarningJudgment warningJudgment;
/**
* 查询工资保证金列表
*/
@ -88,7 +93,9 @@ public class BsSgcJsjdBuiGzbzjController extends BaseController
public AjaxResult add(@RequestBody BsSgcJsjdBuiGzbzj bsSgcJsjdBuiGzbzj)
{
BaseEntityUtils.preInsert(bsSgcJsjdBuiGzbzj);
return toAjax(bsSgcJsjdBuiGzbzjService.save(bsSgcJsjdBuiGzbzj));
AjaxResult ajaxResult = toAjax(bsSgcJsjdBuiGzbzjService.save(bsSgcJsjdBuiGzbzj));
warningJudgment.GzbzjWarn(bsSgcJsjdBuiGzbzj, WarnType.SALARY_DEPOSIT);
return ajaxResult;
}
/**

9
jwtech-system/src/main/java/com/kms/build/controller/BsSgcJsjdBuiSalaryEnsureController.java

@ -9,6 +9,8 @@ import com.jianwei.common.utils.poi.ExcelUtil;
import com.kms.common.utils.BaseEntityUtils;
import com.kms.warn.WarnType;
import com.kms.warn.WarningJudgment;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,6 +47,9 @@ public class BsSgcJsjdBuiSalaryEnsureController extends BaseController
@Autowired
private BsSgcJsjdBuiSalaryEnsureService bsSgcJsjdBuiSalaryEnsureService;
@Autowired
WarningJudgment warningJudgment;
/**
* 查询工资保证金账户管理列表
*/
@ -87,7 +92,9 @@ public class BsSgcJsjdBuiSalaryEnsureController extends BaseController
public AjaxResult add(@RequestBody BsSgcJsjdBuiSalaryEnsure bsSgcJsjdBuiSalaryEnsure)
{
BaseEntityUtils.preInsert(bsSgcJsjdBuiSalaryEnsure);
return toAjax(bsSgcJsjdBuiSalaryEnsureService.save(bsSgcJsjdBuiSalaryEnsure));
boolean save = bsSgcJsjdBuiSalaryEnsureService.save(bsSgcJsjdBuiSalaryEnsure);
warningJudgment.salaryEnsureWarn(bsSgcJsjdBuiSalaryEnsure,WarnType.MARGIN_PAYMENT_TIME);
return toAjax(save);
}
/**

1
jwtech-system/src/main/java/com/kms/build/domain/BsSgcJsjdBuiDjjgd.java

@ -55,6 +55,5 @@ public class BsSgcJsjdBuiDjjgd extends BaseEntity
@ApiModelProperty("附件")
private String attachment;
private String remark;
}

230
jwtech-system/src/main/java/com/kms/warn/HolidayUtil.java

@ -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;
}
}

46
jwtech-system/src/main/java/com/kms/warn/TaskPoolConfig.java

@ -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;
}
}

59
jwtech-system/src/main/java/com/kms/warn/WarnOperate.java

@ -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;
}
}

50
jwtech-system/src/main/java/com/kms/warn/WarnType.java

@ -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);
}
}

99
jwtech-system/src/main/java/com/kms/warn/WarningJudgment.java

@ -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…
Cancel
Save