| | |
| | | package com.yeshi.fanli.util.elme;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Properties;
|
| | |
|
| | | import javax.mail.Folder;
|
| | | import javax.mail.Message;
|
| | | import javax.mail.Part;
|
| | | import javax.mail.Session;
|
| | | import javax.mail.Store;
|
| | | import javax.mail.internet.MimeMessage;
|
| | |
|
| | | import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
| | | import org.apache.poi.ss.usermodel.Cell;
|
| | | import org.apache.poi.ss.usermodel.Row;
|
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
| | | import org.yeshi.utils.mail.ShowMail;
|
| | |
|
| | | import com.yeshi.fanli.entity.elme.ElmeOrder;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | |
|
| | | public class ElmeOrderUtil {
|
| | |
|
| | | public static List<ElmeOrder> parseOrder(InputStream is) {
|
| | | List<ElmeOrder> list = new ArrayList<>();
|
| | |
|
| | | org.apache.poi.ss.usermodel.Workbook wb = null;
|
| | | try {
|
| | | wb = new XSSFWorkbook(is);
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | // 开始解析
|
| | | org.apache.poi.ss.usermodel.Sheet sheet = wb.getSheetAt(0);
|
| | |
|
| | | Row firstRow = sheet.getRow(0);
|
| | | for (int r = 1; r <= sheet.getLastRowNum(); r++) {
|
| | | ElmeOrder order = new ElmeOrder();
|
| | | Row row = sheet.getRow(r);
|
| | | for (int c = row.getFirstCellNum(); c < row.getLastCellNum(); c++) {
|
| | | Cell cell = row.getCell(c);
|
| | | String content = null;
|
| | |
|
| | | String columnName = firstRow.getCell(c).getStringCellValue().trim();
|
| | | if (cell == null)
|
| | | continue;
|
| | | if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
|
| | | if (HSSFDateUtil.isCellDateFormatted(cell)) { // 判断日期类型
|
| | | Date date = cell.getDateCellValue();
|
| | | content = TimeUtil.getGernalTime(date.getTime(), "yyyy-MM-dd");
|
| | | } else { // 否
|
| | | content = cell.getNumericCellValue() + "";
|
| | | }
|
| | |
|
| | | } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
|
| | | content = (cell.getStringCellValue());
|
| | | }
|
| | | switch (columnName) {
|
| | | case "渠道号":
|
| | | order.setChannelId(new BigDecimal(content).longValue() + "");
|
| | | break;
|
| | | case "渠道名称":
|
| | | order.setChannelName(content);
|
| | | break;
|
| | | case "track_pid":
|
| | | order.setTrackPid(content);
|
| | | break;
|
| | | case "rid":
|
| | | order.setRid(new BigDecimal(content).longValue() + "");
|
| | | break;
|
| | | case "订单日期":
|
| | | order.setOrderDate(new Date(TimeUtil.convertToTimeTemp(content, "yyyy-MM-dd")));
|
| | | break;
|
| | | case "订单号":
|
| | | order.setOrderId(content.replace("<", "").replace(">", "").replace("<", "").replace(">", ""));
|
| | | break;
|
| | | case "支付金额":
|
| | | order.setPayMoney(new BigDecimal(content));
|
| | | break;
|
| | | case "下单城市":
|
| | | order.setCity(content);
|
| | | break;
|
| | | case "用券金额":
|
| | | order.setCouponMoney(new BigDecimal(content));
|
| | | break;
|
| | | case "是否新客首单":
|
| | | order.setNewerFirstOrder(new BigDecimal(content).intValue());
|
| | | break;
|
| | | case "是否新客复购单":
|
| | | order.setNewerRepayOrder(new BigDecimal(content).intValue());
|
| | | break;
|
| | | case "是否使用淘客红包":
|
| | | order.setTaokeHongBao(new BigDecimal(content).intValue());
|
| | | break;
|
| | | case "是否有在会场内该门店的点击记录":
|
| | | order.setShopClick(new BigDecimal(content).intValue());
|
| | | break;
|
| | | case "是否领券后7天内首单":
|
| | | order.setRecieveCoupon7DayFirstOrder(new BigDecimal(content).intValue());
|
| | | break;
|
| | | case "是否6结佣":
|
| | | if ("是".equalsIgnoreCase(content))
|
| | | order.setIsSettle(true);
|
| | | else
|
| | | order.setIsSettle(false);
|
| | | break;
|
| | | }
|
| | | }
|
| | | list.add(order);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | public static BigDecimal getCommission(BigDecimal payMoney) {
|
| | | return MoneyBigDecimalUtil.mul(payMoney, new BigDecimal("0.06"));
|
| | | }
|
| | |
|
| | | public static List<ElmeOrder> pullLatest5DayOrder() {
|
| | | List<ElmeOrder> totalOrderList = new ArrayList<>();
|
| | | String host = "pop.qq.com";
|
| | | String username = "2780501319@qq.com";
|
| | | String password = "dbltidaeknumdgfd";
|
| | | Properties props = new Properties();
|
| | | Session session = Session.getDefaultInstance(props, null);
|
| | | try {
|
| | | Store store = session.getStore("pop3");
|
| | | store.connect(host, username, password);
|
| | | Folder folder = store.getFolder("INBOX");
|
| | | folder.open(Folder.READ_ONLY);
|
| | | Message message[] = folder.getMessages();
|
| | | List<Message> list = Arrays.asList(message);
|
| | | int count = 0;
|
| | | for (int i = list.size() - 1; i >= 0; i--) {
|
| | | ShowMail showMail = new ShowMail((MimeMessage) list.get(i));
|
| | | if ("qiuming.wu<qiuming.wu@ele.me>".equalsIgnoreCase(showMail.getFrom())) {
|
| | | if (count++ > 5)
|
| | | break;
|
| | | try {
|
| | | boolean attch = showMail.isContainAttach((Part) list.get(i));
|
| | | if (attch) {
|
| | | List<InputStream> attchList = showMail.saveAttachMent((Part) list.get(i));
|
| | | if (attchList.size() > 0) {
|
| | | List<ElmeOrder> orderList = ElmeOrderUtil.parseOrder(attchList.get(0));
|
| | | if (orderList != null && orderList.size() > 0)
|
| | | totalOrderList.addAll(orderList);
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | |
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | return totalOrderList;
|
| | | }
|
| | |
|
| | | }
|