package com.ld.igds.warn; import com.bstek.bdf2.core.model.DefaultUser; import com.ld.igds.common.CoreCommonService; import com.ld.igds.common.mapper.CommonMapper; import com.ld.igds.constant.Constant; import com.ld.igds.constant.WarnLevel; import com.ld.igds.constant.WarnStatus; import com.ld.igds.constant.WarnType; import com.ld.igds.models.Depot; import com.ld.igds.models.DepotConf; import com.ld.igds.models.Grain; import com.ld.igds.models.MWarnConf; import com.ld.igds.util.ContextUtil; import com.ld.igds.warn.data.WarnData; import com.ld.igds.warn.service.CoreWarnService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateFormatUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; /** * 警告工具类 * * @author: chen * @description: * @version: * @data:2021年12月06日 */ @Service(WarnUtils.BEAN_ID) @Slf4j public class WarnUtils { public static final String BEAN_ID = "core.warnUtils"; //出入库推送微信接口编码 public static final String WECHAT_WARN_1007 = "1007"; //警告推送微信接口编码 public static final String WECHAT_WARN_1008 = "1008"; //工单推送微信接口 public static final String WECHAT_WARN_1011 = "1011"; @Autowired private CoreCommonService commonService; @Autowired private CoreWarnService coreWarnService; @Autowired private CommonMapper commonMapper; /** * 根据警告配置获取通知人 * * @param conf * @return */ public List getWarnUserByWarnConf(MWarnConf conf, String depotId) { if(null == conf){ return null; } //获取仓库信息,用于下面获取保管员 Depot depot = commonService.getCacheDepot(conf.getCompanyId(), depotId); // 根据警告配置获取通知人 List listUser = new ArrayList<>(); if (StringUtils.isNotEmpty(conf.getUser1())) listUser.add(conf.getUser1()); if (StringUtils.isNotEmpty(conf.getUser2())) listUser.add(conf.getUser2()); if (StringUtils.isNotEmpty(conf.getUser3())) listUser.add(conf.getUser3()); if (StringUtils.isNotEmpty(conf.getUser4())) listUser.add(conf.getUser4()); if (StringUtils.isNotEmpty(conf.getUser5())) listUser.add(conf.getUser5()); if (null !=depot && Constant.YN_Y.equals(conf.getKeeperTag()) && StringUtils.isNotEmpty(depot.getStoreKeeper())){ listUser.add(depot.getStoreKeeper()); } return commonMapper.getUserByList(conf.getCompanyId(), listUser); } /** * 设置微信通知人等信息 * @param warnData * @param users * @return */ public WarnData setPhoneByWeChat(WarnData warnData, List users) { if (users.size() > 0) { warnData.setNoticeUser(""); warnData.setPhone(""); for (DefaultUser defaultUser : users) { if (StringUtils.isEmpty(defaultUser.getMobile())){ continue; } warnData.setNoticeUser(defaultUser.getUsername() + "," + warnData.getNoticeUser()); warnData.setPhone(defaultUser.getMobile() + "," + warnData.getPhone()); } } return warnData; } /** * 增加粮情高温记录 * @param depotConf * @param grain */ public void addGrainWarn(DepotConf depotConf, Grain grain){ //获取仓库信息 Depot depot = commonService.getCacheDepot(depotConf.getCompanyId(), depotConf.getDepotId()); if(null == depot){ log.error("-----未获取到仓库信息,不生成警告-----"); return; } WarnData warn = new WarnData(); warn.setId(ContextUtil.getUUID()); warn.setCompanyId(depot.getCompanyId()); warn.setDeptId(depot.getDeptId()); warn.setDepotId(depot.getId()); warn.setDepotName(depot.getName()); warn.setName("粮情高温警告"); warn.setType(WarnType.TYPE_01.getCode()); warn.setLevel(WarnLevel.LEVEL_01.getCode()); warn.setTime(grain.getReceiveDate()); warn.setBizType(Constant.MODEL_GRAIN); warn.setStatus(WarnStatus.STATUS_10.getCode()); String info = depot.getName() + "出现粮情高温警告,设定高温:" + depotConf.getTempMax() + ", 当前检测高温:" + grain.getTempMax() + ",检测时间:" + DateFormatUtils.format(grain.getReceiveDate(),"yyyy-MM-dd HH:mm:ss"); warn.setInfo(info); coreWarnService.addWarnAndNotice(warn); } }