From ecd5881b1054a222963b9764b865b489918c5971 Mon Sep 17 00:00:00 2001 From: xd <844539747@qq.com> Date: Wed, 19 Jun 2024 17:06:26 +0800 Subject: [PATCH] '123123123' --- .../web/controller/quot/QuotController.java | 132 +++++++++++------- .../com/ruoyi/common/utils/DateUtils.java | 77 +++++++++- 2 files changed, 155 insertions(+), 54 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/quot/QuotController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/quot/QuotController.java index 34d48a3..74b8de6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/quot/QuotController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/quot/QuotController.java @@ -1,7 +1,9 @@ package com.ruoyi.web.controller.quot; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletResponse; @@ -375,68 +377,92 @@ public class QuotController extends BaseController @PostMapping("/commitQuot") public AjaxResult commitQuot(@RequestBody Quot quot) { - // 获取用户角色 --判断是否是核价组角色 - Boolean hjRoleFlag = false; - List roles = SecurityUtils.getLoginUser().getUser().getRoles(); - for(SysRole sysRole:roles){ - String roleKey = sysRole.getRoleKey(); - if("PRICE_VERIFICATION".equals(roleKey) || "QUOT".equals(roleKey)){ - hjRoleFlag = true; - break; + try{ + // 获取用户角色 --判断是否是核价组角色 + Boolean hjRoleFlag = false; + List roles = SecurityUtils.getLoginUser().getUser().getRoles(); + for(SysRole sysRole:roles){ + String roleKey = sysRole.getRoleKey(); + if("PRICE_VERIFICATION".equals(roleKey) || "QUOT".equals(roleKey)){ + hjRoleFlag = true; + break; + } } - } - if(!hjRoleFlag){ - // 每天限制提交200条 - String quotCommitCount = configService.selectConfigByKey("quot.commit.count"); - String count = quotService.selectQuotListCount(); - if(Integer.valueOf(count)>=Integer.valueOf(quotCommitCount)){ - return error("当前报价量已达极限,无法继续提供报价单"); + if(!hjRoleFlag){ + // 每天限制提交200条 + String quotCommitCount = configService.selectConfigByKey("quot.commit.count"); + String count = quotService.selectQuotListCount(); + if(Integer.valueOf(count)>=Integer.valueOf(quotCommitCount)){ + return error("当前报价量已达极限,无法继续提供报价单"); + } + + // 提交报价时间限制 + String commitQuotTime = configService.selectConfigByKey("quot.allow.commitQuotTime"); + if(commitQuotTime.indexOf("-")<0){ + return error("提交报价时间限制系统参数错误,格式不规范"); + } + String startTime = commitQuotTime.split("-")[0]; + String endTime = commitQuotTime.split("-")[1]; + if(!DateUtils.isMatch(startTime) || !DateUtils.isMatch(endTime)){ + return error("提交报价时间限制系统参数错误,格式不规范"); + } + + //当前时间 + Date date = new Date(); + String currentTime = new SimpleDateFormat("HH:mm:ss").format(date); + Date nowTime = new SimpleDateFormat("HH:mm:ss").parse(currentTime); + Date startTimeD = new SimpleDateFormat("HH:mm:ss").parse(startTime); + Date endTimeE = new SimpleDateFormat("HH:mm:ss").parse(endTime); + Boolean flag = DateUtils.isEffectiveDate(nowTime,startTimeD,endTimeE); + if(!flag){ + return error("已超过提交报价限制时间【"+commitQuotTime+"】,无法继续提交"); + } } - // 提交报价时间限制 - } + String quot_id = quot.getQuotId(); - String quot_id = quot.getQuotId(); + quot.setUpdateBy(getUsername()); + quot.setQuotApprovalStatus("1");//报价单 状态设置为 协助中 + quot.setQuotInquiryDate(DateUtils.getNowDate());//报价单 询价日期设置为 当前日期 - quot.setUpdateBy(getUsername()); - quot.setQuotApprovalStatus("1");//报价单 状态设置为 协助中 - quot.setQuotInquiryDate(DateUtils.getNowDate());//报价单 询价日期设置为 当前日期 - - // 校验 是否已有重复报价单(客户+项目名) - Boolean flag = false; - if(!hjRoleFlag){ - flag = quotService.checkExistQuot(getUsername(),quot.getQuotCustomerBm(),quot.getQuotProject()); - }else{ - flag = quotService.checkExistQuot(quot.getQuotSalesmanCode(),quot.getQuotCustomerBm(),quot.getQuotProject()); - } - if(flag){ - return error("存在相同客户且项目名称一致的报价单,无法提交"); - } - - if(StringUtils.isEmpty(quot_id)){ - quot.setQuotId(UUID.fastUUID().toString()); - //quot.setQuotCode(IdUtils.createNo("BJD_",0)); - String quotCode = quotService.getCode("BJD"); - quot.setQuotCode(quotCode); - - if(hjRoleFlag){ - quot.setCreateBy(quot.getQuotSalesmanCode()); + // 校验 是否已有重复报价单(客户+项目名) + Boolean flag = false; + if(!hjRoleFlag){ + flag = quotService.checkExistQuot(getUsername(),quot.getQuotCustomerBm(),quot.getQuotProject()); }else{ - quot.setCreateBy(getUsername()); + flag = quotService.checkExistQuot(quot.getQuotSalesmanCode(),quot.getQuotCustomerBm(),quot.getQuotProject()); } - //quot.setQuotSalesmanCode(getUsername()); - quotService.insertQuot(quot); - //sendNoticeToBjz(quot); - return success(); - }else{ - if(hjRoleFlag){ - quot.setUpdateBy(quot.getQuotSalesmanCode()); + if(flag){ + return error("存在相同客户且项目名称一致的报价单,无法提交"); + } + + if(StringUtils.isEmpty(quot_id)){ + quot.setQuotId(UUID.fastUUID().toString()); + //quot.setQuotCode(IdUtils.createNo("BJD_",0)); + String quotCode = quotService.getCode("BJD"); + quot.setQuotCode(quotCode); + + if(hjRoleFlag){ + quot.setCreateBy(quot.getQuotSalesmanCode()); + }else{ + quot.setCreateBy(getUsername()); + } + //quot.setQuotSalesmanCode(getUsername()); + quotService.insertQuot(quot); + //sendNoticeToBjz(quot); + return success(); }else{ - quot.setUpdateBy(getUsername()); + if(hjRoleFlag){ + quot.setUpdateBy(quot.getQuotSalesmanCode()); + }else{ + quot.setUpdateBy(getUsername()); + } + quotService.updateQuot(quot); + //sendNoticeToBjz(quot); + return success(); } - quotService.updateQuot(quot); - //sendNoticeToBjz(quot); - return success(); + }catch (Exception e){ + return error("系统异常"); } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 5905cb3..8fd8124 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -5,7 +5,11 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.*; import java.time.temporal.ChronoUnit; +import java.util.Calendar; import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.commons.lang3.time.DateFormatUtils; /** @@ -204,8 +208,79 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return Integer.parseInt(String.valueOf(secondsLeft)); } + /** + * 判断当前时间是否在[startTime, endTime]区间,注意时间格式要一致 + * + * @param nowTime 当前时间 + * @param startTime 开始时间 + * @param endTime 结束时间 + * @return + */ + public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) { + if (nowTime.getTime() == startTime.getTime() + || nowTime.getTime() == endTime.getTime()) { + return true; + } + + Calendar date = Calendar.getInstance(); + date.setTime(nowTime); + + Calendar begin = Calendar.getInstance(); + begin.setTime(startTime); + + Calendar end = Calendar.getInstance(); + end.setTime(endTime); + + if (date.after(begin) && date.before(end)) { + return true; + } else { + return false; + } + } + + /** + * 是否满足时分秒时间格式 + * @param inputString + * @return + */ + public static boolean isMatch(String inputString) { + String timeRegex = "^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"; + Pattern pattern = Pattern.compile(timeRegex); + Matcher matcher = pattern.matcher(inputString); + return matcher.matches(); + } + public static void main(String[] args) { - System.out.println(secondsUntilMidnight()); + + try{ + String format = "HH:mm:ss"; + + Date date = new Date(); + String currentTime = new SimpleDateFormat(format).format(date); + + Date nowTime = new SimpleDateFormat(format).parse(currentTime); + Date startTime = new SimpleDateFormat(format).parse("7:00:00"); + Date endTime = new SimpleDateFormat(format).parse("19:00:00"); + System.out.println(isEffectiveDate(nowTime, startTime, endTime)); + + + String inputString = "7:34:56"; + String timeRegex = "^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"; + + Pattern pattern = Pattern.compile(timeRegex); + Matcher matcher = pattern.matcher(inputString); + + if (matcher.matches()) { + System.out.println("输入的字符串是时分秒格式"); + } else { + System.out.println("输入的字符串不是时分秒格式"); + } + + }catch (Exception e){ + e.printStackTrace(); + } + + } }