From 4669a215d1d76db22b79f3c3651d3be7156be543 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Fri, 14 Jan 2022 15:08:40 +0800 Subject: [PATCH] 督办单 --- screen-api/src/main/java/com/moral/api/service/SupervisionService.java | 29 +++ screen-api/src/main/resources/mapper/SupervisionMapper.xml | 23 ++ screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java | 18 ++ screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java | 3 screen-api/src/main/resources/application-dev.yml | 7 screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java | 161 ++++++++++++++++++++ screen-api/src/main/java/com/moral/api/mapper/SupervisionMapper.java | 17 ++ screen-common/src/main/java/com/moral/util/FileUtils.java | 33 ++++ screen-api/src/main/java/com/moral/api/controller/SupervisionController.java | 72 +++++++++ screen-api/src/main/java/com/moral/api/entity/Supervision.java | 112 ++++++++++++++ 10 files changed, 473 insertions(+), 2 deletions(-) diff --git a/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java b/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java index dec9b13..4afcad5 100644 --- a/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java +++ b/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(); + } + + } } diff --git a/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java b/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java new file mode 100644 index 0000000..5f07951 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/controller/SupervisionController.java @@ -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(); + } + +} diff --git a/screen-api/src/main/java/com/moral/api/entity/Supervision.java b/screen-api/src/main/java/com/moral/api/entity/Supervision.java new file mode 100644 index 0000000..17f4a4f --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/entity/Supervision.java @@ -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; + } + +} diff --git a/screen-api/src/main/java/com/moral/api/mapper/SupervisionMapper.java b/screen-api/src/main/java/com/moral/api/mapper/SupervisionMapper.java new file mode 100644 index 0000000..e2f0b93 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/mapper/SupervisionMapper.java @@ -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> { + +} diff --git a/screen-api/src/main/java/com/moral/api/service/SupervisionService.java b/screen-api/src/main/java/com/moral/api/service/SupervisionService.java new file mode 100644 index 0000000..b17644f --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/service/SupervisionService.java @@ -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); + +} diff --git a/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java new file mode 100644 index 0000000..4afdb41 --- /dev/null +++ b/screen-api/src/main/java/com/moral/api/service/impl/SupervisionServiceImpl.java @@ -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; + } +} diff --git a/screen-api/src/main/resources/application-dev.yml b/screen-api/src/main/resources/application-dev.yml index d1498d7..49177d8 100644 --- a/screen-api/src/main/resources/application-dev.yml +++ b/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: diff --git a/screen-api/src/main/resources/mapper/SupervisionMapper.xml b/screen-api/src/main/resources/mapper/SupervisionMapper.xml new file mode 100644 index 0000000..7db5524 --- /dev/null +++ b/screen-api/src/main/resources/mapper/SupervisionMapper.xml @@ -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> \ No newline at end of file diff --git a/screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java b/screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java index 54dea75..24f8f23 100644 --- a/screen-common/src/main/java/com/moral/constant/ResponseCodeEnum.java +++ b/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; diff --git a/screen-common/src/main/java/com/moral/util/FileUtils.java b/screen-common/src/main/java/com/moral/util/FileUtils.java new file mode 100644 index 0000000..8434170 --- /dev/null +++ b/screen-common/src/main/java/com/moral/util/FileUtils.java @@ -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; + } + } +} \ No newline at end of file -- Gitblit v1.8.0