【定时任务】供应商和注册证预警发送邮件
This commit is contained in:
		
							parent
							
								
									74b3cc43ac
								
							
						
					
					
						commit
						dbf6caad5e
					
				|  | @ -5,41 +5,67 @@ import kd.bos.dataentity.entity.DynamicObject; | |||
| import kd.bos.exception.KDException; | ||||
| import kd.bos.logging.Log; | ||||
| import kd.bos.logging.LogFactory; | ||||
| import kd.bos.message.api.EmailInfo; | ||||
| import kd.bos.message.service.handler.EmailHandler; | ||||
| import kd.bos.orm.query.QCP; | ||||
| import kd.bos.orm.query.QFilter; | ||||
| import kd.bos.schedule.executor.AbstractTask; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| import kd.bos.workflow.engine.msg.info.MessageAttachment; | ||||
| import kd.sdk.plugin.Plugin; | ||||
| import org.apache.commons.lang3.StringUtils; | ||||
| import tqq9.lc123.cloud.app.plugin.operate.sys.ValiddaysSavePlugin; | ||||
| import tqq9.lc123.cloud.app.plugin.utils.ConfigUtils; | ||||
| import tqq9.lc123.cloud.app.plugin.utils.DateDifferenceCalculator; | ||||
| import tqq9.lc123.cloud.app.plugin.utils.EmailUtils; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import static kd.bos.mvc.form.TitleField.number; | ||||
| 
 | ||||
