目录

1.数据据库导出到Excel

1.1需求分析

1.2设计思路与实现

1.2.1 对数据库进行操作

1.2.2服务层实现

1.2.3工具类util

1.数据据库导出到Excel

1.1需求分析

按照已有模板导出疫情每日打卡全量表增量表未打卡人员统计(内部、外部人员)、离沪人员统计

1.2设计思路与实现

1.2.1 对数据库进行操作

整合MyBatis(持久化操作):

1.编写.pojo实体类

实体类就是一个拥有Set和Get方法的类。实体类通常总是和数据库之类的(所谓持久层数据)联系在一起。这种联系是借由框架(如Hibernate)来建立的。实体类就是一个载体。       现在的设计差不多都是一张表就等于业务里面的一个类。一条记录(一般一行数据)是一个对象,一行中的一列就是这个对象的一个属性。在操作某个表时(比如更改这个表的信息),我们就可以在前台定义一个这样的对象,然后将其对应的属性赋值,然后传到后台。
这样后台就可以拿到这个对象的所有值了——不用一个一个属性当参数传过来,只要传一个这个类的对象就好了,也就是说只要一个参数就好了。好处不言而喻。

public class VirusDetailAll implements Serializable{private int virus_detail_id;private Date crt_date;private Date upd_date;private String is_valid;private String pernr;//工号/身份证号 private String reg_date;//登记日期private int user_type;//人员类别 1 大众 ,2 相关方, 0:没填private int work_city;//工作城市 1 安亭,2 南京, 3 仪征,4 宁波, 5 乌鲁木齐, 6 长沙,7 其他private String user_name;//姓名private String dept;//部门/相关方单位名称private int trd_type;//相关方类型,1 三资企业,2 非三产的外包内做企业, 3 其他(非三产非外包内做)private String tel;//手机号码private String emg_user;//紧急联系人姓名private String emg_tel;//紧急联系人电话private int health_state;//当前身体状况,1 诊断新型肺炎, 2 疑似新型肺炎, 3 有发热、咳嗽、乏力等症状, 4 正常private int lvh;//是否就医(近2周内),1 是, 0 否private String lvh_date;//最近一次就医时间(近2周内)private String lvh_name;//最近一次就医医院(近2周内)private String city;//目前所在城市private String city_key;//private int in_work_city;//目前是否在工作城市,1 是, 0 否 private String bwc_date;//返回工作地日期private int bwc_type;//返程交通方式 , 1 飞机,2 火车,3 自驾, 4 其他private String bwc_order;//航班或车次信息private int bwc_hb;//返程是否途经湖北省,1 是, 0 否private int visit_hb;//疫情期间是否出入过湖北,1 是, 0 否private String visit_hb_city;//出入城市private String visit_city_key;//private String visit_in_hb_date;//进入日期private String visit_out_hb_date;//离开日期private int tsp;//疫情期间是否接触过特殊人群 ,1 是, 0 否private int tsp_type;//接触特殊人群分类, 1 接触过确诊病例, 2 接触过疑似病例,3 接触过湖北来人,4 接触过其他高风险人private int tsp_way;//接触特殊人群形式 ,1 同住,2 同行,3 聚餐,4 会务,5 其他private String tsp_start_date;//接触开始日期private String tsp_end_date;//接触结束日期private String id_card;// 外部员工身份证private String never_leave_work_place;//当天是否离开过工作所在城市,否:当天未离开过,是:当天离开过private String now_place;//当天离开后到往地区private String physical_card_number;//出入证号,数据库中是APPLY_IDprivate String related_departments;//相关科室,dept_out//是否跟上一天有变化标志位 1:有变化,0:无变化private int flag_isvariable;//转义String user_type_str;//人员类别String work_city_str;//工作城市String trd_type_str;//相关方类型String health_state_str;//当前身体状况String lvh_str;//是否就医(近2周内)String in_work_city_str;//目前是否在工作城市String bwc_type_str;//返程交通方式String bwc_hb_str;//返程是否途经湖北省String visit_hb_str;//疫情期间是否出入过湖北String tsp_str;//疫情期间是否接触过特殊人群String tsp_type_str;//接触特殊人群分类String tsp_way_str;//接触特殊人群形式///未打卡天数private String daysOfNotSubmit; public String getUser_type_str() {if(this.getUser_type()==1){return "大众";}else if(this.getUser_type()==2){return "相关方";}return "";}public String getWork_city_str() {if(this.getWork_city()==1)return "安亭";if(this.getWork_city()==2)return "南京";if(this.getWork_city()==3)return "仪征";if(this.getWork_city()==4)return "宁波";if(this.getWork_city()==5)return "乌鲁木齐";if(this.getWork_city()==6)return "长沙";if(this.getWork_city()==7)return "其他";return "";}public String getTrd_type_str() {if(this.getTrd_type()==1)return "三产企业";if(this.getTrd_type()==2)return "非三产的外包内做企业";if(this.getTrd_type()==3)return "其他(非三产非外包内做)";return "";}public String getHealth_state_str() {if(this.getHealth_state()==1)return "诊断新型肺炎";if(this.getHealth_state()==2)return "疑似新型肺炎";if(this.getHealth_state()==3)return "有发热、咳嗽、乏力等症状";if(this.getHealth_state()==4)return "正常";return "";}public String getLvh_str() {if(this.getLvh()==1)return "是";if(this.getLvh()==0)return "否";return "";}public String getIn_work_city_str() {if(this.getIn_work_city()==1)return "是";if(this.getIn_work_city()==0)return "否";return "";}public String getBwc_type_str() {if(this.getBwc_type()==1)return "飞机";if(this.getBwc_type()==2)return "火车";if(this.getBwc_type()==3)return "自驾";if(this.getBwc_type()==4)return "其他";return "";}public String getBwc_hb_str() {if(this.getBwc_hb()==1)return "是";if(this.getBwc_hb()==0)return "否";return "";}public String getVisit_hb_str() {if(this.getVisit_hb()==1)return "是";if(this.getVisit_hb()==0)return "否";return "";}public String getTsp_str() {if(this.getTsp()==1)return "是";if(this.getTsp()==0)return "否";return "";}public String getTsp_type_str() {if(this.getTsp_type()==1)return "接触过确诊病例";if(this.getTsp_type()==2)return "接触过疑似病例";if(this.getTsp_type()==3)return "接触过湖北来人";if(this.getTsp_type()==4)return "接触过其他高风险人";return "";}public String getTsp_way_str() {if(this.getTsp_way()==1)return "同住";if(this.getTsp_way()==2)return "同行";if(this.getTsp_way()==3)return "聚餐";if(this.getTsp_way()==4)return "会务";if(this.getTsp_way()==5)return "其他";return "";}public int getVirus_detail_id() {return virus_detail_id;}public void setVirus_detail_id(int virus_detail_id) {this.virus_detail_id = virus_detail_id;}public Date getCrt_date() {return crt_date;}public void setCrt_date(Date crt_date) {this.crt_date = crt_date;}public Date getUpd_date() {return upd_date;}public void setUpd_date(Date upd_date) {this.upd_date = upd_date;}public String getIs_valid() {return is_valid;}public void setIs_valid(String is_valid) {this.is_valid = is_valid;}public String getPernr() {return pernr;}public void setPernr(String pernr) {this.pernr = pernr;}public String getReg_date() {return reg_date;}public void setReg_date(String reg_date) {this.reg_date = reg_date;}public int getUser_type() {return user_type;}public void setUser_type(int user_type) {this.user_type = user_type;}public int getWork_city() {return work_city;}public void setWork_city(int work_city) {this.work_city = work_city;}public String getUser_name() {return user_name;}public void setUser_name(String user_name) {this.user_name = user_name;}public String getDept() {return dept;}public void setDept(String dept) {this.dept = dept;}public int getTrd_type() {return trd_type;}public void setTrd_type(int trd_type) {this.trd_type = trd_type;}public String getTel() {return tel;}public void setTel(String tel) {this.tel = tel;}public String getEmg_user() {return emg_user;}public void setEmg_user(String emg_user) {this.emg_user = emg_user;}public String getEmg_tel() {return emg_tel;}public void setEmg_tel(String emg_tel) {this.emg_tel = emg_tel;}public int getHealth_state() {return health_state;}public void setHealth_state(int health_state) {this.health_state = health_state;}public int getLvh() {return lvh;}public void setLvh(int lvh) {this.lvh = lvh;}public String getLvh_date() {return lvh_date;}public void setLvh_date(String lvh_date) {this.lvh_date = lvh_date;}public String getLvh_name() {return lvh_name;}public void setLvh_name(String lvh_name) {this.lvh_name = lvh_name;}public String getCity() {return city;}public void setCity(String city) {this.city = city;}public String getCity_key() {return city_key;}public void setCity_key(String city_key) {this.city_key = city_key;}public int getIn_work_city() {return in_work_city;}public void setIn_work_city(int in_work_city) {this.in_work_city = in_work_city;}public String getBwc_date() {return bwc_date;}public void setBwc_date(String bwc_date) {this.bwc_date = bwc_date;}public int getBwc_type() {return bwc_type;}public void setBwc_type(int bwc_type) {this.bwc_type = bwc_type;}public String getBwc_order() {return bwc_order;}public void setBwc_order(String bwc_order) {this.bwc_order = bwc_order;}public int getBwc_hb() {return bwc_hb;}public void setBwc_hb(int bwc_hb) {this.bwc_hb = bwc_hb;}public int getVisit_hb() {return visit_hb;}public void setVisit_hb(int visit_hb) {this.visit_hb = visit_hb;}public String getVisit_hb_city() {return visit_hb_city;}public void setVisit_hb_city(String visit_hb_city) {this.visit_hb_city = visit_hb_city;}public String getVisit_city_key() {return visit_city_key;}public void setVisit_city_key(String visit_city_key) {this.visit_city_key = visit_city_key;}public String getVisit_in_hb_date() {return visit_in_hb_date;}public void setVisit_in_hb_date(String visit_in_hb_date) {this.visit_in_hb_date = visit_in_hb_date;}public String getVisit_out_hb_date() {return visit_out_hb_date;}public void setVisit_out_hb_date(String visit_out_hb_date) {this.visit_out_hb_date = visit_out_hb_date;}public int getTsp() {return tsp;}public void setTsp(int tsp) {this.tsp = tsp;}public int getTsp_type() {return tsp_type;}public void setTsp_type(int tsp_type) {this.tsp_type = tsp_type;}public int getTsp_way() {return tsp_way;}public void setTsp_way(int tsp_way) {this.tsp_way = tsp_way;}public String getTsp_start_date() {return tsp_start_date;}public void setTsp_start_date(String tsp_start_date) {this.tsp_start_date = tsp_start_date;}public String getTsp_end_date() {return tsp_end_date;}public void setTsp_end_date(String tsp_end_date) {this.tsp_end_date = tsp_end_date;}public String getId_card() {return id_card;}public void setId_card(String id_card) {this.id_card = id_card;}public String getNever_leave_work_place() {return never_leave_work_place;}public void setNever_leave_work_place(String never_leave_work_place) {this.never_leave_work_place = never_leave_work_place;}public String getNow_place() {return now_place;}public void setNow_place(String now_place) {this.now_place = now_place;}public int getFlag_isvariable() {return flag_isvariable;}public void setFlag_isvariable(int flag_isvariable) {this.flag_isvariable = flag_isvariable;}   public String getDaysOfNotSubmit() {return daysOfNotSubmit;}public void setDaysOfNotSubmit(String daysOfNotSubmit) {this.daysOfNotSubmit = daysOfNotSubmit;}public String getPhysical_card_number() {return physical_card_number;}public void setPhysical_card_number(String physical_card_number) {this.physical_card_number = physical_card_number;}public String getRelated_departments() {return related_departments;}public void setRelated_departments(String related_departments) {this.related_departments = related_departments;}}

人员属性

public class UserMsg implements Serializable{private String pernr;private String name;private String department;private String user_type;private String office_address;private String email;private String telephone;public String getPernr() {return pernr;}public String getName() {return name;}public void setName(String name) {this.name = name;}public void setPernr(String pernr) {this.pernr = pernr;}public String getDepartment() {return department;}public void setDepartment(String department) {this.department = department;}public String getUser_type() {return user_type;}public void setUser_type(String user_type) {this.user_type = user_type;}public String getOffice_address() {return office_address;}public void setOffice_address(String office_address) {this.office_address = office_address;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public String getTelephone() {return telephone;}public void setTelephone(String telephone) {this.telephone = telephone;}}

未打卡天数统计

@SuppressWarnings("serial")
public class DaysOfUserNotSubmit implements Serializable{private String pernr;private String daysOfNotSubmit;public String getPernr() {return pernr;}public void setPernr(String pernr) {this.pernr = pernr;}public String getDaysOfNotSubmit() {return daysOfNotSubmit;}public void setDaysOfNotSubmit(String daysOfNotSubmit) {this.daysOfNotSubmit = daysOfNotSubmit;} }

2.Mapper接口的编写

public interface VirusInfoMapper{
//    查询疫情打卡记录表List<VirusDetailAll> queryVirusDetail(Map<String,Object> map);public String queryMaxDateOfReg(Map<String,Object> map);public String queryMinDateOfReg(Map<String,Object> map);
//内部人员未打卡public List<UserMsg>  queryUserInternalNotSubmit(Map<String,Object> map);
//外部人员未打卡List<UserMsg> queryUserOutNotSubmit(Map<String, Object> map);
//内部人员离开工作地List<VirusDetailAll> queryUsersLeaveWorkPlaceToday(Map<String, Object> map);
//外部人员离开工作地public List<VirusDetailAll> queryOutUsersLeaveWorkPlaceThisWeek(Map<String,Object> map);//获得用户信息:从数据表AUTH_USERMSG//PersonInfo queryUserinfoInfo(Map<String, Object> map);//相关方未打卡天数public List<DaysOfUserNotSubmit> queryDaysOfNotSubmit(Map<String,Object> map);
//内部人员未打卡天数List<DaysOfUserNotSubmit> queryDaysOfNotSubmitInternal(Map<String, Object> map);}

3.xml文件实现这些方法

<select id="queryVirusDetail" parameterType="Map" resultType="com.svw.kf.pojo.VirusDetailAll">SELECT case when vd.USER_TYPE=1then vd.pernrwhen vd.USER_TYPE=2then upper(ID_CARD)else vd.pernrend as pernr,REG_DATE,vd.USER_TYPE,WORK_CITY,upper(replace(vd.USER_NAME,' ','')) as USER_NAME,DEPT,TRD_TYPE,vd.TEL,EMG_USER,EMG_TEL,HEALTH_STATE,PHYSICAL_CARD_NUMBER,RELATED_DEPARTMENTS,LVH,casewhen lvh=1then LVH_DATEwhen lvh=0then nullend as LVH_DATE,casewhen lvh=1then LVH_NAMEwhen lvh=0then nullend as LVH_NAME,--case --when--(--vd.city like '上海%' or--vd.city like '重庆%' or--vd.city like '北京%' or--vd.city like '天津%'--)--then SUBSTR(vd.city, 0, 2)--else vd.city--end city,vd.city as city,CITY_KEY,IN_WORK_CITY,case when IN_WORK_CITY=0then BWC_DATEwhen IN_WORK_CITY=1then nullend as BWC_DATE,case when IN_WORK_CITY=0then BWC_TYPEwhen IN_WORK_CITY=1then nullend as BWC_TYPE,case when IN_WORK_CITY=0then BWC_ORDERwhen IN_WORK_CITY=1then nullend as BWC_ORDER,case when IN_WORK_CITY=0 then BWC_HBwhen IN_WORK_CITY=1then -1end as BWC_HB,             VISIT_HB,casewhen VISIT_HB=1then VISIT_HB_CITYwhen VISIT_HB=0then nullend as VISIT_HB_CITY,VISIT_HB_CITY_KEY,casewhen VISIT_HB=1then VISIT_IN_HB_DATEwhen VISIT_HB=0then nullend as VISIT_IN_HB_DATE,casewhen VISIT_HB=1then VISIT_OUT_HB_DATEwhen VISIT_HB=0then nullend as VISIT_OUT_HB_DATE,TSP,case when TSP=1then TSP_TYPEwhen TSP=0then nullend as TSP_TYPE,case when TSP=1then TSP_WAYwhen TSP=0then nullend as TSP_WAY,case when TSP=1then TSP_START_DATEwhen TSP=0then nullend as TSP_START_DATE,case when TSP=1then TSP_END_DATEwhen TSP=0then nullend as TSP_END_DATEFROM VIRUS_DETAIL vdjoin KF_USER_UNIONID kfuon upper(vd.PERNR) =upper(kfu.PERNR)WHERE vd.is_valid=0and kfu.IS_VALID=0<if test="pernr !=null and pernr !=''">and vd.pernr=#{pernr}</if><if test="user_type !=null and user_type !='' and user_type != '0'.toString()">and vd.user_type=#{user_type}</if><if test="user_name !=null and user_name !=''">and vd.user_name=#{user_name}</if><if test="reg_date !=null and reg_date !=''">and   to_char(to_date(REG_DATE,'yyyy-mm-dd'),'yyyy-mm-dd')=#{reg_date}</if><if test="work_city !=null and work_city !='' and work_city != '0'.toString()">and WORK_CITY=#{work_city}</if><if test="last_flag !=null and last_flag !=''" ><![CDATA[and vd.UPD_DATE<trunc(SYSDATE)-10/24]]></if><if test="today_flag !=null and today_flag !=''"><![CDATA[and vd.UPD_DATE>=trunc(SYSDATE)-10/24]]></if><if test="fourteen2zero !=null and fourteen2zero !=''"><![CDATA[and vd.UPD_DATE>=trunc(SYSDATE)-10/24 and vd.UPD_DATE<trunc(SYSDATE)]]></if><if test="zero2fourteen !=null and zero2fourteen !=''"><![CDATA[and vd.UPD_DATE>=trunc(SYSDATE) and vd.UPD_DATE<trunc(SYSDATE)+14/24]]></if>ANDCASE WHEN vd.USER_TYPE=1THEN UPPER(to_char(DEPT)) ELSE UPPER('CI')ENDLIKE CONCAT(UPPER('CI'),'%')order by REG_DATE desc</select>

1.2.2服务层实现

1.定义一个接口

public interface IVirusInfoService {
//    疫情全量public Res<List<VirusDetailAll>> exportVirusDetailLatestTotal(VirusInfoReq reqParams);
//    内部员工未打卡public Res<List<VirusDetailAll>> exportUserDetailNotSubmit(VirusInfoReq reqParams);
//    疫情增量public Res<List<VirusDetailAll>> exportVirusDetailDeltaToday(VirusInfoReq reqParams);
//    离沪人员统计public Res<List<VirusDetailAll>> queryUsersLeaveWorkPlaceToday(VirusInfoReq reqParams);//    相关方未打卡public Res<List<VirusDetailAll>> exportOutUserDetailNotSubmit(VirusInfoReq reqParams);
//  邮件发送功能  //  public Res<String> sendMailByChenHanyu(MailRequest mailRequest);
}

2.入参类型

public class VirusInfoReq extends Pager{private String upd_date;private String reg_Date;private int user_type;private String pernr;private String user_name;private int work_city;private String last_flag;private String today_flag;private String fourteen2zero;private String zero2fourteen;public String getUpd_date() {return upd_date;}public void setUpd_date(String upd_date) {this.upd_date = upd_date;}public String getReg_Date() {return reg_Date;}public void setReg_Date(String reg_Date) {this.reg_Date = reg_Date;}public int getUser_type() {return user_type;}public void setUser_type(int user_type) {this.user_type = user_type;}public String getPernr() {return pernr;}public void setPernr(String pernr) {this.pernr = pernr;}public String getUser_name() {return user_name;}public void setUser_name(String user_name) {this.user_name = user_name;}public int getWork_city() {return work_city;}public void setWork_city(int work_city) {this.work_city = work_city;}public String getLast_flag() {return last_flag;}public void setLast_flag(String last_flag) {this.last_flag = last_flag;}public String getToday_flag() {return today_flag;}public void setToday_flag(String today_flag) {this.today_flag = today_flag;}public String getFourteen2zero() {return fourteen2zero;}public void setFourteen2zero(String fourteen2zero) {this.fourteen2zero = fourteen2zero;}public String getZero2fourteen() {return zero2fourteen;}public void setZero2fourteen(String zero2fourteen) {this.zero2fourteen = zero2fourteen;}}

(18条消息) 三层架构中Model的作用_kule1208的博客-CSDN博客_java中model的作用

3.实现这个接口

//抛出疫情全量
@Overridepublic Res<List<VirusDetailAll>> exportVirusDetailLatestTotal(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();Map<String,Object> map = new HashMap<String,Object>();try {if (!StringUtil.isNullOrEmpty(reqParams.getPernr())) {map.put("pernr", reqParams.getPernr());}if (!StringUtil.isNullOrEmpty(reqParams.getUser_name())) {map.put("user_name", reqParams.getUser_name());}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getUser_type()))) {map.put("user_type", String.valueOf(reqParams.getUser_type()));}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getWork_city()))) {map.put("work_city", String.valueOf(reqParams.getWork_city()));}List<VirusDetailAll> lst_virusDetail =  this.virusInfoMapper.queryVirusDetail(map);String maxRegDate_str = this.virusInfoMapper.queryMaxDateOfReg(map);String minRegDate_str = this.virusInfoMapper.queryMinDateOfReg(map);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Date maxRegDate_date =  sdf.parse(maxRegDate_str);Date minRegDate_date =  sdf.parse(minRegDate_str);List<Date> lst_date = new ArrayList<Date>();lst_date.add(minRegDate_date);//列出所有时间(疫情期间的每一天)for(int i=1;i<5000;i++){if(!addAndSubtractByGetTime(minRegDate_date,i).after(maxRegDate_date)){lst_date.add(addAndSubtractByGetTime(minRegDate_date,i));}}//最新疫情信息List<VirusDetailAll> lst_virusDetail_last = new ArrayList<VirusDetailAll>();//最新人员信息List<String> lst_users_lasted = new ArrayList<String>();if(!lst_virusDetail.isEmpty()){       //统计第一天所有人的疫情信息(当前前一天所有信息)for(VirusDetailAll tmp:lst_virusDetail){if(minRegDate_str.equals(tmp.getReg_date())){lst_virusDetail_last.add(tmp);}}for(Date tmp_date:lst_date){//下一天的日期Date next_date = addAndSubtractByGetTime(tmp_date,1);if(!next_date.after(maxRegDate_date)){///*****************拿到当天14:00以及之前的最新数据************************************/////当天第一次填报的,新增的人员信息//当天前一天所有的用户List<String> origin_total_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail_last){origin_total_user.add(tmp.getPernr());}//当天的所有用户List<String> new_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){new_user.add(tmp.getPernr());}}//当天为历史第一次填写的人员List<String> lst_users_first_submit = new ArrayList<String>();lst_users_first_submit.addAll(new_user);lst_users_first_submit.removeAll(origin_total_user);if(lst_users_first_submit.size()>0){for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){for(String str:lst_users_first_submit){if(tmp.getPernr().equals(str)){lst_virusDetail_last.add(tmp);}}}                 }}//在已填报人员的基础上更新数据的for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){for(VirusDetailAll v_d_last:lst_virusDetail_last){if(tmp.getPernr().equals(v_d_last.getPernr())){for(VirusDetailAll repl:lst_virusDetail_last){if(repl.getPernr().equals(tmp.getPernr())){int index_repl = lst_virusDetail_last.indexOf(repl);lst_virusDetail_last.set(index_repl, tmp);}}
//                                      lst_virusDetail_last.replaceAll(a->a.equals(v_d_last)?tmp:a);}   }}}///*****************拿到当天最新全量数据************************************///}}      }res.setData(lst_virusDetail_last);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;}

