2020-08-13 10:49:31.830 [SessionValidationThread-1] INFO o.a.s.s.m.AbstractValidatingSessionManager - [validateSessions,275] - Validating all active sessions... | |||||
2020-08-13 10:49:31.902 [SessionValidationThread-1] INFO o.a.s.s.m.AbstractValidatingSessionManager - [validateSessions,308] - Finished session validation. No sessions were stopped. | |||||
2020-08-13 11:08:25.709 [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskScheduler - [shutdown,208] - Shutting down ExecutorService 'taskScheduler' | |||||
2020-08-13 11:08:26.086 [SpringContextShutdownHook] INFO c.a.d.p.DruidDataSource - [close,1825] - {dataSource-1} closed |
2020-08-13 10:49:31.830 [SessionValidationThread-1] INFO o.a.s.s.m.AbstractValidatingSessionManager - [validateSessions,275] - Validating all active sessions... | |||||
2020-08-13 10:49:31.902 [SessionValidationThread-1] INFO o.a.s.s.m.AbstractValidatingSessionManager - [validateSessions,308] - Finished session validation. No sessions were stopped. | |||||
2020-08-13 11:08:25.709 [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskScheduler - [shutdown,208] - Shutting down ExecutorService 'taskScheduler' | |||||
2020-08-13 11:08:26.086 [SpringContextShutdownHook] INFO c.a.d.p.DruidDataSource - [close,1825] - {dataSource-1} closed | |||||
2020-08-14 09:59:01.928 [SpringContextShutdownHook] INFO o.s.s.c.ThreadPoolTaskScheduler - [shutdown,208] - Shutting down ExecutorService 'taskScheduler' | |||||
2020-08-14 09:59:02.172 [SpringContextShutdownHook] INFO c.a.d.p.DruidDataSource - [close,1825] - {dataSource-1} closed |
// 获取顶部广告 | // 获取顶部广告 | ||||
List<CtAd> adList = adService.getAdList(); | List<CtAd> adList = adService.getAdList(); | ||||
// 获取通知公告 | // 获取通知公告 | ||||
List<UserNotice> noticeList = noticeService.getNoticeList(3); | |||||
List<UserNotice> noticeList = noticeService.getRecommNoticeList(3); | |||||
// 返回结果 | // 返回结果 | ||||
Map<String, Object> result = new HashMap<>(); | Map<String, Object> result = new HashMap<>(); | ||||
result.put("adList", adList); | result.put("adList", adList); |
package com.taauav.api.controller; | |||||
import com.taauav.api.service.IInspectFileService; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.constant.PermissionConstants; | |||||
import org.apache.shiro.authz.annotation.RequiresPermissions; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.PostMapping; | |||||
import org.springframework.web.bind.annotation.RequestBody; | |||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
import com.taauav.api.controller.ApiBaseController; | |||||
import java.io.IOException; | |||||
import java.util.Map; | |||||
/** | |||||
* <p> | |||||
* 前端控制器 | |||||
* </p> | |||||
* | |||||
* @author zongjl | |||||
* @since 2020-08-14 | |||||
*/ | |||||
@RestController | |||||
@RequestMapping("/user/inspectfile") | |||||
public class InspectFileController extends ApiBaseController { | |||||
@Autowired | |||||
private IInspectFileService inspectFileService; | |||||
/** | |||||
* 图片上传 | |||||
* | |||||
* @param map | |||||
* @return | |||||
*/ | |||||
@PostMapping("uploadPic") | |||||
public Response uploadPic(@RequestBody Map<String, Object> map) throws IOException { | |||||
return inspectFileService.uploadPic(map); | |||||
} | |||||
} |
import com.taauav.api.dto.InspectQuestionDto; | import com.taauav.api.dto.InspectQuestionDto; | ||||
import com.taauav.api.query.InspectQuestionQuery; | |||||
import com.taauav.api.service.IInspectQuestionService; | import com.taauav.api.service.IInspectQuestionService; | ||||
import com.taauav.common.bean.Response; | import com.taauav.common.bean.Response; | ||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import com.taauav.api.controller.ApiBaseController; | |||||
import java.io.IOException; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
* @return | * @return | ||||
*/ | */ | ||||
@GetMapping("/getQuestionList") | @GetMapping("/getQuestionList") | ||||
public Response getQuestionList(@RequestBody InspectQuestionDto inspectQuestionDto) { | |||||
public Response getQuestionList(@RequestBody InspectQuestionQuery inspectQuestionDto) { | |||||
return response.success(inspectQuestionService.getQuestionList(inspectQuestionDto)); | return response.success(inspectQuestionService.getQuestionList(inspectQuestionDto)); | ||||
} | } | ||||
return inspectQuestionService.getQuestionInfo(id); | return inspectQuestionService.getQuestionInfo(id); | ||||
} | } | ||||
/** | |||||
* 问题上报 | |||||
* | |||||
* @param inspectQuestionDto 参数 | |||||
* @return | |||||
*/ | |||||
@PostMapping("/createQuestion") | |||||
public Response createQuestion(@RequestBody InspectQuestionDto inspectQuestionDto) throws IOException { | |||||
return inspectQuestionService.createQuestion(inspectQuestionDto); | |||||
} | |||||
} | } |
package com.taauav.api.controller; | package com.taauav.api.controller; | ||||
import org.springframework.web.bind.annotation.RequestMapping; | |||||
import com.taauav.api.dto.NoticeQuery; | |||||
import com.taauav.api.service.INoticeService; | |||||
import com.taauav.common.bean.Response; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
import com.taauav.api.controller.ApiBaseController; | import com.taauav.api.controller.ApiBaseController; | ||||
/** | /** | ||||
@RequestMapping("/user/notice") | @RequestMapping("/user/notice") | ||||
public class NoticeController extends ApiBaseController { | public class NoticeController extends ApiBaseController { | ||||
@Autowired | |||||
private INoticeService noticeService; | |||||
/** | |||||
* 获取通知列表 | |||||
* | |||||
* @param query 查询条件 | |||||
* @return | |||||
*/ | |||||
@GetMapping("/getNoticeList") | |||||
public Response getNoticeList(@RequestBody NoticeQuery query) { | |||||
return noticeService.getNoticeList(query); | |||||
} | |||||
/** | |||||
* 获取通知公告详情 | |||||
* | |||||
* @param id 通知ID | |||||
* @return | |||||
*/ | |||||
@GetMapping("/getNoticeInfo/{id}") | |||||
public Response getNoticeInfo(@PathVariable("id") Integer id) { | |||||
return noticeService.getNoticeInfo(id); | |||||
} | |||||
} | } |
package com.taauav.api.dto; | package com.taauav.api.dto; | ||||
import com.taauav.common.core.mps.BaseQuery; | |||||
import lombok.Data; | import lombok.Data; | ||||
/** | |||||
* 巡检问题上报 | |||||
*/ | |||||
@Data | @Data | ||||
public class InspectQuestionDto extends BaseQuery { | |||||
public class InspectQuestionDto { | |||||
/** | /** | ||||
* 状态 | |||||
* 巡检河道ID | |||||
*/ | */ | ||||
private Integer status; | |||||
private Integer inspectDriverId; | |||||
/** | |||||
* 问题选项ID | |||||
*/ | |||||
private Integer questionId; | |||||
/** | |||||
* 问题图片 | |||||
*/ | |||||
private String questionSrc; | |||||
/** | |||||
* 问题描述 | |||||
*/ | |||||
private String questionNote; | |||||
/** | |||||
* 经度 | |||||
*/ | |||||
private String latitude; | |||||
/** | |||||
* 纬度 | |||||
*/ | |||||
private String longitude; | |||||
/** | |||||
* 问题位置 | |||||
*/ | |||||
private String address; | |||||
} | } |
package com.taauav.api.dto; | |||||
import com.taauav.common.core.mps.BaseQuery; | |||||
import lombok.Data; | |||||
@Data | |||||
public class NoticeQuery extends BaseQuery { | |||||
} |
package com.taauav.api.mapper; | |||||
import com.taauav.admin.entity.TauvInspectFile; | |||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | |||||
/** | |||||
* <p> | |||||
* Mapper 接口 | |||||
* </p> | |||||
* | |||||
* @author zongjl | |||||
* @since 2020-08-14 | |||||
*/ | |||||
public interface InspectFileMapper extends BaseMapper<TauvInspectFile> { | |||||
} |
<?xml version="1.0" encoding="UTF-8"?> | |||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
<mapper namespace="com.taauav.api.mapper.InspectFileMapper"> | |||||
</mapper> |
import com.baomidou.mybatisplus.core.metadata.IPage; | import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
import com.taauav.admin.entity.TauvInspectQuestion; | import com.taauav.admin.entity.TauvInspectQuestion; | ||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||||
import com.taauav.api.dto.InspectQuestionDto; | |||||
import com.taauav.api.query.InspectQuestionQuery; | |||||
import com.taauav.api.vo.InspectQuestionListVo; | import com.taauav.api.vo.InspectQuestionListVo; | ||||
import org.springframework.web.bind.annotation.RequestParam; | import org.springframework.web.bind.annotation.RequestParam; | ||||
* @param param 参数 | * @param param 参数 | ||||
* @return | * @return | ||||
*/ | */ | ||||
List<InspectQuestionListVo> getQuestionList(IPage<TauvInspectQuestion> page, @RequestParam("param") InspectQuestionDto param); | |||||
List<InspectQuestionListVo> getQuestionList(IPage<TauvInspectQuestion> page, @RequestParam("param") InspectQuestionQuery param); | |||||
/** | /** | ||||
* 获取问题详情 | * 获取问题详情 |
package com.taauav.api.query; | |||||
import com.taauav.common.core.mps.BaseQuery; | |||||
import lombok.Data; | |||||
@Data | |||||
public class InspectQuestionQuery extends BaseQuery { | |||||
/** | |||||
* 状态 | |||||
*/ | |||||
private Integer status; | |||||
} |
package com.taauav.api.service; | |||||
import com.taauav.admin.entity.TauvInspectFile; | |||||
import com.baomidou.mybatisplus.extension.service.IService; | |||||
import com.taauav.common.bean.Response; | |||||
import java.io.IOException; | |||||
import java.util.Map; | |||||
/** | |||||
* <p> | |||||
* 服务类 | |||||
* </p> | |||||
* | |||||
* @author zongjl | |||||
* @since 2020-08-14 | |||||
*/ | |||||
public interface IInspectFileService extends IService<TauvInspectFile> { | |||||
/** | |||||
* 上传图片 | |||||
* | |||||
* @param map | |||||
* @return | |||||
* @throws IOException | |||||
*/ | |||||
Response uploadPic(Map<String, Object> map) throws IOException; | |||||
} |
import com.taauav.admin.entity.TauvInspectQuestion; | import com.taauav.admin.entity.TauvInspectQuestion; | ||||
import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||
import com.taauav.api.dto.InspectQuestionDto; | import com.taauav.api.dto.InspectQuestionDto; | ||||
import com.taauav.api.query.InspectQuestionQuery; | |||||
import com.taauav.api.vo.InspectQuestionListVo; | import com.taauav.api.vo.InspectQuestionListVo; | ||||
import com.taauav.common.bean.Response; | import com.taauav.common.bean.Response; | ||||
import java.io.IOException; | |||||
import java.util.List; | import java.util.List; | ||||
/** | /** | ||||
* @param inspectQuestionDto 参数 | * @param inspectQuestionDto 参数 | ||||
* @return | * @return | ||||
*/ | */ | ||||
List<InspectQuestionListVo> getQuestionList(InspectQuestionDto inspectQuestionDto); | |||||
List<InspectQuestionListVo> getQuestionList(InspectQuestionQuery inspectQuestionDto); | |||||
/** | /** | ||||
* 获取问题详情 | * 获取问题详情 | ||||
*/ | */ | ||||
Response getQuestionInfo(Integer id); | Response getQuestionInfo(Integer id); | ||||
/** | |||||
* 上报问题 | |||||
* | |||||
* @param inspectQuestionDto 参数 | |||||
* @return | |||||
*/ | |||||
Response createQuestion(InspectQuestionDto inspectQuestionDto) throws IOException; | |||||
} | } |
package com.taauav.api.service; | package com.taauav.api.service; | ||||
import com.baomidou.mybatisplus.extension.service.IService; | import com.baomidou.mybatisplus.extension.service.IService; | ||||
import com.taauav.api.dto.NoticeQuery; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.front.entity.UserNotice; | import com.taauav.front.entity.UserNotice; | ||||
import java.util.List; | import java.util.List; | ||||
* @param num 获取条数 | * @param num 获取条数 | ||||
* @return | * @return | ||||
*/ | */ | ||||
List<UserNotice> getNoticeList(Integer num); | |||||
List<UserNotice> getRecommNoticeList(Integer num); | |||||
/** | |||||
* 获取通知列表 | |||||
* | |||||
* @param query 查询条件 | |||||
* @return | |||||
*/ | |||||
Response getNoticeList(NoticeQuery query); | |||||
/** | |||||
* 获取通知详情 | |||||
* | |||||
* @param id 通知ID | |||||
* @return | |||||
*/ | |||||
Response getNoticeInfo(Integer id); | |||||
} | } |
package com.taauav.api.service.impl; | |||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
import com.taauav.admin.entity.TauvInspectDriver; | |||||
import com.taauav.admin.entity.TauvInspectFile; | |||||
import com.taauav.admin.mapper.TauvInspectDriverMapper; | |||||
import com.taauav.api.mapper.InspectFileMapper; | |||||
import com.taauav.api.service.IInspectFileService; | |||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | |||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.util.DateUtil; | |||||
import com.taauav.common.util.FileUtil; | |||||
import com.taauav.common.util.ImageUtil; | |||||
import com.taauav.common.util.ShiroUtils; | |||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.beans.factory.annotation.Value; | |||||
import org.springframework.stereotype.Service; | |||||
import org.springframework.util.StringUtils; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.util.*; | |||||
/** | |||||
* <p> | |||||
* 服务实现类 | |||||
* </p> | |||||
* | |||||
* @author zongjl | |||||
* @since 2020-08-14 | |||||
*/ | |||||
@Service | |||||
public class InspectFileServiceImpl extends ServiceImpl<InspectFileMapper, TauvInspectFile> implements IInspectFileService { | |||||
@Autowired | |||||
private TauvInspectDriverMapper inspectDriverMapper; | |||||
@Autowired | |||||
private InspectFileMapper inspectFileMapper; | |||||
@Autowired | |||||
private Response response; | |||||
@Value("${file.uploadFolder}") | |||||
private String uploadFolder; | |||||
@Value("${server.UPLOAD_URL}") | |||||
private String uploadUrl; | |||||
/** | |||||
* 上传图片 | |||||
* | |||||
* @param map | |||||
* @return | |||||
* @throws IOException | |||||
*/ | |||||
@Override | |||||
public Response uploadPic(Map<String, Object> map) throws IOException { | |||||
if (StringUtils.isEmpty(map)) { | |||||
return response.failure("参数不全"); | |||||
} | |||||
if (StringUtils.isEmpty(map.get("fileList"))) { | |||||
return response.failure("请选择要上传的文件"); | |||||
} | |||||
String inspectDriverIdStr = map.get("inspectDriverId").toString(); | |||||
String fileDocument = map.get("fileDocument").toString(); | |||||
List<String> fileList = (List<String>) map.get("fileList"); | |||||
if (StringUtils.isEmpty(inspectDriverIdStr)) { | |||||
return response.failure("任务编号不能为空"); | |||||
} | |||||
if (StringUtils.isEmpty(fileDocument)) { | |||||
return response.failure("图片类型不能为空"); | |||||
} | |||||
Integer inspectDriverId = Integer.valueOf(inspectDriverIdStr); | |||||
TauvInspectDriver driverInfo = inspectDriverMapper.selectById(inspectDriverId); | |||||
Integer inspectId = StringUtils.isEmpty(driverInfo) ? 0 : driverInfo.getInspectId(); | |||||
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/file/" + year + month + day + "/"; | |||||
File destPathFile = new File(destPath); | |||||
if (!destPathFile.isDirectory()) { | |||||
destPathFile.mkdirs(); | |||||
} | |||||
List<Map<String, String>> list = new ArrayList<>(); | |||||
//判断同一任务、同一图片分类下是否已存在待上传的图片 | |||||
Integer num = 1; | |||||
String numStr = ""; | |||||
for (String fileSrc : fileList) { | |||||
fileSrc = fileSrc.replace("-thumbnail", ""); | |||||
fileSrc = fileSrc.replace(uploadUrl, uploadFolder); | |||||
String md5 = DigestUtils.md5Hex(new FileInputStream(fileSrc)); | |||||
QueryWrapper wrapper = new QueryWrapper(); | |||||
wrapper.eq("mark", 1); | |||||
wrapper.eq("inspect_driver_id", inspectDriverId); | |||||
wrapper.eq("file_document", fileDocument); | |||||
wrapper.eq("md5", md5); | |||||
List<TauvInspectFile> fileExists = inspectFileMapper.selectList(wrapper); | |||||
if (fileExists.size() > 0) { | |||||
numStr += "【" + num + "】"; | |||||
} | |||||
num++; | |||||
} | |||||
if (!"".equals(numStr)) { | |||||
return response.failure("第" + numStr + "张图片已存在"); | |||||
} | |||||
for (String fileSrc : fileList) { | |||||
fileSrc = fileSrc.replace("-thumbnail", ""); | |||||
fileSrc = fileSrc.replace(uploadUrl, uploadFolder); | |||||
File file = new File(fileSrc); | |||||
Map<String, String> mapReturn = new HashMap<>(3); | |||||
TauvInspectFile inspectFile = new TauvInspectFile(); | |||||
String originName = file.getName(); | |||||
Long size = file.length(); | |||||
String extension = originName.substring(originName.lastIndexOf(".") + 1); | |||||
String nname = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 32); | |||||
String newName = nname + "." + extension; | |||||
String destFileUrl = destPath + originName; | |||||
String destNewFileUrl = destPath + newName; | |||||
inspectFile.setInspectId(inspectId); | |||||
inspectFile.setDate(year + month + day); | |||||
inspectFile.setInspectDriverId(inspectDriverId); | |||||
inspectFile.setFileDocument(fileDocument); | |||||
inspectFile.setExtension(extension); | |||||
inspectFile.setName(originName); | |||||
inspectFile.setFileType(Integer.valueOf("1")); | |||||
inspectFile.setSize(size.intValue()); | |||||
inspectFile.setFileName(originName); | |||||
inspectFile.setType(extension); | |||||
inspectFile.setMd5(DigestUtils.md5Hex(new FileInputStream(fileSrc))); | |||||
mapReturn.put("code", "ok"); | |||||
FileUtil.cutGeneralFile(fileSrc, destPath); | |||||
File destFile = new File(destFileUrl); | |||||
File destNewFile = new File(destNewFileUrl); | |||||
destFile.renameTo(destNewFile); | |||||
if (ImageUtil.isImage(extension)) { | |||||
List<Map<String, Integer>> sizeList = getCutImgSize(); | |||||
String[] scalImgArr = new String[2]; | |||||
int i = 0; | |||||
for (Map<String, Integer> sizeL : sizeList) { | |||||
String scalImg = uploadFolder + nname + "_" + sizeL.get("extension") + "." + extension; | |||||
int width = sizeL.get("width"); | |||||
int height = sizeL.get("height"); | |||||
ImageUtil.thumbnailImage(destNewFile, width, height, scalImg, false); | |||||
scalImgArr[i] = scalImg; | |||||
i++; | |||||
} | |||||
String thumbImg = scalImgArr[0].replace(uploadFolder, ""); | |||||
String filePath = destNewFileUrl.replace(uploadFolder, ""); | |||||
inspectFile.setSrc(filePath); | |||||
inspectFile.setOriginalImg(filePath); | |||||
inspectFile.setCreateUser(ShiroUtils.getAdminId()); | |||||
inspectFile.setCreateTime(DateUtil.now()); | |||||
inspectFile.setThumbImg(thumbImg); | |||||
inspectFileMapper.insert(inspectFile); | |||||
mapReturn.put("msg", "success"); | |||||
mapReturn.put("fileUrl", uploadUrl + thumbImg); | |||||
} else { | |||||
mapReturn.put("code", "error"); | |||||
mapReturn.put("msg", "上传图片格式不正确"); | |||||
mapReturn.put("fileUrl", ""); | |||||
log.warn("上传图片格式不正确"); | |||||
} | |||||
list.add(mapReturn); | |||||
} | |||||
return response.success(list); | |||||
} | |||||
/** | |||||
* 切图尺寸 | |||||
* | |||||
* @return | |||||
*/ | |||||
private List<Map<String, Integer>> getCutImgSize() { | |||||
List<Map<String, Integer>> list = new ArrayList<>(); | |||||
Map<String, Integer> map = new HashMap<>(3); | |||||
map.put("width", 100); | |||||
map.put("height", 100); | |||||
map.put("extension", 1); | |||||
list.add(map); | |||||
map = new HashMap<>(3); | |||||
map.put("width", 650); | |||||
map.put("height", 365); | |||||
map.put("extension", 2); | |||||
list.add(map); | |||||
return list; | |||||
} | |||||
} |
import com.baomidou.mybatisplus.core.metadata.IPage; | import com.baomidou.mybatisplus.core.metadata.IPage; | ||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
import com.taauav.admin.entity.TauvDriver; | |||||
import com.taauav.admin.entity.TauvInspectQuestion; | |||||
import com.taauav.admin.entity.*; | |||||
import com.taauav.admin.mapper.TauvDriverMapper; | import com.taauav.admin.mapper.TauvDriverMapper; | ||||
import com.taauav.admin.mapper.TauvInspectDriverMapper; | |||||
import com.taauav.admin.mapper.TauvInspectFileMapper; | |||||
import com.taauav.admin.mapper.TauvQuestionOptionsMapper; | |||||
import com.taauav.api.dto.InspectQuestionDto; | import com.taauav.api.dto.InspectQuestionDto; | ||||
import com.taauav.api.query.InspectQuestionQuery; | |||||
import com.taauav.api.mapper.InspectQuestionMapper; | import com.taauav.api.mapper.InspectQuestionMapper; | ||||
import com.taauav.api.service.IInspectQuestionService; | import com.taauav.api.service.IInspectQuestionService; | ||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
import com.taauav.api.vo.InspectQuestionListVo; | import com.taauav.api.vo.InspectQuestionListVo; | ||||
import com.taauav.common.bean.Response; | import com.taauav.common.bean.Response; | ||||
import com.taauav.common.util.*; | |||||
import com.taauav.front.entity.UserAdmin; | import com.taauav.front.entity.UserAdmin; | ||||
import com.taauav.front.mapper.UserAdminMapper; | import com.taauav.front.mapper.UserAdminMapper; | ||||
import org.apache.commons.codec.digest.DigestUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import java.util.List; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.util.*; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
@Autowired | @Autowired | ||||
private InspectQuestionMapper inspectQuestionMapper; | private InspectQuestionMapper inspectQuestionMapper; | ||||
@Autowired | @Autowired | ||||
private TauvDriverMapper driverMapper; | private TauvDriverMapper driverMapper; | ||||
@Autowired | @Autowired | ||||
private UserAdminMapper userAdminMapper; | private UserAdminMapper userAdminMapper; | ||||
@Autowired | |||||
private TauvInspectFileMapper inspectFileMapper; | |||||
@Autowired | |||||
private TauvInspectDriverMapper inspectDriverMapper; | |||||
@Autowired | |||||
private TauvQuestionOptionsMapper questionOptionsMapper; | |||||
@Autowired | @Autowired | ||||
private Response response; | private Response response; | ||||
@Value("${file.uploadFolder}") | |||||
private String uploadFolder; | |||||
@Value("${server.IMAGE_URL}") | @Value("${server.IMAGE_URL}") | ||||
private String uploadUrl; | private String uploadUrl; | ||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public List<InspectQuestionListVo> getQuestionList(InspectQuestionDto inspectQuestionDto) { | |||||
public List<InspectQuestionListVo> getQuestionList(InspectQuestionQuery inspectQuestionDto) { | |||||
IPage<TauvInspectQuestion> page = new Page<>(inspectQuestionDto.getPage(), inspectQuestionDto.getPageSize()); | IPage<TauvInspectQuestion> page = new Page<>(inspectQuestionDto.getPage(), inspectQuestionDto.getPageSize()); | ||||
return inspectQuestionMapper.getQuestionList(page, inspectQuestionDto); | return inspectQuestionMapper.getQuestionList(page, inspectQuestionDto); | ||||
} | } | ||||
} | } | ||||
return response.success(inspectQuestionListVo); | return response.success(inspectQuestionListVo); | ||||
} | } | ||||
/** | |||||
* 上报问题 | |||||
* | |||||
* @param inspectQuestionDto 参数 | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response createQuestion(InspectQuestionDto inspectQuestionDto) throws IOException { | |||||
// 巡检河流ID | |||||
if (inspectQuestionDto.getInspectDriverId() == null || inspectQuestionDto.getInspectDriverId() <= 0) { | |||||
return response.failure("巡检河流ID不能为空"); | |||||
} | |||||
// 问题类型 | |||||
if (inspectQuestionDto.getQuestionId() == null || inspectQuestionDto.getQuestionId() <= 0) { | |||||
return response.failure("问题类型不能为空"); | |||||
} | |||||
// 问题图片 | |||||
if (StringUtils.isEmpty(inspectQuestionDto.getQuestionSrc())) { | |||||
return response.failure("问题图片不能为空"); | |||||
} | |||||
// 获取巡检河道信息 | |||||
TauvInspectDriver inspectDriver = inspectDriverMapper.selectById(inspectQuestionDto.getInspectDriverId()); | |||||
if (inspectDriver == null) { | |||||
return response.failure("巡检河道信息不能为空"); | |||||
} | |||||
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/file/" + year + month + day + "/"; | |||||
File destPathFile = new File(destPath); | |||||
if (!destPathFile.isDirectory()) { | |||||
destPathFile.mkdirs(); | |||||
} | |||||
// 问题图片入库 | |||||
String fileSrc = inspectQuestionDto.getQuestionSrc().replace("-thumbnail", ""); | |||||
fileSrc = fileSrc.replace(uploadUrl, uploadFolder); | |||||
File file = new File(fileSrc); | |||||
TauvInspectFile inspectFile = new TauvInspectFile(); | |||||
String originName = file.getName(); | |||||
Long size = file.length(); | |||||
String extension = originName.substring(originName.lastIndexOf(".") + 1); | |||||
String nname = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 32); | |||||
String newName = nname + "." + extension; | |||||
String destFileUrl = destPath + originName; | |||||
String destNewFileUrl = destPath + newName; | |||||
inspectFile.setInspectId(inspectDriver.getInspectId()); | |||||
inspectFile.setDate(year + month + day); | |||||
inspectFile.setInspectDriverId(inspectQuestionDto.getInspectDriverId()); | |||||
inspectFile.setFileDocument(""); | |||||
inspectFile.setExtension(extension); | |||||
inspectFile.setName(originName); | |||||
inspectFile.setFileType(1); | |||||
inspectFile.setSize(size.intValue()); | |||||
inspectFile.setFileName(originName); | |||||
inspectFile.setType(extension); | |||||
inspectFile.setQuestionId(inspectQuestionDto.getQuestionId()); | |||||
inspectFile.setDescription(inspectQuestionDto.getQuestionNote()); | |||||
inspectFile.setMd5(DigestUtils.md5Hex(new FileInputStream(fileSrc))); | |||||
FileUtil.cutGeneralFile(fileSrc, destPath); | |||||
File destFile = new File(destFileUrl); | |||||
File destNewFile = new File(destNewFileUrl); | |||||
destFile.renameTo(destNewFile); | |||||
if (ImageUtil.isImage(extension)) { | |||||
List<Map<String, Integer>> sizeList = getCutImgSize(); | |||||
String[] scalImgArr = new String[2]; | |||||
int i = 0; | |||||
for (Map<String, Integer> sizeL : sizeList) { | |||||
String scalImg = uploadFolder + nname + "_" + sizeL.get("extension") + "." + extension; | |||||
int width = sizeL.get("width"); | |||||
int height = sizeL.get("height"); | |||||
ImageUtil.thumbnailImage(destNewFile, width, height, scalImg, false); | |||||
scalImgArr[i] = scalImg; | |||||
i++; | |||||
} | |||||
String thumbImg = scalImgArr[0].replace(uploadFolder, ""); | |||||
String filePath = destNewFileUrl.replace(uploadFolder, ""); | |||||
inspectFile.setSrc(filePath); | |||||
inspectFile.setOriginalImg(filePath); | |||||
inspectFile.setCreateUser(1); | |||||
inspectFile.setCreateTime(DateUtil.now()); | |||||
inspectFile.setThumbImg(thumbImg); | |||||
Integer result = inspectFileMapper.insert(inspectFile); | |||||
if (result == 0) { | |||||
return response.failure("问题图片创建失败"); | |||||
} | |||||
// 创建问题 | |||||
TauvInspectQuestion inspectQuestion = new TauvInspectQuestion(); | |||||
inspectQuestion.setInspectDriverId(inspectQuestionDto.getInspectDriverId()); | |||||
inspectQuestion.setInspectFileId(inspectFile.getId()); | |||||
inspectQuestion.setQuestionId(inspectQuestionDto.getQuestionId()); | |||||
inspectQuestion.setQuestionNo(createQuestionNo()); | |||||
inspectQuestion.setNote(inspectQuestionDto.getQuestionNote()); | |||||
inspectQuestion.setCreateUser(1); | |||||
inspectQuestion.setCreateTime(DateUtil.now()); | |||||
Integer result2 = inspectQuestionMapper.insert(inspectQuestion); | |||||
if (result2 == 0) { | |||||
return response.failure("上报失败"); | |||||
} | |||||
} | |||||
return response.success("上报成功"); | |||||
} | |||||
/** | |||||
* 创建问题编号 | |||||
* | |||||
* @return | |||||
*/ | |||||
private String createQuestionNo() { | |||||
Calendar date = Calendar.getInstance(); | |||||
String year = String.valueOf(date.get(Calendar.YEAR)).substring(2); | |||||
String month = String.format("%02d", date.get(Calendar.MONTH) + 1); | |||||
String code = "10" + year + month + (int) ((Math.random() * 9 + 1) * 100000); | |||||
return code; | |||||
} | |||||
/** | |||||
* 切图尺寸 | |||||
* | |||||
* @return | |||||
*/ | |||||
private List<Map<String, Integer>> getCutImgSize() { | |||||
List<Map<String, Integer>> list = new ArrayList<>(); | |||||
Map<String, Integer> map = new HashMap<>(3); | |||||
map.put("width", 100); | |||||
map.put("height", 100); | |||||
map.put("extension", 1); | |||||
list.add(map); | |||||
map = new HashMap<>(3); | |||||
map.put("width", 650); | |||||
map.put("height", 365); | |||||
map.put("extension", 2); | |||||
list.add(map); | |||||
return list; | |||||
} | |||||
} | } |
package com.taauav.api.service.impl; | package com.taauav.api.service.impl; | ||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 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.api.dto.NoticeQuery; | |||||
import com.taauav.api.mapper.NoticeMapper; | import com.taauav.api.mapper.NoticeMapper; | ||||
import com.taauav.api.service.INoticeService; | import com.taauav.api.service.INoticeService; | ||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
import com.taauav.common.bean.Response; | |||||
import com.taauav.common.util.FunctionUtils; | |||||
import com.taauav.common.util.StringUtils; | |||||
import com.taauav.front.constant.UserNoticeConstant; | |||||
import com.taauav.front.entity.UserAdmin; | |||||
import com.taauav.front.entity.UserNotice; | import com.taauav.front.entity.UserNotice; | ||||
import com.taauav.front.vo.usernotice.UserNoticeListVo; | |||||
import org.springframework.beans.BeanUtils; | |||||
import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
import java.util.ArrayList; | |||||
import java.util.HashMap; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Map; | |||||
/** | /** | ||||
* <p> | * <p> | ||||
@Autowired | @Autowired | ||||
private NoticeMapper noticeMapper; | private NoticeMapper noticeMapper; | ||||
@Autowired | |||||
private Response response; | |||||
/** | /** | ||||
* 获取工作台通知公告 | * 获取工作台通知公告 | ||||
* | * | ||||
* @return | * @return | ||||
*/ | */ | ||||
@Override | @Override | ||||
public List<UserNotice> getNoticeList(Integer num) { | |||||
public List<UserNotice> getRecommNoticeList(Integer num) { | |||||
QueryWrapper<UserNotice> queryWrapper = new QueryWrapper<>(); | QueryWrapper<UserNotice> queryWrapper = new QueryWrapper<>(); | ||||
queryWrapper.eq("status", 1); | queryWrapper.eq("status", 1); | ||||
queryWrapper.eq("mark", 1); | queryWrapper.eq("mark", 1); | ||||
List<UserNotice> noticeList = noticeMapper.selectList(queryWrapper); | List<UserNotice> noticeList = noticeMapper.selectList(queryWrapper); | ||||
return noticeList; | return noticeList; | ||||
} | } | ||||
/** | |||||
* 获取通知列表 | |||||
* | |||||
* @param query 查询条件 | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response getNoticeList(NoticeQuery query) { | |||||
// 查询条件 | |||||
QueryWrapper<UserNotice> queryWrapper = new QueryWrapper<>(); | |||||
queryWrapper.eq("status", 1); | |||||
queryWrapper.eq("mark", 1); | |||||
queryWrapper.orderByDesc("id"); | |||||
IPage<UserNotice> page = new Page<>(query.getPage(), query.getPageSize()); | |||||
IPage<UserNotice> data = noticeMapper.selectPage(page, queryWrapper); | |||||
List<UserNotice> noticeList = data.getRecords(); | |||||
List<UserNoticeListVo> userNoticeListVoList = new ArrayList<>(); | |||||
if (!noticeList.isEmpty()) { | |||||
noticeList.forEach(item -> { | |||||
UserNoticeListVo userNoticeListVo = new UserNoticeListVo(); | |||||
// 拷贝属性 | |||||
BeanUtils.copyProperties(item, userNoticeListVo); | |||||
// 发布时间 | |||||
userNoticeListVo.setPublishTime(item.getCreateTime()); | |||||
// 通知类型 | |||||
userNoticeListVo.setTypeName(UserNoticeConstant.USER_NOTICE_TYPE_LIST.get(item.getType())); | |||||
// 通知内容 | |||||
userNoticeListVo.setContent(FunctionUtils.delHTMLTag(userNoticeListVo.getContent())); | |||||
userNoticeListVoList.add(userNoticeListVo); | |||||
}); | |||||
} | |||||
// 返回结果 | |||||
Map<String, Object> result = new HashMap<>(); | |||||
result.put("total", data.getTotal()); | |||||
result.put("size", data.getSize()); | |||||
result.put("current", data.getCurrent()); | |||||
result.put("pages", data.getPages()); | |||||
result.put("records", userNoticeListVoList); | |||||
return response.success(result); | |||||
} | |||||
/** | |||||
* 获取通知公告详情 | |||||
* | |||||
* @param id 通知ID | |||||
* @return | |||||
*/ | |||||
@Override | |||||
public Response getNoticeInfo(Integer id) { | |||||
UserNotice userNotice = noticeMapper.selectById(id); | |||||
if (userNotice == null) { | |||||
return response.failure("通知公告信息不存在"); | |||||
} | |||||
return response.success(userNotice); | |||||
} | |||||
} | } |
import java.text.ParseException; | import java.text.ParseException; | ||||
import java.util.*; | import java.util.*; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.regex.Matcher; | |||||
import java.util.regex.Pattern; | |||||
/** | /** | ||||
* 常用方法 | * 常用方法 | ||||
return firstDayOfMonth; | return firstDayOfMonth; | ||||
} | } | ||||
/** | |||||
* 删除HTML标签 | |||||
* | |||||
* @param htmlStr | |||||
* @return | |||||
*/ | |||||
public static String delHTMLTag(String htmlStr) { | |||||
String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式 | |||||
String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式 | |||||
String regEx_html = "<[^>]+>"; //定义HTML标签的正则表达式 | |||||
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE); | |||||
Matcher m_script = p_script.matcher(htmlStr); | |||||
htmlStr = m_script.replaceAll(""); //过滤script标签 | |||||
Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE); | |||||
Matcher m_style = p_style.matcher(htmlStr); | |||||
htmlStr = m_style.replaceAll(""); //过滤style标签 | |||||
Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); | |||||
Matcher m_html = p_html.matcher(htmlStr); | |||||
htmlStr = m_html.replaceAll(""); //过滤html标签 | |||||
return htmlStr.trim(); //返回文本字符串 | |||||
} | |||||
} | } |