| /** | ||||
|  * 后台任务插件 | ||||
|  * 供应商、注册证证照时间到期时间计算并发送预警邮件 | ||||
|  */ | ||||
| public class DaysRemaining extends AbstractTask implements Plugin { | ||||
|     private final static Log logger = LogFactory.getLog(DaysRemaining.class); | ||||
| 
 | ||||
|     @Override | ||||
|     public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException { | ||||
|         DynamicObject[] suppliers = BusinessDataServiceHelper.load("bd_supplier", "" + | ||||
|         int warnDays = 0; | ||||
|         String warnDaysStr = ConfigUtils.getDevSysConfigByNumber("WARN_LICENCE_DAYS");//预警天数 | ||||
|         if(StringUtils.isNotBlank(warnDaysStr)){ | ||||
|             warnDays = Integer.valueOf(warnDaysStr); | ||||
|         } | ||||
|         //供应商 | ||||
|         QFilter f1 = new QFilter("enable", QCP.equals, "1"); | ||||
|         QFilter f2 = new QFilter("status", QCP.equals, "C"); | ||||
|         DynamicObject[] suppliers = BusinessDataServiceHelper.load("bd_supplier", | ||||
|                 "id,number,name,tqq9_datefield1,tqq9_validdays_ylqxsc,tqq9_datefield21,tqq9_validdays_ylqxjy,tqq9_datefield4,tqq9_validdays_ylqxjy2,tqq9_datefield22," + | ||||
|                 "tqq9_validdays_yljg,tqq9_licenseenddate,tqq9_validdays_hzp,tqq9_zlbzxyyxqz,tqq9_validdays_zlbz,tqq9_datefield2,tqq9_validdays_gmp,tqq9_datefield7," + | ||||
|                 "tqq9_validdays_frsq,tqq9_datefield9,tqq9_validdays_yyzz,tqq9_gspyxqz,tqq9_validdays_gsp,tqq9_minvaliddays", null); | ||||
|                 "tqq9_validdays_frsq,tqq9_datefield9,tqq9_validdays_yyzz,tqq9_gspyxqz,tqq9_validdays_gsp,tqq9_minvaliddays,creator.email", | ||||
|                 new QFilter[]{f1, f2}); | ||||
|         Date currentDate = new Date();//当前日期 | ||||
|         Long remainingDays = null; | ||||
|         for (DynamicObject supplier : suppliers) { | ||||
|             String number = supplier.getString("number");//供应商编码 | ||||
|             String name = supplier.getString("name");//供应商名称 | ||||
|             int remainingDays = 0; | ||||
|             StringBuilder sb = new StringBuilder(); | ||||
|             //医疗器械生生产许可证 | ||||
|             Date tqq9_datefield1 = supplier.getDate("tqq9_datefield1");//失效日期 | ||||
|             if (tqq9_datefield1 != null) { | ||||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield1, currentDate); | ||||
|                 supplier.set("tqq9_validdays_ylqxsc", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("医疗器械生生产许可证距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //医疗器械经营许可证 | ||||
|  | @ -48,9 +74,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield21, currentDate); | ||||
|                 supplier.set("tqq9_validdays_ylqxjy", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("医疗器械经营许可证距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //第二类医疗器械经营备案凭证 | ||||
|  | @ -59,9 +88,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield4, currentDate); | ||||
|                 supplier.set("tqq9_validdays_ylqxjy2", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("第二类医疗器械经营备案凭证距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|  | @ -71,9 +103,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield22, currentDate); | ||||
|                 supplier.set("tqq9_validdays_yljg", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("医疗机构执行许可证距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //化妆品许可证 | ||||
|  | @ -82,9 +117,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_licenseenddate, currentDate); | ||||
|                 supplier.set("tqq9_validdays_hzp", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("化妆品许可证距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //质量保证书 | ||||
|  | @ -93,9 +131,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_zlbzxyyxqz, currentDate); | ||||
|                 supplier.set("tqq9_validdays_zlbz", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("质量保证书距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //GMP证书 | ||||
|  | @ -104,9 +145,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield2, currentDate); | ||||
|                 supplier.set("tqq9_validdays_gmp", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("GMP证书距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //法人委托授权书 | ||||
|  | @ -115,9 +159,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield7, currentDate); | ||||
|                 supplier.set("tqq9_validdays_frsq", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("法人委托授权书距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //营业执照 | ||||
|  | @ -126,9 +173,12 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_datefield9, currentDate); | ||||
|                 supplier.set("tqq9_validdays_yyzz", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("营业执照距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
|             //GSP证书 | ||||
|  | @ -137,24 +187,54 @@ public class DaysRemaining extends AbstractTask implements Plugin { | |||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_gspyxqz, currentDate); | ||||
|                 supplier.set("tqq9_validdays_gsp", remainingDays); | ||||
|                 Long tqq9_minvaliddays = supplier.getLong("tqq9_minvaliddays"); | ||||
|                 if (Long.compare(remainingDays, tqq9_minvaliddays) < 0) { | ||||
|                 if (remainingDays < tqq9_minvaliddays) { | ||||
|                     supplier.set("tqq9_minvaliddays", remainingDays); | ||||
| 
 | ||||
|                 } | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //与预警天数进行对比 | ||||
|                     sb.append("GSP证书距离过期时间还剩余 " + remainingDays + " 天。"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             //发送邮件 | ||||
|             if(StringUtils.isNotBlank(sb.toString())){ | ||||
|                 DynamicObject creator = supplier.getDynamicObject("creator");//创建人 | ||||
|                 if(creator != null){ | ||||
|                     String emailAddress = creator.getString("email");//创建人邮箱 | ||||
|                     if(StringUtils.isNotBlank(emailAddress)){ | ||||
|                         String warnStr = "供应商【编码:"+number+",名称:"+name+"】证照到期提醒:"+ sb; | ||||
|                         EmailUtils.sendEmail(emailAddress, warnStr, "供应商证照到期提醒"); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         DynamicObject[] tqq9_registration = BusinessDataServiceHelper.load("tqq9_registration", "id,number,name,tqq9_enddate,tqq9_validdays", null); | ||||
| 
 | ||||
|         //注册证 | ||||
|         DynamicObject[] tqq9_registration = BusinessDataServiceHelper.load("tqq9_registration", | ||||
|                 "id,number,name,tqq9_enddate,tqq9_validdays,creator.email", | ||||
|                 new QFilter[]{f1, f2}); | ||||
|         for (DynamicObject dynamicObject : tqq9_registration) { | ||||
|             String number = dynamicObject.getString("number"); | ||||
|             String name = dynamicObject.getString("name"); | ||||
| 
 | ||||
|             //商品注册证 | ||||
|             Date tqq9_enddate = dynamicObject.getDate("tqq9_enddate");//失效日期 | ||||
|             if (tqq9_enddate != null) { | ||||
|                 remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_enddate, currentDate); | ||||
|                 int remainingDays = DateDifferenceCalculator.calculateRemainingDays(tqq9_enddate, currentDate); | ||||
|                 dynamicObject.set("tqq9_validdays", remainingDays); | ||||
|                 if(remainingDays <= warnDays){ | ||||
|                     //商品注册证 | ||||
|                     String warnStr = "商品注册证【编码:"+number+",名称:"+name+"】证照到期提醒:距离过期时间还剩余 " + remainingDays + " 天。"; | ||||
|                     DynamicObject creator = dynamicObject.getDynamicObject("creator"); | ||||
|                     if(creator != null){ | ||||
|                         String emailAddress = creator.getString("email"); | ||||
|                         EmailUtils.sendEmail(emailAddress, warnStr, "商品注册证到期提醒"); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         SaveServiceHelper.save(suppliers); | ||||
|         SaveServiceHelper.save(tqq9_registration); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,58 @@ | |||
| package tqq9.lc123.cloud.app.plugin.utils; | ||||
| 
 | ||||
| import kd.bos.dataentity.entity.DynamicObject; | ||||
| import kd.bos.message.api.EmailInfo; | ||||
| import kd.bos.message.service.handler.EmailHandler; | ||||
| import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||
| import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| /** | ||||
|  * 发送邮件工具类 | ||||
|  */ | ||||
| public class EmailUtils { | ||||
| 
 | ||||
|     // 发送邮件 | ||||
|     public static void sendEmail(String emailAddress, String warnStr, String title) { | ||||
|         EmailInfo emailInfo = new EmailInfo(); | ||||
|         emailInfo.setTitle(title); | ||||
|         emailInfo.setContent(warnStr); | ||||
|         List<String> receiver = new ArrayList<>(); | ||||
|         receiver.add(emailAddress);//接收人地址 | ||||
|         emailInfo.setReceiver(receiver); | ||||
|         Map<String, Object> map = EmailHandler.sendEmail(emailInfo); | ||||
|         boolean result = (Boolean) map.get("result"); | ||||
|         emailLog(title, emailAddress, result, warnStr, new Date(), map); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     /** | ||||
|      * 记录发送邮件日志 | ||||
|      * @param title | ||||
|      * @param rec | ||||
|      * @param success | ||||
|      * @param content | ||||
|      * @param sendTime | ||||
|      * @param map | ||||
|      */ | ||||
|     public static void emailLog(String title, String rec, boolean success, String content, Date sendTime, Map<String, Object> map){ | ||||
|         String sender = ConfigUtils.getDevSysConfigByNumber("MAIL_SENDER_ADDR"); | ||||
|         DynamicObject log = BusinessDataServiceHelper.newDynamicObject("tqq9_emaillog"); | ||||
|         log.set("number", sendTime.getTime()); | ||||
|         log.set("name", title); | ||||
|         log.set("tqq9_sender", sender); | ||||
|         log.set("tqq9_rec", rec); | ||||
|         log.set("tqq9_content", content.substring(0,40)); | ||||
|         log.set("tqq9_content_tag", content); | ||||
|         log.set("tqq9_success", success); | ||||
|         log.set("tqq9_result", map.toString()); | ||||
|         log.set("enable", "1"); | ||||
|         log.set("status", "C"); | ||||
|         SaveServiceHelper.save(new DynamicObject[]{log}); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
		Reference in New Issue