public Date addAndSubtractByGetTime(Date dateTime,int var):日期加一天

//疫情增量@Overridepublic Res<List<VirusDetailAll>> exportVirusDetailDeltaToday(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();Map<String,Object> map = new HashMap<String,Object>();try {if (!StringUtil.isNullOrEmpty(reqParams.getPernr())) {map.put("pernr", reqParams.getPernr());}if (!StringUtil.isNullOrEmpty(reqParams.getUser_name())) {map.put("user_name", reqParams.getUser_name());}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getUser_type()))) {map.put("user_type", String.valueOf(reqParams.getUser_type()));}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getWork_city()))) {map.put("work_city", String.valueOf(reqParams.getWork_city()));}List<VirusDetailAll> lst_virusDetail_delta = new ArrayList<VirusDetailAll>();List<VirusDetailAll> lst_virusDetail_today =this.exportVirusLatestDetailFourteen2Fourteen(reqParams).getData();//            //上一天14:00以后的用户填的信息
//          List<VirusDetail> lst_virusDetail_today =  this.exportMapper.queryVirusDetail(map);//上一天14:00以前的疫情最新数据,1*n(人)List<VirusDetailAll> lst_virusDetail_latest = this.exportVirusLatestDetailYesterday(reqParams).getData();if(!lst_virusDetail_latest.isEmpty()){if(!lst_virusDetail_today.isEmpty()){///*****************比较,有变化的取出来************************************/////当天第一次填报的,新增的人员信息//当天前一天14:00之前所有的用户List<String> origin_total_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail_latest){origin_total_user.add(tmp.getPernr());}//当天前一天14:00之后所有用户List<String> new_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail_today){new_user.add(tmp.getPernr());}//当天前一天14:00之后为历史第一次填写的人员List<String> lst_users_first_submit = new ArrayList<String>();//差集lst_users_first_submit.addAll(new_user);lst_users_first_submit.removeAll(origin_total_user);if(lst_users_first_submit.size()>0){for(VirusDetailAll tmp:lst_virusDetail_today){for(String str:lst_users_first_submit){if(tmp.getPernr().equals(str)){lst_virusDetail_delta.add(tmp);}}             }}//在已填报人员的基础上更新数据的for(VirusDetailAll tmp:lst_virusDetail_today){for(VirusDetailAll v_d_last:lst_virusDetail_latest){if(tmp.getPernr().equals(v_d_last.getPernr())){if(!equals_obj(tmp,v_d_last)){//基本信息更新的,和返程信息更新的不做新增,只作更新if(!equals_attribute(tmp.getHealth_state(),v_d_last.getHealth_state())||!equals_attribute(tmp.getLvh(),v_d_last.getLvh())||!equals_attribute(tmp.getLvh_date(),v_d_last.getLvh_date())||!equals_attribute(tmp.getLvh_name(),v_d_last.getLvh_name())||!equals_attribute(tmp.getVisit_hb(),v_d_last.getVisit_hb())||!equals_attribute(tmp.getVisit_hb_city(),v_d_last.getVisit_hb_city())||!equals_attribute(tmp.getVisit_in_hb_date(),v_d_last.getVisit_in_hb_date())||!equals_attribute(tmp.getVisit_out_hb_date(),v_d_last.getVisit_out_hb_date())||!equals_attribute(tmp.getTsp(),v_d_last.getTsp())||!equals_attribute(tmp.getTsp_type(),v_d_last.getTsp_type())||!equals_attribute(tmp.getTsp_way(),v_d_last.getTsp_way())||!equals_attribute(tmp.getTsp_start_date(),v_d_last.getTsp_start_date())||!equals_attribute(tmp.getTsp_end_date(),v_d_last.getTsp_end_date())||!equals_attribute(tmp.getCity(),v_d_last.getCity())||!equals_attribute(tmp.getIn_work_city(),v_d_last.getIn_work_city())||!equals_attribute(tmp.getBwc_date(),v_d_last.getBwc_date())||!equals_attribute(tmp.getBwc_type(),v_d_last.getBwc_type())||!equals_attribute(tmp.getBwc_order(),v_d_last.getBwc_order())||!equals_attribute(tmp.getBwc_hb(),v_d_last.getBwc_hb())){lst_virusDetail_delta.add(tmp);}}} }}///*****************比较,有变化的取出来************************************///  }}else{res.setData(lst_virusDetail_today);}res.setData(lst_virusDetail_delta);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;}//重写equal,判断是否有变化private boolean equals_attribute(Object a1,Object a2) {if(a1==null&&a2==null)return true;if(a1!=null&&a2==null)return false;if(a1==null&&a2!=null)return false;if(a1!=null&&a2!=null){if(a1.equals(a2)){return true;}else{return false;}}return true;}//判断两条疫情信息是否有变化
private boolean equals_obj(VirusDetailAll b1, VirusDetailAll b2) {if(!equals_attribute(b1.getPernr(),b2.getPernr()))return false;if(!equals_attribute(b1.getUser_type(),b2.getUser_type()))return false;if(!equals_attribute(b1.getWork_city(),b2.getWork_city()))return false;if(!equals_attribute(b1.getUser_name(),b2.getUser_name()))return false;if(!equals_attribute(b1.getDept(),b2.getDept()))return false;if(!equals_attribute(b1.getTrd_type(),b2.getTrd_type()))return false;if(!equals_attribute(b1.getTel(),b2.getTel()))return false;if(!equals_attribute(b1.getEmg_user(),b2.getEmg_user()))return false;if(!equals_attribute(b1.getEmg_tel(),b2.getEmg_tel()))return false;if(!equals_attribute(b1.getHealth_state(),b2.getHealth_state()))return false;if(!equals_attribute(b1.getLvh(),b2.getLvh()))return false;if(!equals_attribute(b1.getLvh_date(),b2.getLvh_date()))return false;if(!equals_attribute(b1.getLvh_name(),b2.getLvh_name()))return false;if(!equals_attribute(b1.getCity(),b2.getCity()))return false;if(!equals_attribute(b1.getIn_work_city(),b2.getIn_work_city()))return false;if(!equals_attribute(b1.getBwc_date(),b2.getBwc_date()))return false;if(!equals_attribute(b1.getBwc_type(),b2.getBwc_type()))return false;if(!equals_attribute(b1.getBwc_order(),b2.getBwc_order()))return false;if(!equals_attribute(b1.getBwc_hb(),b2.getBwc_hb()))return false;if(!equals_attribute(b1.getVisit_hb(),b2.getVisit_hb()))return false;if(!equals_attribute(b1.getVisit_hb_city(),b2.getVisit_hb_city()))return false;if(!equals_attribute(b1.getVisit_in_hb_date(),b2.getVisit_in_hb_date()))return false;if(!equals_attribute(b1.getVisit_out_hb_date(),b2.getVisit_out_hb_date()))return false;if(!equals_attribute(b1.getTsp(),b2.getTsp()))return false;if(!equals_attribute(b1.getTsp_type(),b2.getTsp_type()))return false;if(!equals_attribute(b1.getTsp_way(),b2.getTsp_way()))return false;if(!equals_attribute(b1.getTsp_start_date(),b2.getTsp_start_date()))return false;if(!equals_attribute(b1.getTsp_end_date(),b2.getTsp_end_date()))return false;  return true;
}//疫情最新情况(1*n(人)),当天14:00之前算的
public Res<List<VirusDetailAll>> exportVirusLatestDetailYesterday(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();Map<String,Object> map = new HashMap<String,Object>();try {if (!StringUtil.isNullOrEmpty(reqParams.getPernr())) {map.put("pernr", reqParams.getPernr());}if (!StringUtil.isNullOrEmpty(reqParams.getUser_name())) {map.put("user_name", reqParams.getUser_name());}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getUser_type()))) {map.put("user_type", String.valueOf(reqParams.getUser_type()));}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getWork_city()))) {map.put("work_city", String.valueOf(reqParams.getWork_city()));}map.put("last_flag", "last");List<VirusDetailAll> lst_virusDetail =  this.virusInfoMapper.queryVirusDetail(map);String maxRegDate_str = this.virusInfoMapper.queryMaxDateOfReg(map);String minRegDate_str = this.virusInfoMapper.queryMinDateOfReg(map);SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");Date maxRegDate_date =  sdf.parse(maxRegDate_str);Date minRegDate_date =  sdf.parse(minRegDate_str);List<Date> lst_date = new ArrayList<Date>();lst_date.add(minRegDate_date);//列出所有时间(疫情期间的每一天)for(int i=1;i<5000;i++){if(!addAndSubtractByGetTime(minRegDate_date,i).after(maxRegDate_date)){lst_date.add(addAndSubtractByGetTime(minRegDate_date,i));}}//最新疫情信息List<VirusDetailAll> lst_virusDetail_last = new ArrayList<VirusDetailAll>();//最新人员信息List<String> lst_users_lasted = new ArrayList<String>();if(!lst_virusDetail.isEmpty()){        //统计第一天所有人的疫情信息(当前前一天所有信息)for(VirusDetailAll tmp:lst_virusDetail){if(minRegDate_str.equals(tmp.getReg_date())){lst_virusDetail_last.add(tmp);}}for(Date tmp_date:lst_date){//下一天的日期Date next_date = addAndSubtractByGetTime(tmp_date,1);if(!next_date.after(maxRegDate_date)){///*****************拿到当天14:00以及之前的最新数据************************************/////当天第一次填报的,新增的人员信息//当天前一天所有的用户List<String> origin_total_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail_last){origin_total_user.add(tmp.getPernr());}//当天的所有用户List<String> new_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){new_user.add(tmp.getPernr());}}//当天为历史第一次填写的人员List<String> lst_users_first_submit = new ArrayList<String>();lst_users_first_submit.addAll(new_user);lst_users_first_submit.removeAll(origin_total_user);if(lst_users_first_submit.size()>0){for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){for(String str:lst_users_first_submit){if(tmp.getPernr().equals(str)){lst_virusDetail_last.add(tmp);}}}                 }}//在已填报人员的基础上更新数据的for(VirusDetailAll tmp:lst_virusDetail){if(tmp.getReg_date().equals(sdf.format(next_date))){for(VirusDetailAll v_d_last:lst_virusDetail_last){if(tmp.getPernr().equals(v_d_last.getPernr())){for(VirusDetailAll repl:lst_virusDetail_last){if(repl.getPernr().equals(tmp.getPernr())){int index_repl = lst_virusDetail_last.indexOf(repl);lst_virusDetail_last.set(index_repl, tmp);}}
//                                  lst_virusDetail_last.replaceAll(a->a.equals(v_d_last)?tmp:a);}   }}}///*****************拿到当天14:00以及之前的最新数据************************************///}}       }res.setData(lst_virusDetail_last);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;
}//疫情最新情况(1*n(人)),(前一天1400:00-当天1400:00)
public Res<List<VirusDetailAll>> exportVirusLatestDetailFourteen2Fourteen(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();
//  Map<String,Object> map = new HashMap<String,Object>();try {Map<String,Object> map_fourteen2zero = new HashMap<String,Object>();Map<String,Object> map_zero2fourteen = new HashMap<String,Object>();if (!StringUtil.isNullOrEmpty(reqParams.getPernr())) {map_fourteen2zero.put("pernr", reqParams.getPernr());map_zero2fourteen.put("pernr", reqParams.getPernr());}if (!StringUtil.isNullOrEmpty(reqParams.getUser_name())) {map_fourteen2zero.put("user_name", reqParams.getUser_name());map_zero2fourteen.put("user_name", reqParams.getUser_name());}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getUser_type()))) {map_fourteen2zero.put("user_type", String.valueOf(reqParams.getUser_type()));map_zero2fourteen.put("user_type", String.valueOf(reqParams.getUser_type()));}if (!StringUtil.isNullOrEmpty(String.valueOf(reqParams.getWork_city()))) {map_fourteen2zero.put("work_city", String.valueOf(reqParams.getWork_city()));map_zero2fourteen.put("work_city", String.valueOf(reqParams.getWork_city()));}map_fourteen2zero.put("fourteen2zero","fourteen2zero");//上一天14:00-零点的用户填的信息List<VirusDetailAll> lst_virusDetail_fourteen2zero =  this.virusInfoMapper.queryVirusDetail(map_fourteen2zero);map_zero2fourteen.put("zero2fourteen","zero2fourteen");//当天0点-14:00点的用户填的信息List<VirusDetailAll> lst_virusDetail_zero2fourteen =  this.virusInfoMapper.queryVirusDetail(map_zero2fourteen);//最新疫情信息List<VirusDetailAll> lst_virusDetail_last = new ArrayList<VirusDetailAll>();     if(!lst_virusDetail_fourteen2zero.isEmpty()){for(VirusDetailAll tmp:lst_virusDetail_fourteen2zero){lst_virusDetail_last.add(tmp);}}if(!lst_virusDetail_zero2fourteen.isEmpty()){///*****************拿到前一天14:00-当天14:00最新数据************************************/////当天0点-14:00相对与上一天14:00-零点第一次填报的,新增的人员信息//上一天14:00-零点的用户List<String> origin_total_user = new ArrayList<String>();if(!lst_virusDetail_fourteen2zero.isEmpty()){for(VirusDetailAll tmp:lst_virusDetail_fourteen2zero){origin_total_user.add(tmp.getPernr());}}//当天0点-14:00点的用户List<String> new_user = new ArrayList<String>();for(VirusDetailAll tmp:lst_virusDetail_zero2fourteen){new_user.add(tmp.getPernr());}//当天0点-14:00点相对与上一天14:00-零点为第一次填写的人员List<String> lst_users_first_submit = new ArrayList<String>();lst_users_first_submit.addAll(new_user);lst_users_first_submit.removeAll(origin_total_user);if(lst_users_first_submit.size()>0){for(VirusDetailAll tmp:lst_virusDetail_zero2fourteen){for(String str:lst_users_first_submit){if(tmp.getPernr().equals(str)){lst_virusDetail_last.add(tmp);}}                }}//在已填报人员的基础上更新数据的for(VirusDetailAll tmp:lst_virusDetail_zero2fourteen){for(VirusDetailAll v_d_last:lst_virusDetail_last){if(tmp.getPernr().equals(v_d_last.getPernr())){for(VirusDetailAll repl:lst_virusDetail_last){if(repl.getPernr().equals(tmp.getPernr())){int index_repl = lst_virusDetail_last.indexOf(repl);lst_virusDetail_last.set(index_repl, tmp);}}
//                      lst_virusDetail_last.replaceAll(a->a.equals(v_d_last)?tmp:a);}   }}///*****************拿到前一天14:00-当天14:00最新数据************************************///}res.setData(lst_virusDetail_last);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;
}

