Search in sources :

Example 1 with UserExcelVo

use of com.albedo.java.modules.sys.domain.vo.UserExcelVo in project albedo by somowhere.

the class UserResource method uploadData.

/**
 * @param dataFile
 * @param response
 * @return
 * @throws Exception
 */
@PostMapping(value = "/upload")
@PreAuthorize("@pms.hasPermission('sys_user_upload')")
@LogOperate(value = "用户管理导入")
public ResponseEntity<Result> uploadData(@RequestParam("uploadFile") MultipartFile dataFile, HttpServletResponse response) throws Exception {
    if (dataFile.isEmpty()) {
        return ResponseEntityBuilder.buildFail("上传文件为空");
    }
    ExcelUtil<UserExcelVo> util = new ExcelUtil(UserExcelVo.class);
    List<UserExcelVo> dataList = util.importExcel(dataFile.getInputStream());
    for (UserExcelVo userExcelVo : dataList) {
        if (userExcelVo.getPhone().length() != 11) {
            BigDecimal bd = new BigDecimal(userExcelVo.getPhone());
            userExcelVo.setPhone(bd.toPlainString());
        }
        userService.save(userExcelVo);
    }
    return ResponseEntityBuilder.buildOk("操作成功");
}
Also used : ExcelUtil(com.albedo.java.common.util.ExcelUtil) UserExcelVo(com.albedo.java.modules.sys.domain.vo.UserExcelVo) BigDecimal(java.math.BigDecimal) LogOperate(com.albedo.java.common.log.annotation.LogOperate) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

LogOperate (com.albedo.java.common.log.annotation.LogOperate)1 ExcelUtil (com.albedo.java.common.util.ExcelUtil)1 UserExcelVo (com.albedo.java.modules.sys.domain.vo.UserExcelVo)1 BigDecimal (java.math.BigDecimal)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1