导入


1.jsp

 <body>
            <div class="mini-fit" id="enterpriseinformationimport-form">

                <br>
                <a href="${contextPath}/resources/temp/enterpriseinfoimport.xlsx">模板下载</a>  (需要你自己也一个模板放在文件夹下)
                <br>
                <br>
                <form name="form" action="${contextPath}/enterprisemanagementfunction-enterprisemanagementfunction/enterprisemanagementfunction-import-save.html"
                    method="post" enctype="multipart/form-data">
                    导入:
                    <input type="file" name="file" id="file" />
                    <button type="button" id="submit">上传文件</button>
                </form>

            </div>
        </body>

2.引入js  (jquery.form.js)  

博客不能放文件,需要的留言

3.

var EnterpriseManagementFunctionimport = {
    importForm: null,
    attachmentUploadData: null,
    init: function() {
        var me = this;
        mini.parse();
        me.courseScheduleImportSetEvents();
    },
    courseScheduleImportSetEvents: function() {
        var me = this;
        $('#enterpriseinformationimport-form').delegate('#submit', 'click', function() {
            me.submit();
        });
    },
    submit: function() {
        var  form  =  $("form[name=form]"); 
        var  options  = {   
            dataType: 'json',
            success: function(data) {
                if (data.success) {
                    mini.alert(data.message, '提示', function() {
                        window.CloseOwnerWindow();
                        window.location.reload();
                    });
                } else {
                    alert(data.message);
                }
            }    
        };    
        form.ajaxSubmit(options);
    },
};
$(function() {
    EnterpriseManagementFunctionimport.init();
});

4.action

 /*
     * 导入
     */

    @Action("/enterprisemanagementfunction-enterprisemanagementfunction/enterprisemanagementfunction-import")
    public String enterpriseManagementFunctionimport() {
        return "enterprisemanagementfunction-import";
    }

    @Action("/enterprisemanagementfunction-enterprisemanagementfunction/enterprisemanagementfunction-import-save")
    public void importCourseschedule() throws FileUploadException, IOException {
        try {
            String msg = this.enterpriseManagementFunctionService.saveEnterpriseInformationImport(file);
            sendMsg(true, "", msg);
        } catch (final Throwable e) {
            LOGGER.error("Action:EnterpriseManagementFunctionAction Method:importCourseschedule error ", e);
            sendFailMsg("", "查询失败!");
        }

    }
   @Override
    public String saveEnterpriseInformationImport(final File file) {
        try {
            final UserSession userSession = UserThreadLocal.getUserSession();
            final FileInputStream io = new FileInputStream(file);
            XSSFWorkbook workbook = new XSSFWorkbook(io);
            XSSFSheet sheet = workbook.getSheetAt(0);
            final Iterator<Row> rowIterator = sheet.iterator();
            int i = 0;
            String msg = "";
            while (rowIterator.hasNext()) {
                i++;
                final Row row = rowIterator.next();
                final String email = genCellStringValue(row.getCell(7));
                if (row.getRowNum() < 1) {
                    continue;
                }
                if (StringUtils.isBlank(email)) {
                    msg += "第" + i + "行,邮箱为空。";
                    continue;
                }
                final BaseEnterpriseManagementFunctionPojo enterpriseManagementFunction = rowToEntity(row);
                enterpriseManagementFunction.setCreateUserId(userSession.getUserId());
                enterpriseManagementFunction.setCreateUserName(userSession.getUserName());
                enterpriseManagementFunction.setCreateTime(new Date());
                enterpriseManagementFunction.setDictDeletedValue(DictDeletedType.NOT_DELTEED.getId());
                enterpriseManagementFunction.setDictDeletedName(DictDeletedType.NOT_DELTEED.getNameCn());
                if (!UserOperation.loginNameCheck(enterpriseManagementFunction.getEmail())) {
                    Long successMark = UserOperation.saveUser(enterpriseManagementFunction.getEmail(),
                                                              Constants.DEFAULT_PWD, "", "2");
                    if (null != successMark) {
                        this.save(enterpriseManagementFunction);
                    } else {
                        // 创建用户失败
                        msg += "第" + i + "行,创建用户失败。";
                    }
                } else {
                    // 用户名重复
                    msg += "第" + i + "行,用户名重复。";
                }
            }
            io.close();
            return StringUtils.isNotEmpty(msg) ? msg : "导入成功";
        } catch (final Exception e) {
            e.printStackTrace();
        }
        return "导入失败";
    }

    private BaseEnterpriseManagementFunctionPojo rowToEntity(final Row row) {
        final BaseEnterpriseManagementFunctionPojo baseEnterpriseManagementFunctionPojo =
                new BaseEnterpriseManagementFunctionPojo();
        baseEnterpriseManagementFunctionPojo.setAnEnterpriseName(genCellStringValue(row.getCell(0)));
        baseEnterpriseManagementFunctionPojo.setAddress(genCellStringValue(row.getCell(1)));
        baseEnterpriseManagementFunctionPojo.setSocialCreditCode(genCellStringValue(row.getCell(2)));
        baseEnterpriseManagementFunctionPojo.setFkUnitOfNatureName(genCellStringValue(row.getCell(3)));
        baseEnterpriseManagementFunctionPojo.setFkUnitOfIndustryName(genCellStringValue(row.getCell(4)));
        baseEnterpriseManagementFunctionPojo
                .setTheRegisteredCapital(String.valueOf(row.getCell(5).getStringCellValue()));
        baseEnterpriseManagementFunctionPojo
                .setUndergraduateAndGraduate(String.valueOf(row.getCell(6).getStringCellValue()));
        baseEnterpriseManagementFunctionPojo.setEmail(String.valueOf(row.getCell(7).getStringCellValue()));
        return baseEnterpriseManagementFunctionPojo;
    }

    private String genCellStringValue(final Cell cell) {
        if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
            return String.valueOf(cell.getBooleanCellValue());
        } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            final DecimalFormat df = new DecimalFormat("#");
            return String.valueOf(df.format(cell.getNumericCellValue()));
        } else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
            return String.valueOf(cell.getStringCellValue());
        } else
            return String.valueOf(cell.getStringCellValue());
    }


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值