未打卡人员统计

//内部员工未打卡@Overridepublic Res<List<VirusDetailAll>> exportUserDetailNotSubmit(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();Map<String,Object> map = new HashMap<String,Object>();try {if (!StringUtil.isNullOrEmpty(reqParams.getUpd_date())) {map.put("upd_date", reqParams.getUpd_date());}if (!StringUtil.isNullOrEmpty(reqParams.getReg_Date())) {map.put("reg_date", reqParams.getReg_Date());}map.put("user_type", reqParams.getUser_type());//考虑每天未打卡
//          List<VirusDetail> lst_virusDetail =  this.exportMapper.queryVirusDetail(map);
//
//          String maxRegDate_str = this.exportMapper.queryMaxDateOfReg(map);
//
//          String minRegDate_str = this.exportMapper.queryMinDateOfReg(map);
//
//          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//
//          Date maxRegDate_date =  sdf.parse(maxRegDate_str);
//
//          Date minRegDate_date =  sdf.parse(minRegDate_str);
//
//          List<Date> lst_date = new ArrayList<Date>();
//          lst_date.add(minRegDate_date);
//
//          //疫情相关的所有用户
//          List<UserMsg> lst_user = this.exportMapper.queryUsersInternal(map);
//          List<UserMsg> lst_user_out = this.exportMapper.queryUsersOut(map);
//          List<String> origin_total_user = new ArrayList<String>();
//          for(UserMsg tmp:lst_user){
//              origin_total_user.add(tmp.getPernr());
//          }
//          for(UserMsg tmp:lst_user_out){
//              origin_total_user.add(tmp.getPernr());
//          }
//          //列出所有时间(疫情期间的每一天)
//          for(int i=1;i<5000;i++){
//              if(!addAndSubtractByGetTime(minRegDate_date,i).after(maxRegDate_date)){
//                  lst_date.add(addAndSubtractByGetTime(minRegDate_date,i));
//              }
//          }
//
//          //未填写的人详情
//          List<VirusDetail> lst_userDetail_not_submit = new ArrayList<VirusDetail>();
//
//
//          if(!lst_virusDetail.isEmpty()){
//
//              for(Date tmp_date:lst_date){
//
//                  List<String> new_user = new ArrayList<String>();
//                  //未填写的人
//                  List<String> lst_users_not_submit = new ArrayList<String>();
//
//                  for(VirusDetail tmp:lst_virusDetail){
//                      if(tmp.getReg_date().equals(sdf.format(tmp_date))){
//                          new_user.add(tmp.getPernr());
//                      }
//                  }
//
//                  lst_users_not_submit.addAll(origin_total_user);
//                  lst_users_not_submit.removeAll(new_user);
//
//                  if(lst_users_not_submit.size()>0){
//                      for(String user:lst_users_not_submit){
//
//                          VirusDetail virus = new VirusDetail();
//
//                          for(UserMsg tmp:lst_user){
//                              if(user.equals(tmp.getPernr())){
//                                  virus.setDept(tmp.getDepartment());
//                                  virus.setUser_name(tmp.getName());
//                                  virus.setUser_type(Integer.parseInt(tmp.getUser_type()));
//                              }
//                          }
//
//                          virus.setReg_date(sdf.format(tmp_date));
//                          virus.setPernr(user);
//                          lst_userDetail_not_submit.add(virus);
//                      }
//                  }
//              }
//
//          }Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//未填写的人详情List<VirusDetailAll> lst_userDetail_not_submit = new ArrayList<VirusDetailAll>();List<UserMsg> list_users = this.virusInfoMapper.queryUserInternalNotSubmit(map);if(list_users.size()>0){for(UserMsg tmp:list_users){VirusDetailAll user = new VirusDetailAll();user.setReg_date(sdf.format(date));user.setPernr(tmp.getPernr());user.setDept(tmp.getDepartment());user.setUser_name(tmp.getName());user.setUser_type(Integer.valueOf(tmp.getUser_type()));lst_userDetail_not_submit.add(user);}}res.setData(lst_userDetail_not_submit);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;}

