|
|
@ -10,19 +10,26 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
|
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.feign.ResultDataResolver; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.poi.excel.handler.FreezeAndFilter; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
|
import com.epmet.dto.form.yt.CommunityBuildingManagerPageFormDTO; |
|
|
|
import com.epmet.dto.result.CommunityBuildingManagerDTO; |
|
|
|
import com.epmet.dto.result.ImportTaskCommonResultDTO; |
|
|
|
import com.epmet.dto.result.yt.CommunityBuildingManagerResultDTO; |
|
|
|
import com.epmet.service.CommunityBuildingManagerService; |
|
|
|
import com.epmet.utils.ImportTaskUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
import org.apache.poi.ss.usermodel.IndexedColors; |
|
|
@ -31,15 +38,19 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.PrintWriter; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.nio.file.Path; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -51,7 +62,7 @@ import java.util.List; |
|
|
|
@Slf4j |
|
|
|
@RestController |
|
|
|
@RequestMapping("communityBuildingManager") |
|
|
|
public class CommunityBuildingManagerController { |
|
|
|
public class CommunityBuildingManagerController implements ResultDataResolver { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private CommunityBuildingManagerService communityBuildingManagerService; |
|
|
@ -207,6 +218,53 @@ public class CommunityBuildingManagerController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 导入excel |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@PostMapping("import") |
|
|
|
public Result importExcel(MultipartFile file) { |
|
|
|
// 1.暂存文件
|
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); |
|
|
|
|
|
|
|
Path fileSavePath; |
|
|
|
try { |
|
|
|
Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir(ImportTaskConstants.COMMUNITY_BUILDING_MANAGER, "import"); |
|
|
|
fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName)); |
|
|
|
} catch (IOException e) { |
|
|
|
String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("【楼长单元长导入】创建临时存储文件失败:{}", errorMsg); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败"); |
|
|
|
} |
|
|
|
|
|
|
|
InputStream is = null; |
|
|
|
FileOutputStream os = null; |
|
|
|
|
|
|
|
try { |
|
|
|
is = file.getInputStream(); |
|
|
|
os = new FileOutputStream(fileSavePath.toString()); |
|
|
|
IOUtils.copy(is, os); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error(ImportTaskConstants.COMMUNITY_BUILDING_MANAGER + "表 importExcel exception", e); |
|
|
|
} finally { |
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(is); |
|
|
|
org.apache.poi.util.IOUtils.closeQuietly(os); |
|
|
|
} |
|
|
|
|
|
|
|
// 2.生成导入任务记录
|
|
|
|
ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException( |
|
|
|
ImportTaskUtils.createImportTask(originalFilename, ImportTaskConstants.COMMUNITY_BUILDING_MANAGER), |
|
|
|
ServiceConstant.EPMET_COMMON_SERVICE, |
|
|
|
EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), |
|
|
|
"楼长单元长导入excel错误", |
|
|
|
"楼长单元长导入excel错误"); |
|
|
|
|
|
|
|
// 3.执行导入
|
|
|
|
communityBuildingManagerService.execAsyncExcelImport(fileSavePath, rstData.getTaskId()); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|