|
@@ -1,16 +1,24 @@
|
|
|
package com.example.nngkxxdp.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.FileTypeUtil;
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
+import com.example.nngkxxdp.dao.FileDao;
|
|
|
import com.example.nngkxxdp.dao.RectificationDao;
|
|
|
+import com.example.nngkxxdp.entity.SFile;
|
|
|
import com.example.nngkxxdp.service.RectificationService;
|
|
|
+import com.example.nngkxxdp.util.Blank;
|
|
|
import com.example.nngkxxdp.util.ConstStr;
|
|
|
import com.example.nngkxxdp.util.SendUtil;
|
|
|
-import org.apache.ibatis.annotations.Param;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.example.nngkxxdp.entity.dos.RectificationDO;
|
|
|
import com.example.nngkxxdp.entity.vos.RectificationVO;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -22,31 +30,38 @@ import java.util.Map;
|
|
|
* @Date 2023/01/30 10:44
|
|
|
*/
|
|
|
@Service("rectificationService")
|
|
|
+@Transactional(rollbackFor = Exception.class)
|
|
|
public class RectificationServiceImpl implements RectificationService {
|
|
|
|
|
|
@Resource
|
|
|
private RectificationDao rectificationDao;
|
|
|
-
|
|
|
+
|
|
|
+ @Value("${file.location}")
|
|
|
+ private String location;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FileDao fileDao;
|
|
|
+
|
|
|
/**
|
|
|
* description: 详情
|
|
|
*
|
|
|
+ * @param id 主键
|
|
|
+ * return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
- * @param id 主键
|
|
|
- * return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> info(String id) {
|
|
|
RectificationVO rectificationVO = rectificationDao.info(id);
|
|
|
return SendUtil.send(true, ConstStr.RESULT_SUCCESS, rectificationVO);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* description: 列表
|
|
|
*
|
|
|
+ * @return java.util.Map<java.lang.String, java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
- * @return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> list() {
|
|
@@ -55,18 +70,19 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
|
|
|
/**
|
|
|
* description: 分页查询
|
|
|
- * @author zwq
|
|
|
- * @date 2023/1/30 11:26
|
|
|
+ *
|
|
|
* @param startRows 分页参数,起始
|
|
|
- * @param limit 分页参数,查几个
|
|
|
- * @param type 类型
|
|
|
- * @param url 网站地址
|
|
|
- * @param status 状态
|
|
|
+ * @param limit 分页参数,查几个
|
|
|
+ * @param type 类型
|
|
|
+ * @param url 网站地址
|
|
|
+ * @param status 状态
|
|
|
* @param submitter 提交人
|
|
|
- * @param mail 邮箱
|
|
|
- * @param phone 电话
|
|
|
+ * @param mail 邮箱
|
|
|
+ * @param phone 电话
|
|
|
* @param equipment 设备来源
|
|
|
- * @return java.util.Map<java.lang.String,java.lang.Object>
|
|
|
+ * @return java.util.Map<java.lang.String, java.lang.Object>
|
|
|
+ * @author zwq
|
|
|
+ * @date 2023/1/30 11:26
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> page(Integer startRows, Integer limit, Integer type, String url, Integer status,
|
|
@@ -86,16 +102,52 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
/**
|
|
|
* description: 新增
|
|
|
*
|
|
|
+ * @param rectificationDO 实例对象
|
|
|
+ * @param file 文件对象
|
|
|
+ * @return java.util.Map<java.lang.String, java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
- * @param rectificationDO 实例对象
|
|
|
- * @return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> add(RectificationDO rectificationDO) {
|
|
|
- // TODO 校验
|
|
|
+ public Map<String, Object> add(RectificationDO rectificationDO, MultipartFile file) throws IOException {
|
|
|
+ if (!Blank.isPhone(rectificationDO.getPhone())) {
|
|
|
+ return SendUtil.send(false, "请输入正确的手机号");
|
|
|
+ }
|
|
|
+ if (!Blank.isEmail(rectificationDO.getMail())) {
|
|
|
+ return SendUtil.send(false, "请输入正确的邮箱");
|
|
|
+ }
|
|
|
+ if (Blank.isNotEmpty(file)) {
|
|
|
+ File pathFile = new File(location);
|
|
|
+ if (!pathFile.isDirectory()) {
|
|
|
+ if (!pathFile.mkdirs()) {
|
|
|
+ return SendUtil.send(false, ConstStr.ADD_FAILED, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取上传过来的文件名
|
|
|
+ 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, "");
|
|
|
+ }
|
|
|
+ rectificationDO.setPicture(newName);
|
|
|
+ }
|
|
|
rectificationDO.setId(UUID.randomUUID().toString());
|
|
|
rectificationDO.setCreateTime(new Date());
|
|
|
+ rectificationDO.setStatus(0);
|
|
|
rectificationDO.setIsdel(0);
|
|
|
if (rectificationDao.add(rectificationDO) <= 0) {
|
|
|
return SendUtil.send(false, ConstStr.RESULT_FAILED);
|
|
@@ -106,10 +158,10 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
/**
|
|
|
* description: 修改
|
|
|
*
|
|
|
+ * @param rectificationDO 实例对象
|
|
|
+ * @return java.util.Map<java.lang.String, java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
- * @param rectificationDO 实例对象
|
|
|
- * @return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> update(RectificationDO rectificationDO) {
|
|
@@ -125,10 +177,10 @@ public class RectificationServiceImpl implements RectificationService {
|
|
|
/**
|
|
|
* description: 通过主键删除数据
|
|
|
*
|
|
|
+ * @param id 主键
|
|
|
+ * @return java.util.Map<java.lang.String, java.lang.Object> 数据
|
|
|
* @author zwq
|
|
|
* @date 2023/01/30 10:44
|
|
|
- * @param id 主键
|
|
|
- * @return java.util.Map<java.lang.String,java.lang.Object> 数据
|
|
|
*/
|
|
|
@Override
|
|
|
public Map<String, Object> delete(String id) {
|