外部

//外部员工未打卡@Overridepublic Res<List<VirusDetailAll>> exportOutUserDetailNotSubmit(VirusInfoReq reqParams) {Res<List<VirusDetailAll>> res = new Res<List<VirusDetailAll>>();Map<String,Object> map = new HashMap<String,Object>();try {if (!StringUtil.isNullOrEmpty(reqParams.getUpd_date())) {map.put("upd_date", reqParams.getUpd_date());}if (!StringUtil.isNullOrEmpty(reqParams.getReg_Date())) {map.put("reg_date", reqParams.getReg_Date());}map.put("user_type", reqParams.getUser_type());Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//未填写的人详情List<VirusDetailAll> lst_userDetail_not_submit = new ArrayList<VirusDetailAll>();List<UserMsg> list_users = this.virusInfoMapper.queryUserOutNotSubmit(map);if(list_users.size()>0){for(UserMsg tmp:list_users){VirusDetailAll user = new VirusDetailAll();user.setReg_date(sdf.format(date));user.setPernr(tmp.getPernr());user.setDept(tmp.getDepartment());user.setUser_name(tmp.getName());user.setUser_type(Integer.valueOf(tmp.getUser_type()));lst_userDetail_not_submit.add(user);}}res.setData(lst_userDetail_not_submit);} catch (Exception ex) {res.setCode(Constant.MSG_ERROR);res.setMsg(ex.toString());}return res;}

