package com.dsh.guns.modular.system.util.task.jobs; import com.dsh.guns.core.util.SinataUtil; import com.dsh.guns.modular.system.util.ConstellationUtil; import com.dsh.guns.modular.system.util.task.base.AbstractJob; import org.apache.commons.lang.time.DateUtils; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; /** * 定时1秒后导出用户详情记录 */ public class AddMachine extends AbstractJob { public static final String name = "addMachineJob"; @Override public void execute(JobExecutionContext context) throws JobExecutionException { JobDataMap maps = context.getMergedJobDataMap(); Workbook book = (Workbook) maps.get("book"); try { System.out.println("----定时2秒后导入机器人-----"); Sheet sh = book.getSheetAt(0); //获取到第一个表 for (int i = 1; i <= sh.getLastRowNum(); i++) { Row row = sh.getRow(i); Cell cell0 = row.getCell(0); //用户昵称 String nickname = null; if (SinataUtil.isNotEmpty(cell0)){ nickname = String.valueOf(cell0.getStringCellValue()).trim(); } Cell cell1 = row.getCell(1); //性别 String sex = null; if (SinataUtil.isNotEmpty(cell1)){ sex = String.valueOf(cell1.getStringCellValue()).trim(); } Cell cell2 = row.getCell(2); //认证 String authType = null; if (SinataUtil.isNotEmpty(cell2)){ authType = String.valueOf(cell2.getStringCellValue()).trim(); } Cell cell3 = row.getCell(3); //女神认证 String isGoddess = null; if (SinataUtil.isNotEmpty(cell3)){ isGoddess = String.valueOf(cell3.getStringCellValue()).trim(); } Cell cell4 = row.getCell(4); //会员 String isVip = null; if (SinataUtil.isNotEmpty(cell4)){ isVip = String.valueOf(cell4.getStringCellValue()).trim(); } Cell cell5 = row.getCell(5); //生日 String birthday = null; if (SinataUtil.isNotEmpty(cell5)){ birthday = String.valueOf(cell5.getStringCellValue()).trim(); } Cell cell6 = row.getCell(6); //爱好 String hobbyStr = null; if (SinataUtil.isNotEmpty(cell6)){ hobbyStr = String.valueOf(cell6.getStringCellValue()).trim(); } Cell cell7 = row.getCell(7); //交友原则 String principleStr = null; if (SinataUtil.isNotEmpty(cell7)){ principleStr = String.valueOf(cell7.getStringCellValue()).trim(); } Cell cell8 = row.getCell(8); //身高cm String height = null; if (SinataUtil.isNotEmpty(cell8)){ height = String.valueOf(cell8.getStringCellValue()).trim(); } Cell cell9 = row.getCell(9); //体重kg String weight = null; if (SinataUtil.isNotEmpty(cell9)){ weight = String.valueOf(cell9.getStringCellValue()).trim(); } Cell cell10 = row.getCell(10); //个人简介 String introduction = null; if (SinataUtil.isNotEmpty(cell10)){ introduction = String.valueOf(cell10.getStringCellValue()).trim(); } if (SinataUtil.isEmpty(nickname) || SinataUtil.isEmpty(sex) || SinataUtil.isEmpty(authType) || SinataUtil.isEmpty(isGoddess) || SinataUtil.isEmpty(isVip) || SinataUtil.isEmpty(birthday) || SinataUtil.isEmpty(hobbyStr) || SinataUtil.isEmpty(principleStr)){ continue; }else{ if (SinataUtil.isNotEmpty(height)){ if (!isDouble(height)){ continue; } } if (SinataUtil.isNotEmpty(weight)){ if (!isDouble(weight)){ continue; } } String constellation = null; try { String time = importByExcelForDate(birthday); constellation = ConstellationUtil.getConstellation(time); }catch (Exception e){ continue; } /*AppUserInfo user = new AppUserInfo(); user.setAddTime(new Date()); user.setConstellation(constellation); user.setNickname(nickname); user.setSex(Integer.valueOf(sex)); user.setIsGoddess(Integer.valueOf(isGoddess)); user.setAuthType(Integer.valueOf(authType)); user.setIsVip(Integer.valueOf(isVip)); user.setState(1); user.setBirthday(birthday); user.setHobbyStr(hobbyStr); user.setPrincipleStr(principleStr); if (SinataUtil.isNotEmpty(height)) user.setHeight(Double.valueOf(height)); if (SinataUtil.isNotEmpty(weight)) user.setWeight(Double.valueOf(weight)); if (SinataUtil.isNotEmpty(introduction)) user.setIntroduction(introduction); user.setIsComplete(1); user.setIsMachine(2); appUserInfoService.insert(user);*/ } } } catch (Exception e) { e.printStackTrace(); } } /** * 转换日期 * @return */ public static String importByExcelForDate(String value) {//value就是它的天数 String currentCellValue = ""; if(value != null && !value.equals("")){ Calendar calendar = new GregorianCalendar(1900,0,-1); Date d = calendar.getTime(); Date dd = DateUtils.addDays(d,Integer.valueOf(value)); DateFormat formater = new SimpleDateFormat("yyyy-MM-dd"); currentCellValue = formater.format(dd); } return currentCellValue; } /** * 验证是否可以字符转为金额值 * @param str * @return */ public static boolean isDouble(String str) { try{ Double.parseDouble(str); return true; }catch(NumberFormatException e) { System.out.println("异常:\"" + str + "\"不是数字/整数/小数..."); return false; } } }