|
|
@@ -0,0 +1,127 @@
|
|
|
+package com.lc.ibps.platform.plan.job;
|
|
|
+
|
|
|
+import com.lc.ibps.base.core.util.AppUtil;
|
|
|
+import com.lc.ibps.base.core.util.BeanUtils;
|
|
|
+import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
+import com.lc.ibps.cloud.message.util.MessageQueueProductorUtil;
|
|
|
+import jodd.util.StringUtil;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class ReagentsConsumablesJob extends AbstractJob {
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(EquipmentMaintenancePlanJob.class);
|
|
|
+ private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+ //step1: 查询出所有的数据
|
|
|
+ List<Map<String, Object>> queryParam = queryData(context);
|
|
|
+ //step2: 删选出值需要发消息的数据
|
|
|
+ List<Map<String, Object>> list = screening(queryParam);
|
|
|
+ //开始发送消息
|
|
|
+ sendMessage(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private List<Map<String, Object>> queryData(JobExecutionContext context) {
|
|
|
+ logger.warn("group={} job={} trigger={} is running.",
|
|
|
+ context.getJobDetail().getKey().getGroup(),
|
|
|
+ context.getJobDetail().getKey().getName(),
|
|
|
+ context.getTrigger().getKey().getName());
|
|
|
+ String querySql = "select id_,di_dian_,bian_zhi_bu_men_,bian_hao_,ming_cheng_,bian_ma_,pi_hao_,xiao_qi_,fa_song_xiao_xi_ from t_sjhxhclrkysdjbzb where xiao_qi_ <> null and xiao_qi_ is not null";
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(querySql);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Map<String, Object>> screening(List<Map<String, Object>> queryParam) {
|
|
|
+ List<Map<String, Object>> arrayList = new ArrayList<>();
|
|
|
+ if (BeanUtils.isEmpty(queryParam)) {
|
|
|
+ for (Map<String, Object> item : queryParam) {
|
|
|
+ Map<String, Object> map = calculation(item);
|
|
|
+ boolean b = BeanUtils.isEmpty(map);
|
|
|
+ if (b) {
|
|
|
+ arrayList.add(map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return arrayList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> calculation(Map<String, Object> map) {
|
|
|
+ // 1. 参数校验
|
|
|
+ if (map == null || !map.containsKey("xiao_qi_")) { //|| !map.containsKey("fa_song_xiao_xi_") )
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 2. 获取并验证是否已发送消息
|
|
|
+ String isFs = map.get("fa_song_xiao_xi_").toString();
|
|
|
+ if ("1".equals(isFs)) {
|
|
|
+ logger.warn("当前试剂已发送过消息提醒 id=={}", map.get("id_").toString());
|
|
|
+ return null; // 已经发送过消息
|
|
|
+ }
|
|
|
+ // 3. 解析有效期日期
|
|
|
+ String xiaoQi = map.get("xiao_qi_").toString();
|
|
|
+ LocalDate expiryDate = LocalDate.parse(xiaoQi, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
+ // 4. 获取当前日期(不含时间)
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+ // 5. 检查是否已过期
|
|
|
+ if (currentDate.isAfter(expiryDate)) {
|
|
|
+ logger.warn("当前试剂的已经过期 id=={}", map.get("id_").toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 6. 计算一个月前的日期
|
|
|
+ LocalDate oneMonthBeforeExpiry = expiryDate.minusMonths(1);
|
|
|
+ // 7. 检查是否在提醒窗口期内
|
|
|
+ if (currentDate.isAfter(oneMonthBeforeExpiry)) {
|
|
|
+ logger.warn("当前试剂即将过期,需要发送消息提醒 id=={}", map.get("id_").toString());
|
|
|
+ //获取当前部门下的所有技术员
|
|
|
+ Map<String, Object> allJSY = findAllJSY(map);
|
|
|
+ return allJSY; // 在提醒窗口期内,需要发送消息
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> findAllJSY(Map<String, Object> map) {
|
|
|
+ String buMen = map.get("bian_zhi_bu_men_").toString();
|
|
|
+ String sql = "select em.ID_ from ibps_party_employee em join ibps_party_user_role ur on em.ID_ = ur.USER_ID_ join ibps_party_role ro on ur.ROLE_ID_ = ro.ID_ where ro.ROLE_ALIAS_ = 'jcys' and em.POSITIONS_ like '%%s%%'";
|
|
|
+ sql = String.format(sql, buMen);
|
|
|
+ List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ String result = list.stream().map(m -> m.get("ID").toString()).collect(Collectors.joining(","));
|
|
|
+ map.put("user", result);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendMessage(List<Map<String, Object>> list){
|
|
|
+ if(BeanUtils.isEmpty(list)){
|
|
|
+ for (Map<String,Object> item : list) {
|
|
|
+ //转换接收人
|
|
|
+ String user = item.get("user").toString();
|
|
|
+ List<String> receiver = Arrays.asList(user.split(","));
|
|
|
+ //拼接title
|
|
|
+ String title = "【入库编号:" + item.get("bian_hao_").toString() + "-试剂耗材名称:" + item.get("ming_cheng_").toString() + "】的即将过期通知" ;
|
|
|
+ //拼接内容
|
|
|
+ String neiRong = "入库编号:" + item.get("bian_hao_").toString() + "-试剂耗材名称:" + item.get("ming_cheng_").toString() +
|
|
|
+ "-编码:" + item.get("bian_ma_").toString() + "-批号:" + item.get("pi_hao_") + "-有效期:" + item.get("xiao_qi_").toString() +
|
|
|
+ "的试剂耗材即将过期,请及时处理";
|
|
|
+ MessageQueueProductorUtil.send("ReagentsConsumablesJob", "system" , "inner"
|
|
|
+ , receiver,null , title, neiRong, null, null, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|