| | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.doumee.service.common.EmailService; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.catalina.Manager; |
| | |
| | | |
| | | @Autowired |
| | | private SystemDictDataBiz systemDictDataBiz; |
| | | @Autowired |
| | | private EmailService emailService; |
| | | |
| | | @Autowired |
| | | private MemberMapper memberMapper; |
| | |
| | | } |
| | | Constants.WORKORDER_SHE_EMAIL_SENDING = true; |
| | | try { |
| | | List<Notices> list = noticesMapper.selectList(new QueryWrapper<Notices>().lambda() |
| | | .eq(Notices::getIsdeleted,Constants.ZERO) |
| | | .eq(Notices::getStatus,Constants.ZERO) |
| | | .eq(Notices::getType,Constants.THREE)//邮箱通知 |
| | | List<Workorder> list = workorderMapper.selectJoinList(Workorder.class,new MPJLambdaWrapper<Workorder>() |
| | | .selectAll(Workorder.class) |
| | | .selectAs(Member::getName,Workorder::getMemberName) |
| | | .selectAs(Member::getCompanyName,Workorder::getCompanyName) |
| | | .selectAs(Member::getPhone,Workorder::getMemberPhone) |
| | | .select(" c2.name_path ",Workorder::getCategoryName) |
| | | .select(" c3.name_path ",Workorder::getTypeName) |
| | | .leftJoin(Member.class,Member::getId,Workorder::getMemberId) |
| | | .leftJoin(" category c3 on t.TYPE_ID = c3.id ") //风险类型 |
| | | .leftJoin(" category c2 on t.CATEGORY_ID = c2.id ") //DCA一级问题编码 |
| | | .eq(Workorder::getIsdeleted,Constants.ZERO) |
| | | .eq(Workorder::getEmailStatus,Constants.ZERO) |
| | | .eq(Workorder::getType,Constants.ZERO) |
| | | .isNotNull(Workorder::getEmialMemberIds )//邮箱通知 |
| | | ); |
| | | if(list!=null && list.size()>0){ |
| | | Date date = new Date(); |
| | | String path = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode() |
| | | +systemDictDataBiz.queryByCode(Constants.FTP,Constants.WORKORDER_FILE_PATH).getCode(); |
| | | for(Workorder workorder :list){ |
| | | dealEmailBiz(workorder,date,path); |
| | | } |
| | | } |
| | | |
| | | }catch (Exception e){ |
| | | log.error("==================定时发生SHE邮件失败:"+e.getMessage()); |
| | |
| | | |
| | | |
| | | } |
| | | @Transactional |
| | | private void dealEmailBiz(Workorder workorder, Date date,String path) { |
| | | List<Notices> noticesList = new ArrayList<>(); |
| | | int status =1; |
| | | String info ="邮箱已发送:"; |
| | | String ids = workorder.getEmialMemberIds(); |
| | | List<Member> memberList = getEmailMemberlistByIDs(ids); |
| | | if(memberList == null || memberList.size() ==0){ |
| | | status = 2; |
| | | info ="无效员工信息,无法发送邮箱"; |
| | | }else{ |
| | | List<String> successInfo = new ArrayList<>(); |
| | | List<String> errorInfo = new ArrayList<>(); |
| | | Map<String,String> contentForm = getEmailContentFormByModel(workorder); |
| | | List<String> imgList = getEmailImglistByModel(workorder,path); |
| | | for(Member m : memberList){ |
| | | if(org.apache.commons.lang3.StringUtils.isNotBlank(m.getEmail())){ |
| | | //如果邮箱不为空,进行邮箱发送 |
| | | successInfo.add(m.getName()+"邮箱"+m.getEmail()+""); |
| | | if( emailService.sendEmailWithImages(m.getEmail(),"SHE事件工单上报通知", contentForm,imgList)){ |
| | | Notices notices = new Notices(); |
| | | notices.setType(Constants.THREE+""); |
| | | notices.setIsdeleted(Constants.ZERO); |
| | | notices.setObjId(workorder.getId()); |
| | | notices.setTitle("SHE事件工单上报邮件通知"); |
| | | notices.setContent(JSONObject.toJSONString(contentForm)); |
| | | notices.setRemark(JSONObject.toJSONString(imgList)); |
| | | notices.setObjType(Constants.ZERO+""); |
| | | notices.setStatus(Constants.ZERO); |
| | | notices.setSendacopy(Constants.ONE); |
| | | notices.setMemberId(m.getId()); |
| | | noticesList.add(notices); |
| | | }else{ |
| | | errorInfo.add(m.getName()+"/无邮箱"); |
| | | } |
| | | }else{ |
| | | errorInfo.add(m.getName()+"/邮箱"+m.getEmail()+""); |
| | | } |
| | | |
| | | } |
| | | info += "成功:"+JSONObject.toJSONString(successInfo) +"失败:"+JSONObject.toJSONString(errorInfo); |
| | | } |
| | | |
| | | Workorder update = new Workorder(); |
| | | update.setId(workorder.getId()); |
| | | update.setEmailDate(date); |
| | | update.setEmailStatus(status ); |
| | | update.setEmailInfo(info); |
| | | this.updateById(update);//更新工单邮件发送状态 |
| | | if(noticesList.size()>0){ |
| | | noticesMapper.insert(noticesList); |
| | | } |
| | | } |
| | | |
| | | private List<String> getEmailImglistByModel(Workorder workorder, String path ) { |
| | | List<String> list = new ArrayList<>(); |
| | | //查询附件信息 |
| | | List<Multifile> multifileList = multifileMapper.selectList(new QueryWrapper<Multifile>().lambda().eq(Multifile::getIsdeleted,Constants.ZERO) |
| | | .eq(Multifile::getObjId,workorder.getId()).orderByAsc(Multifile::getId)); |
| | | if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(multifileList)){ |
| | | for (Multifile multifile:multifileList) { |
| | | list.add(path+multifile.getFileurl()); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private List<Member> getEmailMemberlistByIDs(String ids) { |
| | | List<Member> memberList = new ArrayList<>(); |
| | | if(org.apache.commons.lang3.StringUtils.isNotBlank(ids)){ |
| | | String[] tt = ids.split(","); |
| | | List<Integer> idList =new ArrayList<>(); |
| | | if(tt.length>0){ |
| | | for(String s :tt){ |
| | | try { |
| | | idList.add(Integer.parseInt(s)); |
| | | }catch (Exception e){ |
| | | |
| | | } |
| | | } |
| | | } |
| | | if(idList.size()>0){ |
| | | memberList = memberMapper.selectList(new QueryWrapper<Member>().lambda() |
| | | .eq(Member::getIsdeleted,Constants.ZERO) |
| | | .in(Member::getId,idList) |
| | | ); |
| | | } |
| | | } |
| | | |
| | | return memberList; |
| | | } |
| | | |
| | | private Map<String, String> getEmailContentFormByModel(Workorder workorder) { |
| | | Map<String, String> map = new LinkedHashMap<>(); |
| | | map.put("上报人",workorder.getMemberName()+"/" +workorder.getCompanyName()); |
| | | map.put("上报时间",DateUtil.getPlusTime2(workorder.getSubmitDate())); |
| | | map.put("事件发生时间/地点",DateUtil.getPlusTime2(workorder.getHappenTime())+"/"+workorder.getLocationName()); |
| | | map.put("伤害类型", workorder.getTypeName()); |
| | | map.put("是否外部就医", Constants.equalsInteger(workorder.getOutJiuyi(),Constants.ONE)?"是":"否"); |
| | | map.put("是否医务室", Constants.equalsInteger(workorder.getIsYiwushi(),Constants.ONE)?"是":"否"); |
| | | map.put("是否受伤", Constants.equalsInteger(workorder.getIsHurted(),Constants.ONE)?"是":"否"); |
| | | map.put("是否和工作相关", Constants.equalsInteger(workorder.getWorkRelated(),Constants.ONE)?"是":"否"); |
| | | map.put("事件说明", org.apache.commons.lang3.StringUtils.defaultString(workorder.getEventInfo(),"-")); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {BusinessException.class,Exception.class}) |