1.2.3工具类util

借用apache的poi接口来使用excel

  • 导入依赖
<dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.14</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.14</version></dependency>

1.导出全量和增量的ExcelUtils:
 public void exportExcel_total(String tempPath, String path, HttpServletResponse response, List<VirusDetailAll> list, String excelName,HttpServletRequest request) { }

--exportExcel(tempPath, path, response, list,fileName,request);

2.未填人员信息 ExcelUtilsNotSubmit

exportExcel(tempPath, path, response, list,list_outUser,fileName);

3.离沪人员统计 UsersLeaveWorkPlaceExportUtil

exportExcel(tempPath, path, response, list,fileName,request);

2.发送带附件的邮件

2.2.1 导入依赖

<!--        邮件发送--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency>

2.2.2 配置resource

spring.mail.default-encoding=UTF-8
spring.mail.port=994
spring.mail.host=smtp.163.com
#spring.mail.host=167.139.8.201
#spring.mail.username=shenmengjiao@csvw.com
#spring.mail.password=4rfv4rfv$RFV
spring.mail.username=chenhanyu202108@163.com
spring.mail.password=CFZQJAMDOAXHCFJU
#spring.mail.properties.debug=true
#spring.mail.properties.smtp.ssl.trust=167.139.8.201
spring.mail.properties.smtp.ssl.enable=true
spring.mail.properties.smtp.auth=false
spring.mail.properties.smtp.starttls.enable=true
spring.mail.properties.smtp.starttls.require=true

