Search in sources :

Example 1 with ExcelRdException

use of com.fruit.manage.util.excelRd.ExcelRdException in project fruit-manage by liuzhaozhao.

the class PlanDetailController method readExcel.

public static List<ExcelRdRow> readExcel(String filePath) {
    ExcelRd excelRd = new ExcelRd(filePath);
    excelRd.setStartRow(1);
    excelRd.setStartCol(0);
    ExcelRdTypeEnum[] types = { ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.DOUBLE, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING };
    // 指定每列的类型
    excelRd.setTypes(types);
    List<ExcelRdRow> rows = null;
    try {
        rows = excelRd.analysisXlsx();
    } catch (ExcelRdException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return rows;
}
Also used : ExcelRdException(com.fruit.manage.util.excelRd.ExcelRdException) ExcelRdRow(com.fruit.manage.util.excelRd.ExcelRdRow) ExcelRdTypeEnum(com.fruit.manage.util.excelRd.ExcelRdTypeEnum) IOException(java.io.IOException) ExcelRd(com.fruit.manage.util.excelRd.ExcelRd)

Example 2 with ExcelRdException

use of com.fruit.manage.util.excelRd.ExcelRdException in project fruit-manage by liuzhaozhao.

the class ExcelController method setProcurementQuota.

/**
 * 采购:导入采购配额
 */
public void setProcurementQuota() {
    Integer uid = getSessionAttr(Constant.SESSION_UID);
    String name = User.dao.findById(uid).getName();
    String fileName = getPara("fileName");
    File file = new File(BASE_PATH + File.separator + fileName);
    try {
        // xls表头顺序:商品名,,规格名,规格编码,采购姓名,采购人编码
        List<Object[]> excelData = ExcelCommon.excelRd(file, 4, 1, new ExcelRdTypeEnum[] { ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER });
        List<ProductStandard> productStandardList = ProductStandard.dao.getProductStandardAllInfo();
        for (Object[] excelRow : excelData) {
            for (ProductStandard productStandard : productStandardList) {
                if (productStandard.get("product_standard_id") != null && productStandard.get("product_standard_id").equals(excelRow[3])) {
                    if (StringUtils.isNotBlank((String) excelRow[4]) && excelRow[5] != null) {
                        ProcurementQuota procurementQuota = new ProcurementQuota();
                        procurementQuota.setProductId(productStandard.get("product_id"));
                        procurementQuota.setProductName(productStandard.get("product_name"));
                        procurementQuota.setProductStandardName(productStandard.get("product_standard_name"));
                        procurementQuota.setProductStandardId(productStandard.get("product_standard_id"));
                        procurementQuota.setProcurementName((String) excelRow[4]);
                        procurementQuota.setProcurementId((Integer) excelRow[5]);
                        procurementQuota.setCreateTime(new Date());
                        procurementQuota.setCreateUserId(uid);
                        procurementQuota.setCreateUserName(name);
                        procurementQuota.save();
                    }
                    break;
                }
            }
        }
        renderNull();
        return;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ExcelRdException e) {
        e.printStackTrace();
    }
    renderErrorText("导入失败,请联系技术修复");
}
Also used : ExcelRdException(com.fruit.manage.util.excelRd.ExcelRdException) IOException(java.io.IOException) File(java.io.File) Date(java.util.Date)

Example 3 with ExcelRdException

use of com.fruit.manage.util.excelRd.ExcelRdException in project fruit-manage by liuzhaozhao.

the class PlanDetailController method uploaderExcel.

public void uploaderExcel() {
    // UploadFile uploadFile=getFile("file");
    try {
        String fileName = getPara("fileName");
        String filePath = CommonController.FILE_PATH + File.separator + fileName;
        ExcelRd excelRd = new ExcelRd(filePath);
        excelRd.setStartRow(1);
        excelRd.setStartCol(0);
        ExcelRdTypeEnum[] types = { ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.STRING, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.DOUBLE, ExcelRdTypeEnum.INTEGER, ExcelRdTypeEnum.STRING };
        // 指定每列的类型
        excelRd.setTypes(types);
        List<ExcelRdRow> rows = null;
        try {
            rows = excelRd.analysisXlsx();
        } catch (ExcelRdException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Iterator<ExcelRdRow> iterator = rows.iterator();
        Integer count = 0;
        String[] createTimes = new String[2];
        Map<Integer, List<Integer>> map = new HashMap<>(12);
        while (iterator.hasNext()) {
            ExcelRdRow next = iterator.next();
            List<Object> row = next.getRow();
            count++;
            if (count == 1) {
                String createTimeStr = ((String) row.get(0)).split(" ")[0].substring(5);
                createTimes[0] = DateAndStringFormat.getNextDay(createTimeStr, "-1") + " 12:00:00";
                createTimes[1] = createTimeStr + " 11:59:59";
            }
            if (count > 2) {
                boolean flag = false;
                ProcurementPlanDetail procurementPlanDetail = ProcurementPlanDetail.dao.getPPlanDetailByPSID((Integer) row.get(0), createTimes, null);
                if (procurementPlanDetail != null) {
                    List<Integer> userIDs = map.get(row.get(0));
                    if (userIDs != null) {
                        for (int i = 0; i < userIDs.size(); i++) {
                            Integer userID = userIDs.get(i);
                            if (userID != null && userID != (int) row.get(5)) {
                                flag = true;
                                userIDs.add((int) row.get(5));
                                map.put((int) row.get(0), userIDs);
                                break;
                            } else {
                                userIDs.add((int) row.get(5));
                                map.put((int) row.get(0), userIDs);
                            }
                        }
                    } else {
                        if (userIDs == null) {
                            userIDs = new ArrayList<>();
                        }
                        userIDs.add((int) row.get(5));
                        map.put((int) row.get(0), userIDs);
                    }
                    if (flag) {
                        procurementPlanDetail.setId(null);
                        procurementPlanDetail.setProductStandardId((int) row.get(0));
                        procurementPlanDetail.setProductName((String) row.get(1));
                        procurementPlanDetail.setProductStandardName((String) row.get(2));
                        procurementPlanDetail.setProcurementNum((int) row.get(3));
                        procurementPlanDetail.setProcurementNeedPrice(new BigDecimal((Double) row.get(4)));
                        procurementPlanDetail.setProcurementId((int) row.get(5));
                        procurementPlanDetail.setProcurementRemark((String) row.get(6));
                        BigDecimal pNeedPrice = new BigDecimal((Double) row.get(4));
                        BigDecimal pNum = new BigDecimal((int) row.get(3));
                        procurementPlanDetail.setProcurementTotalPrice(pNeedPrice.multiply(pNum));
                        procurementPlanDetail.setUpdateTime(new Date());
                        procurementPlanDetail.save();
                    } else {
                        procurementPlanDetail.setProductStandardId((int) row.get(0));
                        procurementPlanDetail.setProductName((String) row.get(1));
                        procurementPlanDetail.setProductStandardName((String) row.get(2));
                        procurementPlanDetail.setProcurementNum((int) row.get(3));
                        procurementPlanDetail.setProcurementNeedPrice(new BigDecimal((Double) row.get(4)));
                        procurementPlanDetail.setProcurementId((int) row.get(5));
                        procurementPlanDetail.setProcurementRemark((String) row.get(6));
                        BigDecimal pNeedPrice = new BigDecimal((Double) row.get(4));
                        BigDecimal pNum = new BigDecimal((int) row.get(3));
                        procurementPlanDetail.setProcurementTotalPrice(pNeedPrice.multiply(pNum));
                        procurementPlanDetail.setUpdateTime(new Date());
                        procurementPlanDetail.update();
                    }
                }
            }
        }
        // 进行删除操作
        List<ProcurementPlanDetail> procurementPlanDetails = ProcurementPlanDetail.dao.getPSIDAndPSCount(createTimes);
        for (int i = 0; i < procurementPlanDetails.size(); i++) {
            ProcurementPlanDetail procurementPlanDetail = procurementPlanDetails.get(i);
            Integer psID = procurementPlanDetail.getProductStandardId();
            Integer psCount = Integer.parseInt(procurementPlanDetail.get("pscount") + "");
            List<Integer> list = map.get(psID);
            // 判断导入的用户是否少了
            if (list != null && list.size() < psCount) {
                List<ProcurementPlanDetail> procurementPlanDetailList = ProcurementPlanDetail.dao.getPPDIDAndProcurementID(createTimes, psID);
                for (int j = 0; j < procurementPlanDetailList.size(); j++) {
                    ProcurementPlanDetail procurementPlanDetail2 = procurementPlanDetailList.get(j);
                    Integer procurementId = procurementPlanDetail2.getProcurementId();
                    Integer id = procurementPlanDetail2.getId();
                    boolean isExist = false;
                    for (int k = 0; k < list.size(); k++) {
                        if (procurementId != null && procurementId.equals(list.get(k))) {
                            isExist = true;
                        }
                    }
                    if (!isExist) {
                        procurementPlanDetail2.deleteById(id);
                    }
                }
            }
        }
        renderJson(new ArrayList<>().add(0));
    } catch (Exception e) {
        renderJson(new ArrayList<>().add(1));
    }
}
Also used : ProcurementPlanDetail(com.fruit.manage.model.ProcurementPlanDetail) ExcelRd(com.fruit.manage.util.excelRd.ExcelRd) ExcelRdException(com.fruit.manage.util.excelRd.ExcelRdException) IOException(java.io.IOException) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) ExcelRdException(com.fruit.manage.util.excelRd.ExcelRdException) ExcelRdRow(com.fruit.manage.util.excelRd.ExcelRdRow) ExcelRdTypeEnum(com.fruit.manage.util.excelRd.ExcelRdTypeEnum)

Aggregations

ExcelRdException (com.fruit.manage.util.excelRd.ExcelRdException)3 IOException (java.io.IOException)3 ExcelRd (com.fruit.manage.util.excelRd.ExcelRd)2 ExcelRdRow (com.fruit.manage.util.excelRd.ExcelRdRow)2 ExcelRdTypeEnum (com.fruit.manage.util.excelRd.ExcelRdTypeEnum)2 ProcurementPlanDetail (com.fruit.manage.model.ProcurementPlanDetail)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1