Search in sources :

Example 1 with Wrap

use of com.kendy.other.Wrap in project financial by greatkendy123.

the class ExcelReaderUtil method readHuishuiRecord.

/**
 * 导入回水
 * @param file
 * @return
 */
public static Wrap readHuishuiRecord(File file) {
    Map<String, Huishui> huishuiMap = new HashMap<>();
    Wrap wrap = new Wrap();
    try {
        FileInputStream is = new FileInputStream(file);
        log.info("读取团队回水开始...");
        Workbook workbook = getWeebWork(file.getAbsolutePath());
        // 回水对应的sheet
        Sheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            if (row.getRowNum() >= 2) {
                // 团队id
                String teamId = "";
                // 团队名称
                String teamName = "";
                // 回水比例
                String huishuiRate = "";
                // 备注
                String beizhu = "";
                // 保险比例
                String insuranceRate = "";
                // 股东
                String gudong = "";
                // 是否代理
                String zjManage = "";
                // 代理回水比例
                String proxyHsRate = "";
                // 代理回保比例
                String proxyHbRate = "";
                // 代理服务费
                String proxyFWF = "";
                // 积分比例
                String jfPercent = "";
                for (int i = 1; i < 11; i++) {
                    Cell cell = row.getCell(i);
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    String value = cell.getStringCellValue();
                    if (i == 1) {
                        // 团ID====="+value);
                        if (!StringUtil.isBlank(value))
                            value = value.toUpperCase();
                        teamId = value;
                    } else if (i == 2) {
                        // 团队名字====="+value);
                        teamName = StringUtil.isBlank(value) ? "" : value;
                    } else if (i == 3) {
                        if (!StringUtil.isBlank(value) && value.contains("E")) {
                            value = Double.valueOf(value) + "";
                        }
                        // 回水比例====="+value);
                        if (value.contains("%")) {
                            value = NumUtil.getNumByPercent(value) + "";
                        }
                        huishuiRate = value;
                    } else if (i == 4) {
                        // 保险比例====="+value);
                        if (value.contains("%")) {
                            value = NumUtil.getNumByPercent(value) + "";
                        }
                        insuranceRate = StringUtil.isBlank(value) ? "0" : NumUtil.digit4(value);
                    } else if (i == 5) {
                        // 股东====="+value);
                        gudong = value;
                    } else if (i == 6) {
                        // 战绩是否代理管====="+value);
                        zjManage = StringUtil.isBlank(value) ? "否" : value;
                    } else if (i == 7) {
                        // 备注====="+value);
                        beizhu = value;
                    } else if (i == 8) {
                        if (StringUtil.isBlank(value)) {
                            value = "0";
                        }
                        if (value.contains("%")) {
                            proxyHsRate = value;
                        } else {
                            // 回水比例====="+NumUtil.getPercentStr(Double.valueOf(value)));
                            proxyHsRate = NumUtil.getPercentStr(Double.valueOf(value));
                        }
                    } else if (i == 9) {
                        if (StringUtil.isBlank(value)) {
                            value = "0";
                        }
                        if (value.contains("%")) {
                            proxyHbRate = value;
                        } else {
                            // 回保比例====="+NumUtil.getPercentStr(Double.valueOf(value)));
                            proxyHbRate = NumUtil.getPercentStr(Double.valueOf(value));
                        }
                    } else if (i == 10) {
                        // 服务费====="+value);
                        proxyFWF = value;
                    } else if (i == 11) {
                        // 积分比例====="+value);
                        if (StringUtil.isBlank(value)) {
                            value = "0";
                        }
                        jfPercent = NumUtil.getPercentStr(Double.valueOf(value));
                    }
                }
                if (!StringUtil.isBlank(teamId))
                    huishuiMap.put(teamId, new Huishui(teamId, teamName, huishuiRate, insuranceRate, gudong, zjManage, beizhu, proxyHsRate, proxyHbRate, proxyFWF));
            }
        }
        is.close();
        wrap = new Wrap(true, huishuiMap);
        log.info("读取团队回水结束!size:" + huishuiMap.size());
    } catch (Exception e) {
        wrap = new Wrap();
        e.printStackTrace();
    }
    return wrap;
}
Also used : Huishui(com.kendy.entity.Huishui) Wrap(com.kendy.other.Wrap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Example 2 with Wrap

use of com.kendy.other.Wrap in project financial by greatkendy123.

the class MyController method importZJExcelAction.

/**
 * 导入战绩文件
 */
public void importZJExcelAction(ActionEvent even) {
    String zjFilePath = excelDir.getText();
    if (!StringUtil.isBlank(zjFilePath)) {
        String tableId = zjFilePath.substring(zjFilePath.lastIndexOf("-") + 1, zjFilePath.lastIndexOf("."));
        if (!NumUtil.isNumeric(tableId)) {
            ErrorUtil.err(zjFilePath + "不是一个合法的Excel文件名称,请检查!");
            return;
        }
        if (hbox_autoTestMode.isVisible()) {
            final_selected_LM_type = "联盟1";
            selected_LM_type = "联盟1";
        } else {
            selectLM();
            if (StringUtil.isBlank(selected_LM_type)) {
                String msg = "导入战绩时没有选择对应的联盟,场次:" + tableId + " Excel不准导入!";
                ShowUtil.show(msg);
                log.warn(msg);
                return;
            }
        }
        // 将人员名单文件缓存起来
        Wrap wrap = ExcelReaderUtil.readZJRecord(new File(zjFilePath), lable_currentClubId.getText(), selected_LM_type, getVersionType());
        dateLabel.setText(DataConstans.Date_Str);
        if (wrap.resultSuccess) {
            indexLabel.setText("第" + tableId + "局");
            // //1 填充总信息表
            // MoneyService.fillTablerAfterImportZJ(tableTotalInfo, tablePaiju,tableDangju,tableJiaoshou,tableTeam,(List<UserInfos>)wrap.obj,tableId);
            // //2填充当局表和交收表和团队表的总和
            // MoneyService.setTotalNumOnTable(tableDangju, DataConstans.SumMap.get("当局"));
            // MoneyService.setTotalNumOnTable(tableJiaoshou, DataConstans.SumMap.get("交收"));
            // tableTeam.getColumns().get(4).setText(MoneyService.digit0(DataConstans.SumMap.get("团队回水及保险总和")));
            importExcelData(tableId, (List<UserInfos>) wrap.obj);
            // 导入不可用
            importZJBtn.setDisable(true);
            ShowUtil.show("导入战绩文件成功", 2);
        } else {
            ShowUtil.show("导入失败!!!原因:" + wrap.obj, 2);
        }
    }
}
Also used : Wrap(com.kendy.other.Wrap) UserInfos(com.kendy.entity.UserInfos) File(java.io.File)

Example 3 with Wrap

use of com.kendy.other.Wrap in project financial by greatkendy123.

the class MyController method importHuishuiExcelAction.

/**
 * 导入回水比例文件
 */
public void importHuishuiExcelAction(ActionEvent even) {
    String huishuiFilePath = huishuiDir.getText();
    if (!StringUtil.isBlank(huishuiFilePath)) {
        // 将人员名单文件缓存起来
        Wrap wrap = ExcelReaderUtil.readHuishuiRecord(new File(huishuiFilePath));
        if (wrap.resultSuccess) {
            DataConstans.huishuiMap.putAll((Map<String, Huishui>) wrap.obj);
            DBUtil.insertTeamHS((Map<String, Huishui>) wrap.obj);
            ShowUtil.show("导入回水比例成功", 2);
            // importHuishuiBtn.setDisable(true);//导入后不再导了
            // 代理查询初始化团队ID
            TeamProxyService.initTeamSelectAndZjManage(teamIDCombox);
            // 积分查询初始化团队ID
            JifenService.init_Jifen_TeamIdCombox();
            // 上码系统中的团队ID按钮
            ShangmaService.initShangmaButton();
        } else {
            ShowUtil.show("导入回水比例失败", 2);
        }
    }
}
Also used : Huishui(com.kendy.entity.Huishui) Wrap(com.kendy.other.Wrap) File(java.io.File)

Example 4 with Wrap

use of com.kendy.other.Wrap in project financial by greatkendy123.

the class ExcelReaderUtil method readZJRecord_NewVersion.

/**
 * 导入战绩Excel
 *
 * 两个功能:
 * 	A:导入到场次信息
 * 	B:导入到联盟Tab
 *
 * @param file 文件夹
 * @return
 */
public static Wrap readZJRecord_NewVersion(File file, String userClubId, String LMType) {
    // 新增了联盟类型
    List<UserInfos> userInfoList = new LinkedList<>();
    UserInfos info = null;
    FileInputStream is = null;
    // 是否已经判断过为空 波哥要求添加
    boolean isHasJudged = false;
    try {
        // 桌号
        String name = file.getName();
        String tableId = name.substring(name.lastIndexOf("-") + 1, name.lastIndexOf("."));
        tableId = "第" + tableId + "局";
        if (StringUtil.isBlank(userClubId) || DataConstans.Index_Table_Id_Map.containsValue(tableId)) {
            return new Wrap(false, "该战绩表(" + tableId + "场次)已经导过");
        }
        log.info("开始----------导入战绩Excel");
        userInfoList = new LinkedList<>();
        is = new FileInputStream(file);
        // 获取excel sheet
        Workbook workbook = (XSSFWorkbook) getWeebWork(file.getAbsolutePath());
        XSSFSheet sheet = (XSSFSheet) workbook.getSheetAt(0);
        // 若无数据,要提示
        int rowNum = sheet.getLastRowNum();
        if (rowNum == 0 && !isHasJudged) {
            isHasJudged = true;
            ShowUtil.show("提示:总手数为0!");
        }
        // 开始遍历Excel行数据
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            XSSFRow row = (XSSFRow) rowIterator.next();
            // add 总手数为空的提示
            // Cell ZSScell = row.getCell(6);
            XSSFCell ZSScell = row.getCell(7);
            if (ZSScell == null) {
                continue;
            }
            // 总手数
            String totalHandCount = ZSScell.toString();
            Integer _tempCount = 0;
            if (!"总手数".equals(totalHandCount)) {
                try {
                    _tempCount = Integer.valueOf(totalHandCount);
                    if (_tempCount == 0) {
                        if (!isHasJudged) {
                            isHasJudged = true;
                            ShowUtil.show("提示:总手数为0!");
                        }
                    }
                } catch (Exception e) {
                    _tempCount = 1;
                }
            }
            info = new UserInfos();
            // 排除第一行以及俱乐部ID不匹配的情况
            // String clubID = row.getCell(9).toString();
            String clubID = row.getCell(10).toString();
            if (row.getRowNum() != 0 && userClubId.equals(row.getCell(10).toString())) {
                // 对于符合条件的进行存储
                // int[] clumns = new int[]{6,7,8,9, 10,15,17,18,19};
                int[] clumns = new int[] { 7, 8, 9, 10, 11, 16, 18, 19, 20 };
                for (int cn : clumns) {
                    XSSFCell cell = row.getCell(cn);
                    if (cell == null) {
                        log.error("出现空值,导入战绩文件夹失败" + "\t");
                        return new Wrap();
                    }
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    String value = cell.getStringCellValue();
                    value = StringUtil.isBlank(value) ? "" : value.trim();
                    switch(cn) {
                        case // add 总手数(只判断不导入)
                        7:
                            if ((StringUtil.isBlank(value) || "0".equals(value)) && !isHasJudged) {
                                isHasJudged = true;
                                ShowUtil.show("提示:总手数为0!");
                            }
                            break;
                        case 8:
                            info.setPlayerId(value);
                            break;
                        case 9:
                            info.setPlayerName(value);
                            break;
                        case 10:
                            info.setClubId(value);
                            break;
                        case 11:
                            info.setClubName(value);
                            break;
                        case 16:
                            info.setInsurance(value);
                            break;
                        case 19:
                            info.setZj(value);
                            break;
                        case 20:
                            {
                                String dateStr = value.split(" ")[0];
                                info.setDay(value);
                                // add 导入的第一局作为当天的时间
                                if (StringUtil.isBlank(DataConstans.Date_Str)) {
                                    DataConstans.Date_Str = dateStr;
                                } else {
                                    try {
                                        if (sdf.parse(dateStr).before(sdf.parse(DataConstans.Date_Str))) {
                                            DataConstans.Date_Str = dateStr;
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
                info.setTableId(tableId);
                userInfoList.add(info);
            }
        }
        // 遍历excel结束
        // 存储数据  {场次=infoList...}
        DataConstans.zjMap.put(tableId, userInfoList);
        is.close();
        // add 添加所有记录到联盟对帐表
        LMController.currentRecordList = LM_ExcelReaderUtil.readRecord_NewVersion(file);
        // LMController.refreshClubList();//放到锁定时去添加
        // LMController.checkOverEdu();
        log.info("结束----------导入战绩Excel" + " ===size:" + userInfoList.size());
    } catch (Exception e) {
        e.printStackTrace();
        return new Wrap();
    }
    return new Wrap(true, userInfoList);
}
Also used : Wrap(com.kendy.other.Wrap) UserInfos(com.kendy.entity.UserInfos) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row)

Example 5 with Wrap

use of com.kendy.other.Wrap in project financial by greatkendy123.

the class ExcelReaderUtil method readZJRecord_OldVersion.

/**
 * 导入战绩Excel
 *
 * 两个功能:
 * 	A:导入到场次信息
 * 	B:导入到联盟Tab
 *
 * @param file 文件夹
 * @return
 */
public static Wrap readZJRecord_OldVersion(File file, String userClubId, String LMType) {
    // 新增了联盟类型
    List<UserInfos> userInfoList = new LinkedList<>();
    UserInfos info = null;
    FileInputStream is = null;
    // 是否已经判断过为空 波哥要求添加
    boolean isHasJudged = false;
    try {
        // 桌号
        String name = file.getName();
        String tableId = name.substring(name.lastIndexOf("-") + 1, name.lastIndexOf("."));
        tableId = "第" + tableId + "局";
        if (StringUtil.isBlank(userClubId) || DataConstans.Index_Table_Id_Map.containsValue(tableId)) {
            return new Wrap(false, "该战绩表(" + tableId + "场次)已经导过");
        }
        log.info("开始----------导入战绩Excel");
        userInfoList = new LinkedList<>();
        is = new FileInputStream(file);
        // 获取excel sheet
        Workbook workbook = getWeebWork(file.getAbsolutePath());
        Sheet sheet = workbook.getSheetAt(0);
        // 若无数据,要提示
        int rowNum = sheet.getLastRowNum();
        if (rowNum == 0 && !isHasJudged) {
            isHasJudged = true;
            ShowUtil.show("提示:总手数为0!");
        }
        // 开始遍历Excel行数据
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            // add 总手数为空的提示
            Cell ZSScell = row.getCell(6);
            if (ZSScell == null) {
                break;
            }
            // 总手数
            String totalHandCount = ZSScell.toString();
            Integer _tempCount = 0;
            if (!"总手数".equals(totalHandCount)) {
                try {
                    _tempCount = Integer.valueOf(totalHandCount);
                    if (_tempCount == 0) {
                        if (!isHasJudged) {
                            isHasJudged = true;
                            ShowUtil.show("提示:总手数为0!");
                        }
                    }
                } catch (Exception e) {
                    _tempCount = 1;
                }
            }
            info = new UserInfos();
            // 排除第一行以及俱乐部ID不匹配的情况
            String clubID = row.getCell(9).toString();
            if (row.getRowNum() != 0 && userClubId.equals(row.getCell(9).toString())) {
                // 对于符合条件的进行存储
                int[] clumns = new int[] { 6, 7, 8, 9, 10, 15, 17, 18, 19 };
                for (int cn : clumns) {
                    Cell cell = row.getCell(cn);
                    if (cell == null) {
                        log.error("出现空值,导入战绩文件夹失败" + "\t");
                        return new Wrap();
                    }
                    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    String value = cell.getStringCellValue();
                    value = StringUtil.isBlank(value) ? "" : value.trim();
                    switch(cn) {
                        case // add 总手数(只判断不导入)
                        6:
                            if ((StringUtil.isBlank(value) || "0".equals(value)) && !isHasJudged) {
                                isHasJudged = true;
                                ShowUtil.show("提示:总手数为0!");
                            }
                            break;
                        case 7:
                            info.setPlayerId(value);
                            break;
                        case 8:
                            info.setPlayerName(value);
                            break;
                        case 9:
                            info.setClubId(value);
                            break;
                        case 10:
                            info.setClubName(value);
                            break;
                        case 15:
                            info.setInsurance(value);
                            break;
                        case 18:
                            info.setZj(value);
                            break;
                        case 19:
                            {
                                String dateStr = value.split(" ")[0];
                                info.setDay(value);
                                // add 导入的第一局作为当天的时间
                                if (StringUtil.isBlank(DataConstans.Date_Str)) {
                                    DataConstans.Date_Str = dateStr;
                                } else {
                                    try {
                                        if (sdf.parse(dateStr).before(sdf.parse(DataConstans.Date_Str))) {
                                            DataConstans.Date_Str = dateStr;
                                        }
                                    } catch (Exception e) {
                                    }
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }
                info.setTableId(tableId);
                userInfoList.add(info);
            }
        }
        // 遍历excel结束
        // 存储数据  {场次=infoList...}
        DataConstans.zjMap.put(tableId, userInfoList);
        is.close();
        // add 添加所有记录到联盟对帐表
        LMController.currentRecordList = LM_ExcelReaderUtil.readRecord(file);
        // LMController.refreshClubList();//放到锁定时去添加
        // LMController.checkOverEdu();
        log.info("结束----------导入战绩Excel" + " ===size:" + userInfoList.size());
    } catch (Exception e) {
        e.printStackTrace();
        return new Wrap();
    }
    return new Wrap(true, userInfoList);
}
Also used : Wrap(com.kendy.other.Wrap) UserInfos(com.kendy.entity.UserInfos) LinkedList(java.util.LinkedList) FileInputStream(java.io.FileInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Cell(org.apache.poi.ss.usermodel.Cell) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Aggregations

Wrap (com.kendy.other.Wrap)5 UserInfos (com.kendy.entity.UserInfos)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 Row (org.apache.poi.ss.usermodel.Row)3 Workbook (org.apache.poi.ss.usermodel.Workbook)3 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)3 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)3 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 Huishui (com.kendy.entity.Huishui)2 File (java.io.File)2 LinkedList (java.util.LinkedList)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1