|
@@ -50,7 +50,7 @@ public class CommonController {
|
|
|
@PostMapping("area/list")
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public RestResponse areaList() {
|
|
|
- List<AreaCode> areaCodeList = (List<AreaCode>)redisTemplate.opsForValue().get(RedisConstants.RK_AREA_LIST);
|
|
|
+ List<AreaCode> areaCodeList = (List<AreaCode>) redisTemplate.opsForValue().get(RedisConstants.RK_AREA_LIST);
|
|
|
if (ObjectUtil.isEmpty(areaCodeList)) {
|
|
|
return RestResponse.success();
|
|
|
}
|
|
@@ -64,7 +64,7 @@ public class CommonController {
|
|
|
*/
|
|
|
@PostMapping("brand/list")
|
|
|
@SuppressWarnings(value = "unchecked")
|
|
|
- public RestResponse list(){
|
|
|
+ public RestResponse list() {
|
|
|
List<LiftBrand> liftBrandList = (List<LiftBrand>) redisTemplate.opsForValue().get(RedisConstants.RK_LIFT_BRAND_LIST);
|
|
|
if (ObjectUtil.isEmpty(liftBrandList)) {
|
|
|
return RestResponse.success();
|
|
@@ -79,29 +79,26 @@ public class CommonController {
|
|
|
* @return RestResponse
|
|
|
*/
|
|
|
@PostMapping("uploads")
|
|
|
- public RestResponse uploads(@RequestParam("files") MultipartFile[] files){
|
|
|
- Verify.notTrue(Objects.isNull(files) || files.length == 0,Verify.Upload.fileDataMissing);
|
|
|
+ public RestResponse uploads(@RequestParam("files") MultipartFile[] files) {
|
|
|
+ Verify.notTrue(Objects.isNull(files) || files.length == 0, Verify.Upload.fileDataMissing);
|
|
|
+ Map<String, MultipartFile> fileMap = new HashMap<>();
|
|
|
+ //1 先解析文件格式
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ String fileName = handleFile(file);
|
|
|
+ fileMap.put(fileName, file);
|
|
|
+ }
|
|
|
+ //2 批量上传
|
|
|
try {
|
|
|
- Map<String, MultipartFile> fileMap = new HashMap<>();
|
|
|
- //1 先解析文件格式
|
|
|
- for (MultipartFile file : files) {
|
|
|
- String fileName = handleFile(file);
|
|
|
- if(StrUtil.isEmpty(fileName)){
|
|
|
- return RestResponse.fail(Verify.Upload.fileFormatNotSupport);
|
|
|
- }
|
|
|
- fileMap.put(fileName, file);
|
|
|
- }
|
|
|
- //2 批量上传
|
|
|
List<String> urls = new ArrayList<>();
|
|
|
- for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()){
|
|
|
+ for (Map.Entry<String, MultipartFile> entry : fileMap.entrySet()) {
|
|
|
String url = systemConfiguration.build().putObject(entry.getKey(), entry.getValue().getBytes());
|
|
|
- log.info("上传文件,文件URL: {}",url);
|
|
|
+ log.info("upload file complete, file URL: {}", url);
|
|
|
Verify.notNull(url, Verify.Upload.fileUploadFail);
|
|
|
urls.add(url);
|
|
|
}
|
|
|
return RestResponse.success(urls);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("上传文件异常",e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("upload file occur exception", e);
|
|
|
return RestResponse.fail(Verify.Upload.fileUploadFail);
|
|
|
}
|
|
|
}
|
|
@@ -113,18 +110,15 @@ public class CommonController {
|
|
|
* @return RestResponse
|
|
|
*/
|
|
|
@PostMapping("upload")
|
|
|
- public RestResponse upload(@RequestParam("file") MultipartFile file){
|
|
|
- Verify.notTrue(Objects.isNull(file) || file.isEmpty(),Verify.Upload.fileDataMissing);
|
|
|
+ public RestResponse upload(@RequestParam("file") MultipartFile file) {
|
|
|
+ Verify.notTrue(Objects.isNull(file) || file.isEmpty(), Verify.Upload.fileDataMissing);
|
|
|
+ String fileName = handleFile(file);
|
|
|
try {
|
|
|
- String fileName = handleFile(file);
|
|
|
- if(StrUtil.isEmpty(fileName)){
|
|
|
- return RestResponse.fail(Verify.Upload.fileFormatNotSupport);
|
|
|
- }
|
|
|
String url = systemConfiguration.build().putObject(fileName, file.getBytes());
|
|
|
- log.info("上传文件,文件URL: {}",url);
|
|
|
+ log.info("upload file complete, file URL: {}", url);
|
|
|
return RestResponse.success(url);
|
|
|
- }catch (Exception e){
|
|
|
- log.error("上传文件异常",e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("upload file occur exception", e);
|
|
|
return RestResponse.fail(Verify.Upload.fileUploadFail);
|
|
|
}
|
|
|
}
|
|
@@ -135,34 +129,36 @@ public class CommonController {
|
|
|
* @param file the {@link MultipartFile} to upload
|
|
|
* @return the name string of the file.
|
|
|
*/
|
|
|
- private String handleFile(MultipartFile file){
|
|
|
- Verify.notTrue(Objects.isNull(file) || file.isEmpty(),Verify.Upload.fileDataMissing);
|
|
|
+ private String handleFile(MultipartFile file) {
|
|
|
+ Verify.notTrue(Objects.isNull(file) || file.isEmpty(), Verify.Upload.fileDataMissing);
|
|
|
// 获取文件名,带后缀
|
|
|
String originalFilename = file.getOriginalFilename();
|
|
|
- log.info("上传文件,原文件名:{}", originalFilename);
|
|
|
+ log.info("the original file name is:{}", originalFilename);
|
|
|
// 获取文件的后缀格式
|
|
|
+ Verify.notNull(originalFilename, "原文件名不能为空");
|
|
|
int lastDotIndex = originalFilename.lastIndexOf(ValuePool.DOT);
|
|
|
Verify.notTrue(-1 == lastDotIndex, "文件名解析不到文件格式");
|
|
|
String fileSuffix = originalFilename.substring(lastDotIndex).toLowerCase();
|
|
|
- Verify.notNull(fileSuffix,Verify.Upload.fileFormatIllegal);
|
|
|
+ Verify.notNull(fileSuffix, Verify.Upload.fileFormatIllegal);
|
|
|
long fileSize = file.getSize();
|
|
|
- if(StrUtil.equalsAny(fileSuffix,Verify.Upload.pics)){
|
|
|
- Verify.notTrue(fileSize > Verify.Upload.maxSizePic,"文件大小不超过" + Verify.Upload.maxSizePicDesc);
|
|
|
- }else if(StrUtil.equalsAny(fileSuffix,Verify.Upload.files)){
|
|
|
- Verify.notTrue(fileSize > Verify.Upload.maxSizeFile,"文件大小不超过" + Verify.Upload.maxSizeFileDesc);
|
|
|
- }else if(StrUtil.equalsAny(fileSuffix,Verify.Upload.videos)){
|
|
|
- Verify.notTrue(fileSize > Verify.Upload.maxSizeVideo,"文件大小不超过" + Verify.Upload.maxSizeVideoDesc);
|
|
|
- }else{
|
|
|
- return null;
|
|
|
+ log.warn("the size of file: {}", fileSize);
|
|
|
+ if (StrUtil.equalsAny(fileSuffix, Verify.Upload.pics)) {
|
|
|
+ Verify.notTrue(fileSize > Verify.Upload.maxSizePic, "文件大小不超过" + Verify.Upload.maxSizePicDesc);
|
|
|
+ } else if (StrUtil.equalsAny(fileSuffix, Verify.Upload.files)) {
|
|
|
+ Verify.notTrue(fileSize > Verify.Upload.maxSizeFile, "文件大小不超过" + Verify.Upload.maxSizeFileDesc);
|
|
|
+ } else if (StrUtil.equalsAny(fileSuffix, Verify.Upload.videos)) {
|
|
|
+ Verify.notTrue(fileSize > Verify.Upload.maxSizeVideo, "文件大小不超过" + Verify.Upload.maxSizeVideoDesc);
|
|
|
+ } else {
|
|
|
+ throw Verify.verifyException(Verify.Upload.fileFormatNotSupport);
|
|
|
}
|
|
|
- String fileName = StrUtil.format("{}/{}{}",DateUtil.format(DateUtil.date(),DateInPath),IdWorker.getIdStr(),fileSuffix);
|
|
|
- log.info("上传文件,新文件名:{}", fileName);
|
|
|
+ String fileName = StrUtil.format("{}/{}{}", DateUtil.format(DateUtil.date(), DateInPath), IdWorker.getIdStr(), fileSuffix);
|
|
|
+ log.info("the new file name:{}", fileName);
|
|
|
return fileName;
|
|
|
}
|
|
|
|
|
|
@PostMapping("countDoing")
|
|
|
@Verifier(fields = {"mtCompanyId", "userId"})
|
|
|
- public RestResponse countDoing(@Ver @RequestBody CommonRequest request){
|
|
|
+ public RestResponse countDoing(@Ver @RequestBody CommonRequest request) {
|
|
|
long inspection = annualInspectionService.countDoingByUser(request);
|
|
|
long repair = emergencyRepairService.countDoingByUser(request);
|
|
|
CommonResponse common = new CommonResponse();
|