|
@@ -1,14 +1,29 @@
|
|
|
package com.example.nngkxxdp.program.service.Impl;
|
|
|
|
|
|
|
|
|
-import com.example.nngkxxdp.program.dao.AppletUserDao;
|
|
|
+import cn.hutool.core.io.FileTypeUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import com.example.nngkxxdp.dao.FileDao;
|
|
|
+import com.example.nngkxxdp.entity.SFile;
|
|
|
import com.example.nngkxxdp.program.dao.SRepairDao;
|
|
|
import com.example.nngkxxdp.program.entity.SRepair;
|
|
|
import com.example.nngkxxdp.program.service.SRepairService;
|
|
|
+import com.example.nngkxxdp.util.Blank;
|
|
|
+import com.example.nngkxxdp.util.ConstStr;
|
|
|
+import com.example.nngkxxdp.util.SendUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* (SRepair)表服务实现类
|
|
@@ -20,11 +35,13 @@ import org.springframework.data.domain.PageRequest;
|
|
|
public class SRepairServiceImpl implements SRepairService {
|
|
|
|
|
|
private final SRepairDao sRepairDao;
|
|
|
-
|
|
|
-
|
|
|
+ private final FileDao fileDao;
|
|
|
+ @Value("${file.location}")
|
|
|
+ private String location;
|
|
|
|
|
|
- public SRepairServiceImpl(SRepairDao sRepairDao) {
|
|
|
+ public SRepairServiceImpl(SRepairDao sRepairDao, FileDao fileDao) {
|
|
|
this.sRepairDao = sRepairDao;
|
|
|
+ this.fileDao = fileDao;
|
|
|
}
|
|
|
/**
|
|
|
* 通过ID查询单条数据
|
|
@@ -33,7 +50,7 @@ public class SRepairServiceImpl implements SRepairService {
|
|
|
* @return 实例对象
|
|
|
*/
|
|
|
@Override
|
|
|
- public SRepair queryById(Integer id) {
|
|
|
+ public SRepair queryById(String id) {
|
|
|
return this.sRepairDao.queryById(id);
|
|
|
}
|
|
|
|
|
@@ -85,5 +102,96 @@ public class SRepairServiceImpl implements SRepairService {
|
|
|
return this.sRepairDao.deleteById(id) > 0;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> addEvaluation(MultipartFile[] files, SRepair sRepair) throws IOException {
|
|
|
+ if (Blank.isNotEmpty(files)) {
|
|
|
+ File pathFile = new File(location);
|
|
|
+ if (!pathFile.isDirectory()) {
|
|
|
+ if (!pathFile.mkdirs()) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<String> picPathList = new ArrayList<>();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ //获取上传过来的文件名
|
|
|
+ File temporaryFile = new File(location + file.getOriginalFilename());
|
|
|
+ file.transferTo(temporaryFile);
|
|
|
+ String type = FileTypeUtil.getType(temporaryFile);
|
|
|
+ if (!("jpg".equals(type) || "png".equals(type) || "bmp".equals(type) || "jpeg".equals(type))) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "上传的格式必须是jpg或png或bmp或jpeg");
|
|
|
+ }
|
|
|
+ String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
|
|
|
+ String filePath = location + newName;
|
|
|
+ File newFile = new File(filePath);
|
|
|
+ if (!temporaryFile.renameTo(newFile)) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ // 增加数据到s_file表
|
|
|
+ SFile sFile = new SFile();
|
|
|
+ sFile.setPath(newName);
|
|
|
+ sFile.setSuffix(type);
|
|
|
+ if (fileDao.addFile(sFile) <= 0) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ picPathList.add(sFile.getId().toString());
|
|
|
+ }
|
|
|
+ String picPath = String.join(",", picPathList);
|
|
|
+ sRepair.setRepairPic(picPath);
|
|
|
+ }
|
|
|
+ sRepair.setId(UUID.randomUUID().toString(true));
|
|
|
+ return SendUtil.send(true,sRepairDao.insert(sRepair)>0);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SRepair> myOrder(String id,Integer status) {
|
|
|
+ Integer status2 = null;
|
|
|
+ if (status==3){
|
|
|
+ status2 = -1;
|
|
|
+ }
|
|
|
+ return sRepairDao.getMyOrder(id,status,status2);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SRepair myOrderInfo(String id) {
|
|
|
+ return sRepairDao.queryById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> closeOrder(MultipartFile[] files, SRepair sRepair) throws IOException {
|
|
|
+ if (Blank.isNotEmpty(files)) {
|
|
|
+ File pathFile = new File(location);
|
|
|
+ if (!pathFile.isDirectory()) {
|
|
|
+ if (!pathFile.mkdirs()) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ArrayList<String> picPathList = new ArrayList<>();
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ //获取上传过来的文件名
|
|
|
+ File temporaryFile = new File(location + file.getOriginalFilename());
|
|
|
+ file.transferTo(temporaryFile);
|
|
|
+ String type = FileTypeUtil.getType(temporaryFile);
|
|
|
+ if (!("jpg".equals(type) || "png".equals(type) || "bmp".equals(type) || "jpeg".equals(type))) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "上传的格式必须是jpg或png或bmp或jpeg");
|
|
|
+ }
|
|
|
+ String newName = (new Date()).getTime() + ((int) (Math.random() * 9000) + 1000) + "." + type;
|
|
|
+ String filePath = location + newName;
|
|
|
+ File newFile = new File(filePath);
|
|
|
+ if (!temporaryFile.renameTo(newFile)) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ // 增加数据到s_file表
|
|
|
+ SFile sFile = new SFile();
|
|
|
+ sFile.setPath(newName);
|
|
|
+ sFile.setSuffix(type);
|
|
|
+ if (fileDao.addFile(sFile) <= 0) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ picPathList.add(sFile.getId().toString());
|
|
|
+ }
|
|
|
+ String picPath = String.join(",", picPathList);
|
|
|
+ sRepair.setResultPic(picPath);
|
|
|
+ }
|
|
|
+ return SendUtil.send(true,sRepairDao.update(sRepair)>0);
|
|
|
+ }
|
|
|
}
|