@@ -1,6 +1,7 @@ | |||
package com.taauav.admin.controller; | |||
import com.taauav.admin.controller.BaseController; | |||
import com.taauav.admin.dto.TauvWaterSpectrumDTO; | |||
import com.taauav.common.bean.Response; | |||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||
import com.taauav.common.core.mps.BaseQuery; | |||
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import com.taauav.admin.entity.TauvWaterSpectrum; | |||
import com.taauav.admin.service.ITauvWaterSpectrumService; | |||
import org.springframework.web.multipart.MultipartFile; | |||
/** | |||
@@ -25,32 +27,29 @@ import com.taauav.admin.service.ITauvWaterSpectrumService; | |||
*/ | |||
@RestController | |||
@RequestMapping("/admin/spectrum") | |||
public class TauvWaterSpectrumController extends BaseController | |||
{ | |||
public class TauvWaterSpectrumController extends BaseController { | |||
@Autowired | |||
private ITauvWaterSpectrumService tauvWaterSpectrumService; | |||
@Autowired | |||
private Response response; | |||
/** | |||
* 查询多光谱图列表 | |||
*/ | |||
@RequiresPermissions("admin:spectrum:list") | |||
@GetMapping("/list") | |||
public Response list(TauvWaterSpectrum tauvWaterSpectrum, BaseQuery query) | |||
{ | |||
return tauvWaterSpectrumService.pageData(query,tauvWaterSpectrum); | |||
public Response list(TauvWaterSpectrumDTO waterSpectrumDTO, BaseQuery query) { | |||
return tauvWaterSpectrumService.selectSpectrumPage(waterSpectrumDTO, query); | |||
} | |||
/** | |||
* 获取多光谱图详细信息 | |||
*/ | |||
@RequiresPermissions("admin:spectrum:query") | |||
// @RequiresPermissions("admin:spectrum:query") | |||
@GetMapping(value = "/{id}") | |||
public Response getInfo(@PathVariable("id") Integer id) | |||
{ | |||
public Response getInfo(@PathVariable("id") Integer id) { | |||
return response.success(tauvWaterSpectrumService.getInfo(id)); | |||
} | |||
@@ -59,19 +58,17 @@ public class TauvWaterSpectrumController extends BaseController | |||
*/ | |||
@RequiresPermissions("admin:spectrum:add") | |||
@PostMapping | |||
public Response add(@RequestBody TauvWaterSpectrum tauvWaterSpectrum) | |||
{ | |||
public Response add(@RequestBody TauvWaterSpectrum tauvWaterSpectrum) { | |||
return response.success(tauvWaterSpectrumService.save(tauvWaterSpectrum)); | |||
} | |||
/** | |||
* 修改多光谱图 | |||
*/ | |||
@RequiresPermissions("admin:spectrum:edit") | |||
@PutMapping | |||
public Response edit(@RequestBody TauvWaterSpectrum tauvWaterSpectrum) | |||
{ | |||
return response.success(tauvWaterSpectrumService.updateById(tauvWaterSpectrum)); | |||
// @RequiresPermissions("admin:spectrum:edit") | |||
@PostMapping("/edit") | |||
public Response edit(@RequestBody TauvWaterSpectrum tauvWaterSpectrum) { | |||
return tauvWaterSpectrumService.editSpectrum(tauvWaterSpectrum); | |||
} | |||
/** | |||
@@ -79,8 +76,17 @@ public class TauvWaterSpectrumController extends BaseController | |||
*/ | |||
@RequiresPermissions("admin:spectrum:remove") | |||
@DeleteMapping("/{ids}") | |||
public Response remove(@PathVariable Integer[] ids) | |||
{ | |||
public Response remove(@PathVariable Integer[] ids) { | |||
return response.success(tauvWaterSpectrumService.deleteByIds(ids, new TauvWaterSpectrum())); | |||
} | |||
/** | |||
* 上传附件 | |||
* @param file | |||
* @return | |||
*/ | |||
@PostMapping("/upload") | |||
public Response uploadFile(MultipartFile file) { | |||
return tauvWaterSpectrumService.uploadSpectrum(file); | |||
} | |||
} |
@@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.RequestParam; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import org.springframework.web.multipart.MultipartFile; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.*; | |||
@@ -17,6 +18,7 @@ import java.util.List; | |||
/** | |||
* <p>文件上传</p> | |||
* | |||
* @author : dyg | |||
* @date : 2019-11-23 13:21 | |||
**/ | |||
@@ -33,6 +35,7 @@ public class UploadController { | |||
/** | |||
* 文件上传 | |||
* | |||
* @param file | |||
* @return | |||
*/ | |||
@@ -41,7 +44,7 @@ public class UploadController { | |||
if (file.isEmpty()) { | |||
return response.failure("上传失败,请选择文件"); | |||
} | |||
Map<String,String> preUrl = getUploadFile(file); | |||
Map<String, String> preUrl = getUploadFile(file); | |||
if (preUrl.get("success").equals("0")) { | |||
return response.failure("上传失败!" + preUrl.get("msg")); | |||
} | |||
@@ -50,6 +53,7 @@ public class UploadController { | |||
/** | |||
* 文件批量上传 | |||
* | |||
* @param fileList | |||
* @return | |||
*/ | |||
@@ -58,24 +62,25 @@ public class UploadController { | |||
if (fileList.isEmpty()) { | |||
return response.failure("上传失败,请选择文件"); | |||
} | |||
List<Map<String,String>> list = new ArrayList<>(); | |||
List<Map<String, String>> list = new ArrayList<>(); | |||
for (MultipartFile file : fileList) { | |||
Map<String,String> preFile = getUploadFile(file); | |||
Map<String, String> preFile = getUploadFile(file); | |||
list.add(preFile); | |||
} | |||
return response.success("上传成功",list); | |||
return response.success("上传成功", list); | |||
} | |||
/** | |||
* 文件上传处理 | |||
* | |||
* @param file | |||
* @return | |||
*/ | |||
private Map<String,String> getUploadFile(MultipartFile file) { | |||
Map<String,String> dt = new HashMap<String,String>(); | |||
private Map<String, String> getUploadFile(MultipartFile file) { | |||
Map<String, String> dt = new HashMap<String, String>(); | |||
String fileName = file.getOriginalFilename(); | |||
String extension = fileName.substring(fileName.lastIndexOf(".")+1); | |||
String newFileName = UUID.randomUUID().toString().replace("-","").substring(0,10)+"."+extension; | |||
String extension = fileName.substring(fileName.lastIndexOf(".") + 1); | |||
String newFileName = UUID.randomUUID().toString().replace("-", "").substring(0, 10) + "." + extension; | |||
String uploadPath = mkfilePath(); | |||
String fileUrl = uploadPath + newFileName; | |||
File dest = new File(fileUrl); | |||
@@ -86,7 +91,7 @@ public class UploadController { | |||
String preUrl = ""; | |||
if (ImageUtil.isImage(extension)) { | |||
//生成缩略图 | |||
List<String> thumImgs = ImageUtil.generateThumbnail2Directory(uploadPath,fileUrl); | |||
List<String> thumImgs = ImageUtil.generateThumbnail2Directory(uploadPath, fileUrl); | |||
preUrl = thumImgs.get(0).replace(uploadFolder, uploadUrl); | |||
} else { | |||
preUrl = fileUrl.replace(uploadFolder, uploadUrl); | |||
@@ -94,19 +99,20 @@ public class UploadController { | |||
dt.put("url", preUrl); | |||
dt.put("success", "1"); | |||
dt.put("msg","ok"); | |||
dt.put("msg", "ok"); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
log.error("文件上传异常"+e.getMessage()); | |||
log.error("文件上传异常" + e.getMessage()); | |||
dt.put("url", ""); | |||
dt.put("success", "0"); | |||
dt.put("msg",e.getMessage()); | |||
dt.put("msg", e.getMessage()); | |||
} | |||
return dt; | |||
} | |||
/** | |||
* 上传文件路径创建 | |||
* | |||
* @return | |||
*/ | |||
private String mkfilePath() { |
@@ -0,0 +1,47 @@ | |||
package com.taauav.admin.dto; | |||
import com.fasterxml.jackson.annotation.JsonFormat; | |||
import lombok.Data; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.math.BigInteger; | |||
import java.util.Date; | |||
/** | |||
* 多光谱请求实体类 | |||
* | |||
* @author daixiantong | |||
* @date 2020-05-18 | |||
*/ | |||
@Data | |||
public class TauvWaterSpectrumDTO { | |||
/** | |||
* 任务单号 | |||
*/ | |||
private String inspectNo; | |||
/** | |||
* 区属id | |||
*/ | |||
private BigInteger areaId; | |||
/** | |||
* 河湖名称 | |||
*/ | |||
private String driverName; | |||
/** | |||
* 巡检时间(开始) | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd") | |||
private Date startTime; | |||
/** | |||
* 巡检时间(结束) | |||
*/ | |||
@DateTimeFormat(pattern = "yyyy-MM-dd") | |||
@JsonFormat(pattern = "yyyy-MM-dd") | |||
private Date endTime; | |||
} |
@@ -7,6 +7,7 @@ import lombok.EqualsAndHashCode; | |||
import lombok.experimental.Accessors; | |||
import org.springframework.format.annotation.DateTimeFormat; | |||
import java.math.BigInteger; | |||
import java.util.Date; | |||
/** | |||
@@ -26,10 +27,22 @@ public class TauvWaterSpectrum extends Entity { | |||
* 巡检河道id | |||
*/ | |||
private Integer inspectDriverId; | |||
/** | |||
* 任务单号 | |||
*/ | |||
private String inspectNo; | |||
/** | |||
* 区属id | |||
*/ | |||
private BigInteger areaId; | |||
/** | |||
* 区属名称 | |||
*/ | |||
private String areaName; | |||
/** | |||
* 河湖id | |||
*/ | |||
private Integer driverId; | |||
/** | |||
* 河湖名称 | |||
*/ |
@@ -1,7 +1,11 @@ | |||
package com.taauav.admin.service; | |||
import com.taauav.admin.dto.TauvWaterSpectrumDTO; | |||
import com.taauav.admin.entity.TauvWaterSpectrum; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.core.mps.BaseQuery; | |||
import com.taauav.common.service.IBaseService; | |||
import org.springframework.web.multipart.MultipartFile; | |||
/** | |||
* 多光谱图Service接口 | |||
@@ -11,5 +15,25 @@ import com.taauav.common.service.IBaseService; | |||
*/ | |||
public interface ITauvWaterSpectrumService extends IBaseService<TauvWaterSpectrum> | |||
{ | |||
/** | |||
* 自定义分页 | |||
* @param waterSpectrumDTO | |||
* @param query | |||
* @return | |||
*/ | |||
Response selectSpectrumPage(TauvWaterSpectrumDTO waterSpectrumDTO, BaseQuery query); | |||
/** | |||
* 编辑 | |||
* @param waterSpectrum | |||
* @return | |||
*/ | |||
Response editSpectrum(TauvWaterSpectrum waterSpectrum); | |||
/** | |||
* 上传多光谱附件 | |||
* @param file | |||
* @return | |||
*/ | |||
Response uploadSpectrum(MultipartFile file); | |||
} |
@@ -700,7 +700,10 @@ public class TauvReportServiceImpl extends BaseServiceImpl<TauvReportMapper, Tau | |||
if (waterSpectrum == null) { | |||
waterSpectrum = new TauvWaterSpectrum(); | |||
waterSpectrum.setInspectDriverId(inspectDriverId); | |||
waterSpectrum.setInspectNo(inspectDriverInfo.getInspectNo()); | |||
waterSpectrum.setAreaId(city != null ? city.getId() : BigInteger.ZERO); | |||
waterSpectrum.setAreaName(city != null ? city.getName() : ""); | |||
waterSpectrum.setDriverId(inspectDriverInfo.getDriverId()); | |||
waterSpectrum.setDriverName(inspectDriverInfo.getDriverName()); | |||
waterSpectrum.setInspectTime(inspectDriverInfo.getExecutionTime()); | |||
waterSpectrum.setCreateUser(ShiroUtils.getAdminId()); |
@@ -1,11 +1,28 @@ | |||
package com.taauav.admin.service.impl; | |||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.taauav.admin.dto.TauvWaterSpectrumDTO; | |||
import com.taauav.common.bean.Response; | |||
import com.taauav.common.core.mps.BaseQuery; | |||
import com.taauav.common.service.impl.BaseServiceImpl; | |||
import com.taauav.common.util.StringUtils; | |||
import org.springframework.beans.factory.annotation.Value; | |||
import org.springframework.stereotype.Service; | |||
import com.taauav.admin.mapper.TauvWaterSpectrumMapper; | |||
import com.taauav.admin.entity.TauvWaterSpectrum; | |||
import com.taauav.admin.service.ITauvWaterSpectrumService; | |||
import org.springframework.web.multipart.MultipartFile; | |||
import javax.annotation.Resource; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.math.BigInteger; | |||
import java.util.Arrays; | |||
import java.util.Calendar; | |||
import java.util.UUID; | |||
/** | |||
* 多光谱图Service业务层处理 | |||
@@ -14,7 +31,114 @@ import com.taauav.admin.service.ITauvWaterSpectrumService; | |||
* @date 20200514 | |||
*/ | |||
@Service | |||
public class TauvWaterSpectrumServiceImpl extends BaseServiceImpl<TauvWaterSpectrumMapper, TauvWaterSpectrum> implements ITauvWaterSpectrumService | |||
{ | |||
public class TauvWaterSpectrumServiceImpl extends BaseServiceImpl<TauvWaterSpectrumMapper, TauvWaterSpectrum> implements ITauvWaterSpectrumService { | |||
@Resource | |||
private Response response; | |||
@Value("${file.spectrumExtension}") | |||
private String spectrumExtension; | |||
@Value("${file.uploadFolder}") | |||
private String uploadFolder; | |||
@Value("${server.UPLOAD_URL}") | |||
private String uploadUrl; | |||
/** | |||
* 自定义分页列表 | |||
* | |||
* @param waterSpectrumDTO | |||
* @param query | |||
* @return | |||
*/ | |||
@Override | |||
public Response selectSpectrumPage(TauvWaterSpectrumDTO waterSpectrumDTO, BaseQuery query) { | |||
QueryWrapper<TauvWaterSpectrum> wrapper = new QueryWrapper<>(); | |||
wrapper.eq("mark", 1); | |||
if (!StringUtils.isEmpty(waterSpectrumDTO.getInspectNo())) { | |||
wrapper.like("inspect_no", waterSpectrumDTO.getInspectNo().trim()); | |||
} | |||
if (StringUtils.isNotNull(waterSpectrumDTO.getAreaId()) && waterSpectrumDTO.getAreaId().compareTo(BigInteger.ZERO) > 0) { | |||
wrapper.eq("area_id", waterSpectrumDTO.getAreaId()); | |||
} | |||
if (!StringUtils.isEmpty(waterSpectrumDTO.getDriverName())) { | |||
wrapper.like("driver_name", waterSpectrumDTO.getDriverName().trim()); | |||
} | |||
if (StringUtils.isNotNull(waterSpectrumDTO.getStartTime()) && StringUtils.isNotNull(waterSpectrumDTO.getEndTime()) | |||
&& StringUtils.isNotEmpty(waterSpectrumDTO.getStartTime().toString()) && StringUtils.isNotEmpty(waterSpectrumDTO.getEndTime().toString())) { | |||
wrapper.between("inspect_time", waterSpectrumDTO.getStartTime().toString(), waterSpectrumDTO.getEndTime().toString()); | |||
} | |||
IPage page = new Page(query.getPage(), query.getPageSize()); | |||
IPage<TauvWaterSpectrum> list = baseMapper.selectPage(page, wrapper); | |||
return response.success(list); | |||
} | |||
/** | |||
* 上传多光谱附件 | |||
* | |||
* @param file | |||
* @return | |||
*/ | |||
@Override | |||
public Response uploadSpectrum(MultipartFile file) { | |||
if (file.isEmpty()) { | |||
return response.failure("请选择上传文件"); | |||
} | |||
String fileName = file.getOriginalFilename(); | |||
String extension = fileName.substring(fileName.lastIndexOf(".") + 1); | |||
// 校验文件后缀 | |||
String[] extensionList = spectrumExtension.split(","); | |||
boolean result = Arrays.asList(extensionList).contains(extension.toLowerCase()); | |||
if (!result) { | |||
return response.failure("上传文件后缀不允许"); | |||
} | |||
String newFileName = UUID.randomUUID().toString().replace("-", "").substring(0, 10) + "." + extension; | |||
Calendar calendar = Calendar.getInstance(); | |||
String year = calendar.get(Calendar.YEAR) + ""; | |||
String month = (calendar.get(Calendar.MONTH) + 1) + ""; | |||
String day = calendar.get(Calendar.DATE) + ""; | |||
String destPath = uploadFolder + "file/spectrum/" + year + month + day + "/"; | |||
File destPathFile = new File(destPath); | |||
if (!destPathFile.isDirectory()) { | |||
destPathFile.mkdirs(); | |||
} | |||
String fileUrl = destPath + newFileName; | |||
File dest = new File(fileUrl); | |||
try { | |||
file.transferTo(dest); | |||
String preUrl = fileUrl.replace(uploadFolder, uploadUrl); | |||
return response.success(preUrl); | |||
} catch (IOException e) { | |||
e.printStackTrace(); | |||
log.error("文件上传异常" + e.getMessage()); | |||
return response.failure(e.getMessage()); | |||
} | |||
} | |||
@Override | |||
public Response editSpectrum(TauvWaterSpectrum waterSpectrum) { | |||
// 处理图片路径 | |||
if (StringUtils.isNotEmpty(waterSpectrum.getCodPic()) && waterSpectrum.getCodPic().contains(uploadFolder)) { | |||
waterSpectrum.setCodPic(waterSpectrum.getCodPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
if (StringUtils.isNotEmpty(waterSpectrum.getNh3nPic()) && waterSpectrum.getNh3nPic().contains(uploadFolder)) { | |||
waterSpectrum.setNh3nPic(waterSpectrum.getNh3nPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
if (StringUtils.isNotEmpty(waterSpectrum.getTpPic()) && waterSpectrum.getTpPic().contains(uploadFolder)) { | |||
waterSpectrum.setTpPic(waterSpectrum.getTpPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
if (StringUtils.isNotEmpty(waterSpectrum.getTnPic()) && waterSpectrum.getTnPic().contains(uploadFolder)) { | |||
waterSpectrum.setTnPic(waterSpectrum.getTnPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
if (StringUtils.isNotEmpty(waterSpectrum.getDoPic()) && waterSpectrum.getDoPic().contains(uploadFolder)) { | |||
waterSpectrum.setDoPic(waterSpectrum.getDoPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
if (StringUtils.isNotEmpty(waterSpectrum.getTubPic()) && waterSpectrum.getTubPic().contains(uploadFolder)) { | |||
waterSpectrum.setTubPic(waterSpectrum.getTubPic().replace(uploadFolder, uploadUrl)); | |||
} | |||
Boolean res = updateById(waterSpectrum); | |||
if (!res) { | |||
return response.failure("操作失败"); | |||
} | |||
return response.success("操作成功"); | |||
} | |||
} |