|
|
@@ -25,10 +25,13 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import java.io.BufferedInputStream; |
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
|
import java.io.IOException; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.concurrent.Future; |
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@@ -258,12 +261,20 @@ public class WxCUserBasicInfoController extends BaseController { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void set_redis_value(String importKey, String allCount, String allSuccessCount, String processCount, String failCount, boolean fail) { |
|
|
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "allCount", allCount); |
|
|
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "allSuccessCount", allSuccessCount); |
|
|
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "processCount", processCount); |
|
|
|
|
|
stringRedisTemplate.opsForHash().put(importKey, "failCount", failCount); |
|
|
|
|
|
if(fail) { |
|
|
|
|
|
stringRedisTemplate.expire(importKey,10, TimeUnit.SECONDS); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/importTemplate") |
|
|
|
|
|
public ResultData importTemplate(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
|
@PostMapping(value = "/importTemplate", consumes = "multipart/*") |
|
|
|
|
|
public ResultData importTemplate(@RequestParam("file") MultipartFile mFile) { |
|
|
logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::importTemplate"); |
|
|
logger.debug("[" + getIpAddr() + "] WxCUserBasicInfoController::importTemplate"); |
|
|
if (file.isEmpty()) { |
|
|
|
|
|
|
|
|
if (mFile.isEmpty()) { |
|
|
throw new MallinkException(Result.ERROR, "上传文件不能为空"); |
|
|
throw new MallinkException(Result.ERROR, "上传文件不能为空"); |
|
|
} |
|
|
} |
|
|
//得到当前用户ID |
|
|
//得到当前用户ID |
|
|
@@ -279,20 +290,71 @@ public class WxCUserBasicInfoController extends BaseController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", 0 + ""); |
|
|
|
|
|
stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allSuccessCount", 0 + ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "processCount", ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", ""); |
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", ""); |
|
|
|
|
|
|
|
|
asyncTask.importExcelData(file, user, importKey, tenantId); |
|
|
|
|
|
|
|
|
String fpath = "./upload/"; |
|
|
|
|
|
File targetFile = new File(fpath); |
|
|
|
|
|
if (!targetFile.exists()) { |
|
|
|
|
|
targetFile.mkdirs(); |
|
|
|
|
|
} |
|
|
|
|
|
String fileName = "1.xls"; |
|
|
|
|
|
int dot = mFile.getOriginalFilename().lastIndexOf('.'); |
|
|
|
|
|
fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); |
|
|
|
|
|
|
|
|
|
|
|
File lFile = new File(fpath + File.separator + fileName); |
|
|
|
|
|
|
|
|
|
|
|
FileOutputStream fos = null; |
|
|
|
|
|
BufferedInputStream fs = null; |
|
|
|
|
|
try { |
|
|
|
|
|
fos = new FileOutputStream(lFile); |
|
|
|
|
|
fs = (BufferedInputStream) mFile.getInputStream(); |
|
|
|
|
|
byte[] buffer = new byte[1024]; |
|
|
|
|
|
int len = 0; |
|
|
|
|
|
while ((len = fs.read(buffer)) != -1) { |
|
|
|
|
|
fos.write(buffer, 0, len); |
|
|
|
|
|
} |
|
|
|
|
|
fos.close(); |
|
|
|
|
|
fs.close(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); |
|
|
|
|
|
} finally { |
|
|
|
|
|
if (fos != null) { |
|
|
|
|
|
try { |
|
|
|
|
|
fos.close(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (fs != null) { |
|
|
|
|
|
try { |
|
|
|
|
|
fs.close(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
stringRedisTemplate.expire(importKey,3,TimeUnit.SECONDS); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "allCount", "1"); |
|
|
|
|
|
stringRedisTemplate.opsForHash().putIfAbsent(importKey, "failCount", "1"); |
|
|
|
|
|
logger.error(e.getMessage()); |
|
|
|
|
|
return new ResultData(ErrorCode.MEM_IMPORT_ERR.getCode(), "模板上传失败"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
asyncTask.importExcelData(lFile, user, importKey, tenantId); |
|
|
|
|
|
|
|
|
stringRedisTemplate.expire(importKey,30,TimeUnit.MINUTES); |
|
|
|
|
|
return new ResultData(Result.SUCCESS, "模板正在导入"); |
|
|
return new ResultData(Result.SUCCESS, "模板正在导入"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/queryTemplateCount") |
|
|
@GetMapping("/queryTemplateCount") |
|
|
public ResultData queryTemplateCount() { |
|
|
public ResultData queryTemplateCount() { |
|
|
String importKey = importMemPrev + getUser().getId(); |
|
|
String importKey = importMemPrev + getUser().getId(); |
|
|
|