|
|
@@ -0,0 +1,206 @@
|
|
|
+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.core.util.Collections;
|
|
|
+import com.lc.ibps.base.framework.table.ICommonDao;
|
|
|
+import com.lc.ibps.cloud.message.util.MessageQueueProductorUtil;
|
|
|
+import org.quartz.JobExecutionContext;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class ReceptionRegistrationJob extends AbstractJob{
|
|
|
+//重启急救室间质评接收登记消息提醒(垃圾需求,真垃圾)
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ReceptionRegistrationJob.class);
|
|
|
+
|
|
|
+ private ICommonDao<?> commonDao = AppUtil.getBean(ICommonDao.class);
|
|
|
+
|
|
|
+ private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+
|
|
|
+ private static final String zhuZhang = "1040905508338270208";//专业组组长角色id
|
|
|
+
|
|
|
+ private static final String zhiLiang = "1040711374352678912"; //质量负责人
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void executeJob(JobExecutionContext context) throws Exception {
|
|
|
+ //1.查找子表所有的数据
|
|
|
+ List<Map<String, Object>> list = selectAll();
|
|
|
+
|
|
|
+ //2.提出不需要的
|
|
|
+ List<Map<String, Object>> screening = screening(list);
|
|
|
+
|
|
|
+ //3组装发消息的数据
|
|
|
+ List<Map<String, Object>> data = buildData(screening);
|
|
|
+
|
|
|
+ //4发送消息
|
|
|
+ sendMsg(data);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map<String,Object>> selectAll(){
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ String sql = " select z.zi_biao_bu_men_,f.di_dian_,z.shang_bao_shi_jia,z.huo_dong_ming_che,z.shi_jian_zhi_ping from t_sjzkwjsdjxqb z join t_sjzkwjsdjb f on z.parent_id_ = f.id_ where shang_bao_shi_jia <> '' ";
|
|
|
+ list = (List<Map<String, Object>> ) commonDao.query(sql);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map<String,Object>> screening(List<Map<String,Object>> selectAll) {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ if(Collections.isNotEmpty(selectAll)){
|
|
|
+ for (Map<String, Object> item :selectAll ) {
|
|
|
+ String date = verificationDate(item.get("shang_bao_shi_jia").toString());
|
|
|
+ if("1".equals(date)||"7".equals(date)){
|
|
|
+ list.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<Map<String, Object>> buildData(List<Map<String, Object>> screening) {
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();//
|
|
|
+ if(Collections.isNotEmpty(screening)){
|
|
|
+ //先获取去重后的所有部门
|
|
|
+ List<String> buMens = screening.stream()
|
|
|
+ .filter(map -> map != null && map.containsKey("zi_biao_bu_men_") && map.get("zi_biao_bu_men_") != null)
|
|
|
+ .map(map -> map.get("zi_biao_bu_men_").toString()) // 转换为String
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ //依据部门去找各个组的组长
|
|
|
+ List<Map<String, Object>> zhuZhang = findZhuZhang(buMens);
|
|
|
+ //还需要给质量负责人也发送一条完整的消息
|
|
|
+ List<Map<String, Object>> zhiLiang = findZhiLiang();
|
|
|
+ //拼接总的给质量负责人
|
|
|
+
|
|
|
+ for (Map<String, Object> it:zhuZhang ) {
|
|
|
+ HashMap<String, Object> map = new HashMap<>(); //消息队列
|
|
|
+ map.put("user",it.get("user_id_").toString());//以人为最小单元封装
|
|
|
+ String title ="";
|
|
|
+ for (Map<String, Object> da :screening ) {
|
|
|
+ if (da.get("zi_biao_bu_men_").toString().contains(it.get("positions_").toString())){
|
|
|
+ title += "活动名称:" + da.get("huo_dong_ming_che").toString() + " 项目名称:" + da.get("shi_jian_zhi_ping").toString() + " 上报时间:" + da.get("shang_bao_shi_jia").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("neiRong",title);
|
|
|
+ list.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> zl: zhiLiang) {
|
|
|
+ HashMap<String, Object> ma = new HashMap<>(); //消息队列
|
|
|
+ ma.put("user",zl.get("user_id_").toString());//以人为最小单元封装
|
|
|
+ String title2 ="";
|
|
|
+ for(Map<String, Object> aa :screening ){
|
|
|
+ title2 += "活动名称:" + aa.get("huo_dong_ming_che").toString() + " 项目名称:" + aa.get("shi_jian_zhi_ping").toString() + " 上报时间:" + aa.get("shang_bao_shi_jia").toString();
|
|
|
+ }
|
|
|
+ ma.put("neiRong",title2);
|
|
|
+ list.add(ma);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendMsg( List<Map<String, Object>> data){
|
|
|
+ if (Collections.isNotEmpty(data)){
|
|
|
+ String title = "室间质评项目上报通知";
|
|
|
+ for (Map<String, Object> item:data ) {
|
|
|
+ //避免发出空消息,虽然前面有过校验
|
|
|
+ if (BeanUtils.isNotEmpty(item.get("neiRong").toString())){
|
|
|
+ MessageQueueProductorUtil.send("ReceptionRegistrationJob", "system" , "inner"
|
|
|
+ , Arrays.asList(item.get("user").toString().split(",")),null , title, item.get("neiRong").toString(), null, null, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验日期
|
|
|
+ public String verificationDate(String shangBao){
|
|
|
+ try {
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
+ LocalDate operationDate = LocalDate.parse(shangBao, DEFAULT_FORMATTER);
|
|
|
+ long daysDifference = java.time.temporal.ChronoUnit.DAYS.between(today,operationDate);
|
|
|
+
|
|
|
+ if (daysDifference == 1) {
|
|
|
+ return "1"; // 昨天
|
|
|
+ } else if (daysDifference == 7) {
|
|
|
+ return "7"; // 7天前
|
|
|
+ } else {
|
|
|
+ return "0"; // 其他
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ return "0";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+// public List<String> findUser(String buMen){
|
|
|
+// List<String> list = new ArrayList<>();
|
|
|
+// if(BeanUtils.isNotEmpty(buMen)){
|
|
|
+// String sql = " select e.id_ from ibps_party_employee e join ibps_party_position p on find_in_set(p.id_,e.positions_) join ibps_party_user_role r on e.id_ = r.user_id_ where p.id_ = '"+ buMen +"' and r.role_id_ = '1040905508338270208'";
|
|
|
+// List<Map<String, Object>> query = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+// for (Map<String, Object> item:query) {
|
|
|
+// list.add(item.get("id_").toString());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+
|
|
|
+ public List<Map<String, Object>> findZhuZhang(List<String> buMens){
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+ if(Collections.isNotEmpty(buMens)){
|
|
|
+ String fixSql = " SELECT " +
|
|
|
+ " e.POSITIONS_ as positions_, " +
|
|
|
+ " GROUP_CONCAT(DISTINCT u.USER_ID_) as user_id_, " +
|
|
|
+ " e.name_ " +
|
|
|
+ " FROM ibps_party_user_role u " +
|
|
|
+ " INNER JOIN ibps_party_employee e ON u.USER_ID_ = e.id_ " +
|
|
|
+ " WHERE u.ROLE_ID_ = '" + zhuZhang + "' " +
|
|
|
+ " AND ( ";
|
|
|
+
|
|
|
+ String jointSql = "";
|
|
|
+
|
|
|
+ String endSql = " ) " +
|
|
|
+ " GROUP BY e.POSITIONS_ " +
|
|
|
+ " ORDER BY COUNT(DISTINCT u.USER_ID_) DESC ";
|
|
|
+
|
|
|
+ for (int i = 0; i < buMens.size(); i++) {
|
|
|
+ if(i< buMens.size()-1){
|
|
|
+ jointSql += " FIND_IN_SET('"+ buMens.get(i) +"', e.POSITIONS_) > 0 OR ";
|
|
|
+ }else{
|
|
|
+ jointSql += " FIND_IN_SET('"+ buMens.get(i) +"', e.POSITIONS_) > 0 ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.warn("sql=>",fixSql + jointSql + endSql);
|
|
|
+ list = (List<Map<String, Object>>) commonDao.query(fixSql + jointSql + endSql);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Map<String, Object>> findZhiLiang(){
|
|
|
+ List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
|
|
+ String sql = " select e.POSITIONS_ as positions_, " +
|
|
|
+ " e.id_ as user_id_, " +
|
|
|
+ " e.name_ from ibps_party_employee e " +
|
|
|
+ " join ibps_party_user_role r on e.id_ = r.user_id_ " +
|
|
|
+ " join ibps_party_entity n on e.id_ = n.id_ " +
|
|
|
+ " where r.role_id_ = '" + zhiLiang + "' and n.party_type_ = 'employee' " +
|
|
|
+ " and e.positions_ in " +
|
|
|
+ " (SELECT e.id_ " +
|
|
|
+ " FROM ibps_party_entity e " +
|
|
|
+ " CROSS JOIN ( " +
|
|
|
+ " SELECT REPLACE(n.PATH_, '.', '') as target_path " +
|
|
|
+ " FROM ibps_party_entity n " +
|
|
|
+ " JOIN t_ipcc c ON n.id_ = c.org_ " +
|
|
|
+ " WHERE c.id_ = '1' " +
|
|
|
+ " LIMIT 1 " +
|
|
|
+ " ) t " +
|
|
|
+ " WHERE e.path_ LIKE CONCAT('%', t.target_path, '%'))";
|
|
|
+ list = (List<Map<String, Object>>) commonDao.query(sql);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+}
|