screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java
@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.ArrayList; @@ -17,7 +18,7 @@ //读取不需拦截路径 @Bean @ConfigurationProperties("mvc.interceptor.exclude") public ArrayList<String> getExcludePath(){ public ArrayList<String> getExcludePath() { return new ArrayList<>(); } @@ -28,4 +29,19 @@ regisration.addPathPatterns("/**/**");//设置拦截路径 regisration.excludePathPatterns(excludePath);//设置不拦截路径 } /** * 添加静态资源文件,外部可以直接访问地址 * * @param registry */ @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { try { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); } catch (Exception e) { e.printStackTrace(); } } } screen-api/src/main/java/com/moral/api/controller/SupervisionController.java
New file @@ -0,0 +1,72 @@ package com.moral.api.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.moral.api.entity.Supervision; import com.moral.api.service.SupervisionService; import com.moral.constant.ResponseCodeEnum; import com.moral.constant.ResultMessage; import com.moral.util.WebUtils; @RestController @RequestMapping("/supervision") @CrossOrigin(origins = "*", maxAge = 3600) @Api(tags = {"督办单模块"}) public class SupervisionController { @Autowired private SupervisionService supervisionService; @PostMapping("add") public ResultMessage add(MultipartFile[] files, Supervision supervision) { Map<String, Object> response = supervisionService.add(files, supervision); if (!response.isEmpty()) { return ResultMessage.fail(Integer.parseInt(response.get("code").toString()), response.get("msg").toString()); } return ResultMessage.ok(); } @ApiOperation(value = "分页督办单列表", notes = "分页督办单列表") @ApiImplicitParams({ @ApiImplicitParam(name = "cityCode", value = "地区码", required = false, paramType = "query", dataType = "int"), @ApiImplicitParam(name = "start", value = "开始时间", required = false, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "end", value = "结束时间", required = false, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "page", value = "当前页", required = false, paramType = "query", dataType = "int"), @ApiImplicitParam(name = "size", value = "每页条数", required = false, paramType = "query", dataType = "int") }) @GetMapping("select") public ResultMessage select(HttpServletRequest request) { Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); if (!params.containsKey("cityCode")) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } Map<String, Object> result = supervisionService.selectSupervisions(params); return ResultMessage.ok(result); } @ApiOperation(value = "修改督办单", notes = "修改督办单") @PostMapping("update") public ResultMessage update(MultipartFile[] files, Supervision supervision) { Map<String, Object> response = supervisionService.updateSupervision(files, supervision); if (!response.isEmpty()) { return ResultMessage.fail(Integer.parseInt(response.get("code").toString()), response.get("msg").toString()); } return ResultMessage.ok(); } } screen-api/src/main/java/com/moral/api/entity/Supervision.java
New file @@ -0,0 +1,112 @@ package com.moral.api.entity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.extension.activerecord.Model; import com.baomidou.mybatisplus.annotation.TableId; import com.fasterxml.jackson.annotation.JsonFormat; import java.io.Serializable; import java.util.Date; import lombok.Data; import lombok.EqualsAndHashCode; import org.springframework.format.annotation.DateTimeFormat; /** * <p> * 督办单 * </p> * * @author moral * @since 2022-01-12 */ @Data @EqualsAndHashCode(callSuper = false) public class Supervision extends Model<Supervision> { private static final long serialVersionUID = 1L; /** * 主键 */ @TableId(value = "id", type = IdType.AUTO) private Integer id; /** * 地区编码 */ private Integer cityCode; /** * 时间 */ @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date time; /** * 被督办单位 */ private String superviseeUnit; /** * 督办单编号 */ private String number; /** * 问题类型 */ private String problemType; /** * 督办问题描述 */ private String problemDesc; /** * 现场图片 */ private String images; /** * 经办人 */ private String handler; /** * 督办次数 */ private Integer numberTimes; /** * 管控措施 */ private String measures; /** * 创建时间 */ @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date createTime; /** * 更新时间 */ @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @DateTimeFormat(pattern = "yyyy-MM-dd") private Date updateTime; /** * 是否删除,0:不删除;1:删除 */ private String isDelete; @Override protected Serializable pkVal() { return this.id; } } screen-api/src/main/java/com/moral/api/mapper/SupervisionMapper.java
New file @@ -0,0 +1,17 @@ package com.moral.api.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.moral.api.entity.Supervision; /** * <p> * 督办单 Mapper 接口 * </p> * * @author moral * @since 2022-01-12 */ public interface SupervisionMapper extends BaseMapper<Supervision> { } screen-api/src/main/java/com/moral/api/service/SupervisionService.java
New file @@ -0,0 +1,29 @@ package com.moral.api.service; import org.springframework.web.multipart.MultipartFile; import java.util.Map; import com.moral.api.entity.Supervision; import com.baomidou.mybatisplus.extension.service.IService; /** * <p> * 督办单 服务类 * </p> * * @author moral * @since 2022-01-12 */ public interface SupervisionService extends IService<Supervision> { //新增督办单 Map<String, Object> add(MultipartFile[] files, Supervision supervision); //查询督办单 Map<String, Object> selectSupervisions(Map<String, Object> params); //修改督办单 Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision); } screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java
New file @@ -0,0 +1,161 @@ package com.moral.api.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.moral.api.entity.Supervision; import com.moral.api.mapper.SupervisionMapper; import com.moral.api.service.SupervisionService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.moral.constant.Constants; import com.moral.constant.ResponseCodeEnum; import com.moral.util.FileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; /** * <p> * 督办单 服务实现类 * </p> * * @author moral * @since 2022-01-12 */ @Service public class SupervisionServiceImpl extends ServiceImpl<SupervisionMapper, Supervision> implements SupervisionService { @Autowired private SupervisionMapper supervisionMapper; @Override public Map<String, Object> add(MultipartFile[] files, Supervision supervision) { String path = this.getClass().getClassLoader() .getResource("").getFile() + "static/img/"; Map<String, Object> result = new HashMap<>(); List<String> images = new ArrayList<>(); for (MultipartFile file : files) { //判断上传文件格式 String fileType = file.getContentType(); if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { //获取文件名 String fileName = file.getOriginalFilename(); //获取文件后缀名 String suffixName = fileName.substring(fileName.lastIndexOf(".")); //重新生成文件名 fileName = UUID.randomUUID() + suffixName; //图片上传 if (FileUtils.upload(file, path, fileName)) { images.add(fileName); } } else { result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); return result; } } if (!ObjectUtils.isEmpty(images)) { String image = images.stream() .map(String::valueOf) .collect(Collectors.joining(",")); supervision.setImages(image); } supervisionMapper.insert(supervision); return result; } @Override public Map<String, Object> selectSupervisions(Map<String, Object> params) { //获取查询参数 int cityCode = Integer.parseInt(params.get("cityCode").toString()); int page = Integer.parseInt(params.get("page").toString()); int size = Integer.parseInt(params.get("size").toString()); Object start = params.get("start"); Object end = params.get("end"); QueryWrapper<Supervision> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("city_code", cityCode) .eq("is_delete", Constants.NOT_DELETE); if (start != null) { queryWrapper.ge("time", start); } if (start != null) { queryWrapper.le("time", end); } //按time倒序 queryWrapper.orderByDesc("time"); //分页 Page<Supervision> supervisionPage = new Page<>(page, size); supervisionMapper.selectPage(supervisionPage, queryWrapper); List<Supervision> supervisions = supervisionPage.getRecords(); Map<String, Object> result = new LinkedHashMap<>(); result.put("total", supervisionPage.getTotal()); result.put("totalPage", supervisionPage.getPages()); result.put("current", supervisionPage.getCurrent()); result.put("pageSize", supervisionPage.getSize()); result.put("item", supervisions); return result; } @Override public Map<String, Object> updateSupervision(MultipartFile[] files, Supervision supervision) { String path = this.getClass().getClassLoader() .getResource("").getFile() + "static/img/"; Map<String, Object> result = new HashMap<>(); List<String> images = new ArrayList<>(); for (MultipartFile file : files) { //判断上传文件格式 String fileType = file.getContentType(); if ("image/jpg".equals(fileType) || "image/png".equals(fileType) || "image/jpeg".equals(fileType)) { //获取文件名 String fileName = file.getOriginalFilename(); //获取文件后缀名 String suffixName = fileName.substring(fileName.lastIndexOf(".")); //重新生成文件名 fileName = UUID.randomUUID() + suffixName; //图片上传 if (FileUtils.upload(file, path, fileName)) { images.add(fileName); } } else { result.put("code", ResponseCodeEnum.IMG_UPLOAD_FAIl.getCode()); result.put("msg", ResponseCodeEnum.IMG_UPLOAD_FAIl.getMsg()); return result; } } if (!ObjectUtils.isEmpty(images)) { String image = images.stream() .map(String::valueOf) .collect(Collectors.joining(",")); supervision.setImages(image); } supervisionMapper.updateById(supervision); return result; } } screen-api/src/main/resources/application-dev.yml
@@ -66,6 +66,12 @@ max-conn-lifetime-millis: 20 test-on-return: false servlet: multipart: enabled: true max-file-size: 2MB max-request-size: 2MB mybatis-plus: mapper-locations: classpath:mapper/*.xml global-config: @@ -116,6 +122,7 @@ - /swagger-ui.html/** - /webjars/** - /verificationCode/** - /static/** AES: KEY: screen-api/src/main/resources/mapper/SupervisionMapper.xml
New file @@ -0,0 +1,23 @@ <?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.moral.api.mapper.SupervisionMapper"> <!-- 通用查询映射结果 --> <resultMap id="BaseResultMap" type="com.moral.api.entity.Supervision"> <id column="id" property="id"/> <result column="city_code" property="cityCode"/> <result column="time" property="time"/> <result column="supervisee_unit" property="superviseeUnit"/> <result column="number" property="number"/> <result column="problem_type" property="problemType"/> <result column="problem_desc" property="problemDesc"/> <result column="images" property="images"/> <result column="handler" property="handler"/> <result column="number_times" property="numberTimes"/> <result column="measures" property="measures"/> <result column="create_time" property="createTime"/> <result column="update_time" property="updateTime"/> <result column="is_delete" property="isDelete"/> </resultMap> </mapper> screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java
@@ -64,7 +64,8 @@ CANNOT_DELETE_ONESELF(-49, "不能删除自己的账号"), EXPIRE_BEYOND_ADMIN(-50, "不能超过主账号过期时间"), SERVICES_SCOPE_IS_EXIST(-51, "服务范围已存在"), SERVICES_SCOPE_IS_NOT_EXIST(-52, "服务范围不存在"); SERVICES_SCOPE_IS_NOT_EXIST(-52, "服务范围不存在"), IMG_UPLOAD_FAIl(-53, "图片上传失败,请确认图片格式和大小"); private final Integer code; private final String msg; screen-common/src/main/java/com/moral/util/FileUtils.java
New file @@ -0,0 +1,33 @@ package com.moral.util; import org.springframework.web.multipart.MultipartFile; import java.io.File; public class FileUtils { /** * @param file 文件 * @param path 文件存放路径 * @param fileName 保存的文件名 * @return */ public static boolean upload(MultipartFile file, String path, String fileName) { //确定上传的文件名 String realPath = path + "\\" + fileName; File dic = new File(path); if (!dic.exists()) { dic.mkdirs(); } try { //保存文件 file.transferTo(new File(realPath)); return true; } catch (Exception e) { e.printStackTrace(); return false; } } }