2.2.3 Service的实现

示例:

 @Overridepublic Res<String> sendMailByChenHanyu(MailRequest mailRequest) {///发送给//mailRequest.setSendTo(new String[]{"shenmengjiao@csvw.com"});
//      mailRequest.setSendTo(new String[]{"weirong@csvw.com","peipei@csvw.com"});mailRequest.setSendTo(new String[]{"2317150710@qq.com"});PersonInfo restemp = new PersonInfo();List<String> emailList = new ArrayList<>();Map<String, Object> map = new HashMap<String, Object>();// 根据人名获取邮箱// map.put("email", authorizationInput.getEmail());// map.put("empNumber", authorizationInput.getEmpNumber());for (int i = 0; i < mailRequest.getSendTo().length; i++) {if (mailRequest.getSendTo()[i].contains("@")) {emailList.add(mailRequest.getSendTo()[i]);} else {map.put("empName", mailRequest.getSendTo()[i]);restemp = this.exportMapper.queryUserinfoInfo(map);if (restemp != null) {emailList.add(restemp.getEmail());}}}Res<String> res = new Res<String>();MimeMessage message1 = null;try {message1 = mailSender.createMimeMessage();MimeMessageHelper helper = new MimeMessageHelper(message1, true);
//          helper.setFrom("SHENMENGJIAO@csvw.com");helper.setFrom("chenhanyu202108@163.com");if (emailList.toArray(new String[emailList.size()]) != null) {helper.setTo(emailList.toArray(new String[emailList.size()]));// helper.setTo("outlook_802A612E2D61A355@outlook.com");}if (!StringUtil.isNullOrEmpty(mailRequest.getSubject())) {helper.setSubject(mailRequest.getSubject());}if (!StringUtil.isNullOrEmpty(mailRequest.getSendFrom())) {helper.setCc(mailRequest.getSendFrom());}抄送//helper.setCc("shenmengjiao@csvw.com");
//          helper.setCc("liyijun@csvw.com");/密送
//          helper.setBcc("shenmengjiao@csvw.com");Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");附件   String file_path_delta = "D:/2020疫情期间工作/在线信息填报开发/疫情增量/"+"疫情增量 "+sdf.format(date).replace(":", "").replace("-", "").replace(" ", "")+".xlsx";String file_path_all = "D:/2020疫情期间工作/在线信息填报开发/疫情全量/"+"疫情全量 "+sdf.format(date).replace(":", "").replace("-", "").replace(" ", "")+".xlsx";String file_path_leave = "D:/2020疫情期间工作/在线信息填报开发/当天离开上海的/"+"离沪人员统计表 "+sdf.format(date).replace(":", "").replace("-", "").replace(" ", "")+".xlsx";String file_path_notSubmit = "D:/2020疫情期间工作/在线信息填报开发/未填人员信息/"+"当天未打卡 "+sdf.format(date).replace(":", "").replace("-", "").replace(" ", "")+".xlsx";FileSystemResource fileSystemResource_delta = new FileSystemResource(file_path_delta);FileSystemResource fileSystemResource_all = new FileSystemResource(file_path_all);FileSystemResource fileSystemResource_leave = new FileSystemResource(file_path_leave);FileSystemResource fileSystemResource_notSubmit = new FileSystemResource(file_path_notSubmit);if(mailRequest.getFlag_delta().equals("有数据")&&mailRequest.getFlag_leave().equals("有数据")&&mailRequest.getFlag_notsubmit().equals("有数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_delta.getFilename(),"utf-8","B"), fileSystemResource_delta);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_leave.getFilename(),"utf-8","B"), fileSystemResource_leave);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_notSubmit.getFilename(),"utf-8","B"), fileSystemResource_notSubmit);}else if(mailRequest.getFlag_delta().equals("有数据")&&mailRequest.getFlag_leave().equals("有数据")&&mailRequest.getFlag_notsubmit().equals("无数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_delta.getFilename(),"utf-8","B"), fileSystemResource_delta);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_leave.getFilename(),"utf-8","B"), fileSystemResource_leave);}else if(mailRequest.getFlag_delta().equals("有数据")&&mailRequest.getFlag_leave().equals("无数据")&&mailRequest.getFlag_notsubmit().equals("有数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_delta.getFilename(),"utf-8","B"), fileSystemResource_delta);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_notSubmit.getFilename(),"utf-8","B"), fileSystemResource_notSubmit);}else if(mailRequest.getFlag_delta().equals("无数据")&&mailRequest.getFlag_leave().equals("有数据")&&mailRequest.getFlag_notsubmit().equals("有数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_leave.getFilename(),"utf-8","B"), fileSystemResource_leave);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_notSubmit.getFilename(),"utf-8","B"), fileSystemResource_notSubmit);}else if(mailRequest.getFlag_delta().equals("有数据")&&mailRequest.getFlag_leave().equals("无数据")&&mailRequest.getFlag_notsubmit().equals("无数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_delta.getFilename(),"utf-8","B"), fileSystemResource_delta);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);}else if(mailRequest.getFlag_delta().equals("无数据")&&mailRequest.getFlag_leave().equals("有数据")&&mailRequest.getFlag_notsubmit().equals("无数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_leave.getFilename(),"utf-8","B"), fileSystemResource_leave);}else if(mailRequest.getFlag_delta().equals("无数据")&&mailRequest.getFlag_leave().equals("无数据")&&mailRequest.getFlag_notsubmit().equals("有数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_notSubmit.getFilename(),"utf-8","B"), fileSystemResource_notSubmit);}else if(mailRequest.getFlag_delta().equals("无数据")&&mailRequest.getFlag_leave().equals("无数据")&&mailRequest.getFlag_notsubmit().equals("无数据")){helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);}//            if(sdf.format(date).equals("2020-05-06")){
//              if(mailRequest.getFlag_notsubmit_outUser().equals("有数据")){
//                  String file_path_notSubmit_outUser = "D:/2020疫情期间工作/在线信息填报开发/相关方绿标黄标/"+"未打卡供应商 "+sdf.format(date).replace("-", "")+".xlsx";
//                  FileSystemResource fileSystemResource_notSubmit_outUser = new FileSystemResource(file_path_notSubmit_outUser);
//                  helper.addAttachment(MimeUtility.encodeWord("未打卡供应商 "+sdf.format(date).replace("-", "")+".xlsx","utf-8","B"), fileSystemResource_notSubmit_outUser);
//              }
//
//          }
//
//          if(mailRequest.getFlag_outUser_leave_this_week().equals("有数据")){
//              String file_path_leave_outUser_thisWeek = "D:/2020疫情期间工作/在线信息填报开发/相关方绿标黄标/"+"近一周离沪相关方 "+sdf.format(date).replace("-", "")+".xlsx";
//              FileSystemResource fileSystemResource_leave_outUser_thisWeek = new FileSystemResource(file_path_leave_outUser_thisWeek);
//              helper.addAttachment(MimeUtility.encodeWord("近一周离沪 "+sdf.format(date).replace("-", "")+".xlsx","utf-8","B"), fileSystemResource_leave_outUser_thisWeek);
//          }//         helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_delta.getFilename(),"utf-8","B"), fileSystemResource_delta);
//          helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_all.getFilename(),"utf-8","B"), fileSystemResource_all);
//          helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_leave.getFilename(),"utf-8","B"), fileSystemResource_leave);
//          helper.addAttachment(MimeUtility.encodeWord(fileSystemResource_notSubmit.getFilename(),"utf-8","B"), fileSystemResource_notSubmit);StringBuffer sb = new StringBuffer();if (mailRequest.getInformation() != null) {for (int i = 0; i < mailRequest.getInformation().length; i++) {if(i==0){sb.append("&nbsp;&nbsp;&nbsp;&nbsp;" + mailRequest.getInformation()[i]);}else{sb.append("<p>&nbsp;&nbsp;&nbsp;&nbsp;" + mailRequest.getInformation()[i]);}}}
//          sb.append("各位好," +"<br>"+"<br>"+ "&nbsp;&nbsp;&nbsp;&nbsp;"+mailRequest.getText()+"<br>"+"<br>"+"请查收,谢谢。");sb.append("各位好," +"<br>"+"<br>"+mailRequest.getText()+"<br>"+"<br>"+"请查收,谢谢。");
//          if (!StringUtil.isNullOrEmpty(mailRequest.getImage())) {
//              sb.append("<p><img src=\"" + mailRequest.getImage() + "\">");
//          }if (!StringUtil.isNullOrEmpty(sb.toString())) {helper.setText(sb.toString(), true);}if (!StringUtil.isNullOrEmpty(mailRequest.getImage())) {String base64img = mailRequest.getImage().substring(mailRequest.getImage().indexOf(",") + 1);generateImage(base64img, "/tmp/" + mailRequest.getSendFrom() + ".jpg");helper.addAttachment("attachment.jpg", new File("/tmp/" + mailRequest.getSendFrom() + ".jpg"));}mailSender.send(message1);res.setCode(Constant.MSG_SUCCESS);return res;} catch (Exception e) {res.setCode(Constant.MSG_ERROR);res.setMsg(e.toString());return res;}}private static boolean generateImage(String imgStr, String imgFilePath) {//if (imgStr == null) // 图像数据为空return false;try {// Base64解码byte[] b = org.apache.commons.codec.binary.Base64.decodeBase64(imgStr);for (int i = 0; i < b.length; ++i) {if (b[i] < 0) {// 调整异常数据b[i] += 256;}}// 生成jpeg图片OutputStream out = new FileOutputStream(imgFilePath);out.write(b);out.flush();out.close();return true;} catch (Exception e) {return false;}}

0909回顾会--数据库导出Excel邮件发送相关推荐

  1. html 文字从数据库导出excel,html数据库导出excel表格

    关于 html数据库导出excel表格的搜索结果 回答 将execl表格导出为csv格式&xff0c;然后数据就是一行一行以逗号分割的数据.后面就好办了吧#找python的excel库.htt ...

  2. python 数据库查询结果邮件提醒_Python实现的查询mysql数据库并通过邮件发送信息功能...

    本文实例讲述了Python实现的查询mysql数据库并通过邮件发送信息功能.分享给大家供大家参考,具体如下: 这里使用Python查询mysql数据库,并通过邮件发送宕机信息. Python代码如下: ...

  3. 导出 服务器 excel文件,服务器数据库导出excel文件格式

    服务器数据库导出excel文件格式 内容精选 换一换 GaussDB(DWS)支持使用gs_dumpall工具导出所有数据库的全量信息,包含集群中每个数据库信息和公共的全局对象信息.可根据需要自定义导 ...

  4. php导出表格是乱码怎么办,数据库导出excel表格是乱码怎么办-Excel表格乱码问题怎么解决?...

    POI导出excel表时文件名变成乱码怎么办 在乱码的表格上键-用记事本打 2 这里会看到里面的文字都恢复了. 3 接下来文件-另存为 4 另存的时候刻改一下文件名,这里改成1副本,格式为txt,然后 ...

  5. 服务器上的文件怎么导出excel,服务器数据库导出excel文件格式

    服务器数据库导出excel文件格式 内容精选 换一换 gs_dump和gs_dumpall通过-U指定执行导出的用户帐户.如果当前使用的帐户不具备导出所要求的权限时,会无法导出数据.此时,可在导出命令 ...

  6. mysql自带的邮件发送功能_Python实现的查询mysql数据库并通过邮件发送信息功能...

    本文实例讲述了Python实现的查询mysql数据库并通过邮件发送信息功能.分享给大家供大家参考,具体如下: 这里使用Python查询mysql数据库,并通过邮件发送宕机信息. Python代码如下: ...

  7. Linux shell脚本、定时备份mysql数据库、sendMail邮件发送

    数据库备份 定时任务 邮件发送 一.数据库备份 vim /sqlbackup/mysql_backup.sh#!/bin/sh ###定义变量#### date=`date "+%Y-%m- ...

  8. 把服务器sql数据库导出excel文件,将mysql数据库数据以Excel文件的形式导出

    最近在工作中,领导让从数据库中导出一些数据并存放到Excel表格中,网上有许多教程,下面是我总结的其中俩种方法. 从数据库管理工具中导出(navicat) 在navicat导出数据导Excel中还是比 ...

  9. linux-自动备份MySQL数据库,并邮件发送

    网站的数据是最重要的,需要我们定期备份,接下来为大家说的就是 定期-自动-备份MySQL数据库,并且压缩后以邮箱发送 大概步骤就是: 1.确保 安装了 sendmail 和 mutt 包(没有安装的话 ...

最新文章

  1. 雷军 26 年前写的代码,你见过吗?
  2. Android退出程序(二)——利用广播机制
  3. etc的常见算法_谈常用的几个机器学习算法,学懂算法也可以这么简单!
  4. 第二章mapper接口 和模糊查询
  5. linux主机解析虚拟机超时_Linux 内核超时导致虚拟机无法正常启动
  6. 从根儿上理解mysql_从根儿上理解 MySQL - 页总结
  7. android自定义金额输入键盘_Android 自定义输入支付密码的软键盘实例代码
  8. YBTOJ:灯光控制(贪心)(公倍数)(暴力枚举)
  9. java学习(122):treeset自定义排序
  10. 内固定取出术后护理_股骨内固定钢板取出术后护理查房记录范文
  11. 连载一:Oracle迁移文档大全
  12. LeetCode-66. 托普利茨矩阵
  13. 并行、并发和代码性能优化
  14. 什么是多态 重载 覆盖 继承 最好解释
  15. php100视频教程下载(全集),下载地址链接(整理后包涵解压密码)
  16. 「标签管理」用数据管理思维去管理你的日常电子化资料、文件、笔记等
  17. 想做IT行业项目管理,面向客户方向的,考ITIL和PMP哪个更好一些?
  18. ACM-ICPC 2018 焦作赛区网络预赛 L. Poor God Water
  19. FPGA 频率计实验
  20. osgEarth示例分析——osgearth_features

热门文章

  1. LeetCode练习——字符串(字符串中的第一个唯一字符)
  2. c语言三元组求矩阵加法,矩阵相加的算法(存储结构为三元组表)
  3. PCM 大端(S16BE)和小端(S16LE)分析,及转换
  4. DirectX12(D3D12)基础教程(二十一)—— PBR:IBL 的数学原理(3/5)漫反射积分项
  5. C++ API 设计 09 第四章 设计
  6. 移动端前端常见的触摸相关事件touch、tap、swipe
  7. 苹果11怎么录屏_小米、苹果手机怎么录屏,这些手机屏幕录制秘方,快来收好...
  8. 海康摄像机抓拍SDK集成java(包括windows和linux)
  9. 微信小程序-OCR信息识别
  10. 2015中国“互联网+”千人论坛活动圆满闭幕