springcloud_k8s_panzhihuazhihuishequ/applets_backstage/src/main/java/com/panzhihua/applets_backstage/api/CommonDataApi.java
@@ -11,10 +11,7 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; 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 org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -64,4 +61,10 @@ return communityService.saveComMngCar(comMngCarSaveDTO); } @ApiOperation(value = "删除车辆信息") @DeleteMapping("/car/delete") public R deleteComMngCar(@RequestParam(value = "id") Long id) { return communityService.deleteComMngCar(id); } } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/ComMngCarExcelListen.java
New file @@ -0,0 +1,59 @@ package com.panzhihua.common.listen; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.alibaba.fastjson.JSONObject; import com.panzhihua.common.exceptions.ServiceException; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComCvtServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngCarExcelVO; import com.panzhihua.common.service.community.CommunityService; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.List; /** * @description: 车辆导入监听 * @author: Null * @date: 2021/3/11 13:26 */ @Slf4j public class ComMngCarExcelListen extends AnalysisEventListener<ComMngCarExcelVO> { private CommunityService communityService; private Long communityId; public ComMngCarExcelListen(CommunityService communityService, Long communityId){ this.communityService = communityService; this.communityId = communityId; } private static final int BATCH_COUNT = 100; private List<ComMngCarExcelVO> list = new ArrayList<>(); @Override public void invoke(ComMngCarExcelVO comMngCarExcelVO, AnalysisContext analysisContext) { list.add(comMngCarExcelVO); // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM if(list.size() >= BATCH_COUNT){ log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); R r = this.communityService.listSaveMngCarExcelVO(list,this.communityId); if (!R.isOk(r)) { throw new ServiceException(r.getMsg()); } list.clear(); //清空list } } @Override public void doAfterAllAnalysed(AnalysisContext analysisContext) { log.info("excel导入数据【{}】", JSONObject.toJSONString(list)); R r = this.communityService.listSaveMngCarExcelVO(list,this.communityId);//确保最后遗留的数据保存在数据库中 if (!R.isOk(r)) { throw new ServiceException(r.getMsg()); } } } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/ComMngCarAppletDTO.java
@@ -24,17 +24,12 @@ @NotBlank(groups = {AddGroup.class},message = "车牌号不能为空") private String plateNum; @ApiModelProperty(value = "车辆品牌") @NotBlank(groups = {AddGroup.class},message = "车辆品牌不能为空") @ApiModelProperty(value = "车辆品牌型号") @NotBlank(groups = {AddGroup.class},message = "车辆品牌型号不能为空") private String brand; @ApiModelProperty(value = "车身颜色") @NotBlank(groups = {AddGroup.class},message = "车身颜色不能为空") private String color; @ApiModelProperty(value = "车辆型号") @NotBlank(groups = {AddGroup.class},message = "车辆型号不能为空") private String model; @ApiModelProperty(value = "社区ID",hidden = true) private Long communityId; springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/ComMngCarSaveDTO.java
@@ -27,17 +27,12 @@ @NotBlank(groups = {AddGroup.class},message = "车牌号不能为空") private String plateNum; @ApiModelProperty(value = "车辆品牌") @NotBlank(groups = {AddGroup.class},message = "车辆品牌不能为空") @ApiModelProperty(value = "车辆品牌型号") @NotBlank(groups = {AddGroup.class},message = "车辆品牌型号不能为空") private String brand; @ApiModelProperty(value = "车身颜色") @NotBlank(groups = {AddGroup.class},message = "车身颜色不能为空") private String color; @ApiModelProperty(value = "车辆型号") @NotBlank(groups = {AddGroup.class},message = "车辆型号不能为空") private String model; @ApiModelProperty(value = "小区ID") @Min(value = 1,groups = {AddGroup.class},message = "用户小区id不能为空") springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/PageComMngCarDTO.java
@@ -13,9 +13,12 @@ @ApiModel("车辆管理列表请求参数") public class PageComMngCarDTO { @ApiModelProperty(value = "社区id",hidden = true) @ApiModelProperty(value = "社区id") private Long communityId; @ApiModelProperty(value = "小区id") private Long areaId; @ApiModelProperty("车主姓名") private String name; springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/ComMngCarExcelVO.java
New file @@ -0,0 +1,45 @@ package com.panzhihua.common.model.vos.community; import com.alibaba.excel.annotation.ExcelProperty; import lombok.Data; import java.io.Serializable; /** * @description: 批量导入车辆管理 * @author: Null * @date: 2021/3/11 17:11 */ @Data public class ComMngCarExcelVO implements Serializable { /** * 小区名称 */ @ExcelProperty(value = "小区名称" ,index = 0) private String areaName; /** * 车主姓名 */ @ExcelProperty(value = "车主姓名" ,index = 1) private String userName; /** * 联系方式 */ @ExcelProperty(value = "联系方式" ,index = 2) private String mobile; /** * 车牌号 */ @ExcelProperty(value = "车牌号" ,index = 3) private String plateNum; /** * 品牌型号 */ @ExcelProperty(value = "品牌型号" ,index = 4) private String brand; /** * 车身颜色 */ @ExcelProperty(value = "车身颜色" ,index = 5) private String color; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/community/ComMngCarVO.java
@@ -32,6 +32,9 @@ @ApiModelProperty("小区ID") private Long areaId; @ApiModelProperty("详细住址") private String address; @ApiModelProperty("车主姓名") private String userName; @@ -44,14 +47,11 @@ @ApiModelProperty("车牌号") private String plateNum; @ApiModelProperty("车辆品牌") @ApiModelProperty("车辆品牌型号") private String brand; @ApiModelProperty("车身颜色") private String color; @ApiModelProperty("车辆型号") private String model; @ApiModelProperty("创建时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -8,6 +8,7 @@ import com.panzhihua.common.model.vos.SystemmanagementConfigVO; import com.panzhihua.common.model.vos.community.*; import com.panzhihua.common.model.vos.user.UserPhoneVO; import io.swagger.annotations.ApiOperation; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.*; @@ -1161,4 +1162,20 @@ @PostMapping("/common/data/car/save") R saveComMngCar(@RequestBody ComMngCarSaveDTO comMngCarSaveDTO); /** * 删除车辆信息 * @param id * @return */ @DeleteMapping("/common/data/car/delete") R deleteComMngCar(@RequestParam(value = "id") Long id); /** * 批量导入便民服务 * @param list 便民服务集合 */ @PostMapping("/common/data/car/import") R listSaveMngCarExcelVO(@RequestBody List<ComMngCarExcelVO> list,@RequestParam("communityId") Long communityId); } springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/CommonDataApi.java
@@ -1,10 +1,15 @@ package com.panzhihua.community_backstage.api; import com.alibaba.excel.EasyExcel; import com.jcraft.jsch.SftpException; import com.panzhihua.common.controller.BaseController; import com.panzhihua.common.listen.ComCvtServeExcelListen; import com.panzhihua.common.model.dtos.community.ComMngCarSaveDTO; import com.panzhihua.common.model.dtos.community.PageComMngCarDTO; import com.panzhihua.common.model.vos.LoginUserInfoVO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComCvtServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngCarExcelVO; import com.panzhihua.common.model.vos.community.ComMngCarVO; import com.panzhihua.common.service.community.CommunityService; import com.panzhihua.common.validated.AddGroup; @@ -13,12 +18,14 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.validation.annotation.Validated; 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 org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; /** * @description: 社区管理基础数据库管理接口 @@ -34,8 +41,8 @@ @Resource private CommunityService communityService; @Value("${excel.convenientUrl}") private String excelConvenientUrl="http://panzhihua.nhys.cdnhxx.com/web/bianminfuwudaoru.xlsx"; @Value("${excel.carUrl}") private String carUrl="http://panzhihua.nhys.cdnhxx.com/web/%e8%bd%a6%e8%be%86%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; // FTP 登录用户名 @Value("${ftp.username}") private String userName; @@ -67,4 +74,31 @@ return communityService.saveComMngCar(comMngCarSaveDTO); } @ApiOperation(value = "删除车辆信息") @DeleteMapping("/car/delete") public R deleteComMngCar(@RequestParam(value = "id") Long id) { return communityService.deleteComMngCar(id); } @ApiOperation(value = "下载模板-车辆管理") @GetMapping(value = "/car/download/template") public R downloadTemplate(HttpServletResponse response) throws IOException, SftpException { return R.ok(carUrl); } @ApiOperation(value = "excel导入车辆信息") @PostMapping(value = "/car/import", consumes = "multipart/*", headers = "content-type=multipart/form-date") public R downloadTemplate(@RequestParam MultipartFile file, HttpServletRequest request) { String fileName = file.getOriginalFilename(); //获取文件名 log.info("传入文件名字【{}】",fileName); InputStream inputStream = null; try { inputStream = file.getInputStream(); EasyExcel.read(inputStream, ComMngCarExcelVO.class, new ComCvtServeExcelListen(communityService,this.getCommunityId())).sheet().doRead(); } catch (IOException e) { e.printStackTrace(); log.error("导入模板失败【{}】", e.getMessage()); } return R.ok(); } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/CommonDataApi.java
@@ -4,11 +4,14 @@ import com.panzhihua.common.model.dtos.community.ComMngCarSaveDTO; import com.panzhihua.common.model.dtos.community.PageComMngCarDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComCvtServeExcelVO; import com.panzhihua.common.model.vos.community.ComMngCarExcelVO; import com.panzhihua.service_community.service.ComMngCarService; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; /** * @description: 社区管理/基础数据 @@ -53,4 +56,14 @@ public R saveComMngCar(@RequestBody ComMngCarSaveDTO comMngCarSaveDTO) { return comMngCarService.saveComMngCar(comMngCarSaveDTO); } @DeleteMapping("/car/delete") public R deleteComMngCar(@RequestParam(value = "id") Long id) { return comMngCarService.deleteComMngCar(id); } @PostMapping("/car/import") public R listSaveMngCarExcelVO(@RequestBody List<ComMngCarExcelVO> list, @RequestParam("communityId") Long communityId){ return comMngCarService.listSaveMngCarExcelVO(list,communityId); } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/dao/ComMngCarDAO.java
@@ -27,11 +27,11 @@ " t2.area_name AS areaName, " + " t.user_id userId, " + " t.user_name AS userName, " + " t.address, " + " t.mobile, " + " t.plate_num AS plateNum, " + " t.brand, " + " t.color, " + " t.model, " + " t.create_at AS createAt, " + " t3.`name` AS createBy " + "FROM " + @@ -46,6 +46,9 @@ "<if test='pageComMngCarDTO.communityId != null and pageComMngCarDTO.communityId != 0'>" + " and t.community_id = #{pageComMngCarDTO.communityId} " + " </if> " + "<if test='pageComMngCarDTO.areaId != null and pageComMngCarDTO.areaId != 0'>" + " and t.area_id = #{pageComMngCarDTO.areaId} " + " </if> " + " order by t.create_at desc"+ "</script>") IPage<ComMngCarVO> pageQueryComMngCar(Page page, @Param(value = "pageComMngCarDTO") PageComMngCarDTO pageComMngCarDTO); springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/model/dos/ComMngCarDO.java
@@ -1,6 +1,7 @@ package com.panzhihua.service_community.model.dos; import com.baomidou.mybatisplus.annotation.*; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.io.Serializable; @@ -34,6 +35,9 @@ /**车主用户ID*/ private Long userId; /**详细住址*/ private String address; /**车主手机号码*/ private String mobile; @@ -45,9 +49,6 @@ /**车身颜色*/ private String color; /**车辆型号*/ private String model; /**创建时间*/ @TableField(fill = FieldFill.INSERT) springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComMngCarService.java
@@ -4,6 +4,9 @@ import com.panzhihua.common.model.dtos.community.ComMngCarSaveDTO; import com.panzhihua.common.model.dtos.community.PageComMngCarDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngCarExcelVO; import java.util.List; public interface ComMngCarService { @@ -34,4 +37,19 @@ * @return */ R saveComMngCar(ComMngCarSaveDTO comMngCarSaveDTO); /** * 删除车辆信息 * @param id * @return */ R deleteComMngCar(Long id); /** * 批量导入车辆信息 * @param list * @param communityId * @return */ R listSaveMngCarExcelVO(List<ComMngCarExcelVO> list, Long communityId); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java
@@ -9,11 +9,13 @@ import com.panzhihua.common.model.dtos.community.ComMngCarSaveDTO; import com.panzhihua.common.model.dtos.community.PageComMngCarDTO; import com.panzhihua.common.model.vos.R; import com.panzhihua.common.model.vos.community.ComMngCarExcelVO; import com.panzhihua.common.model.vos.community.ComMngCarVO; import com.panzhihua.common.model.vos.user.SysUserVO; import com.panzhihua.common.service.user.UserService; import com.panzhihua.service_community.dao.ComMngCarDAO; import com.panzhihua.service_community.dao.ComMngStructAreaDAO; import com.panzhihua.service_community.model.dos.ComCvtServeDO; import com.panzhihua.service_community.model.dos.ComMngCarDO; import com.panzhihua.service_community.model.dos.ComMngStructAreaDO; import com.panzhihua.service_community.service.ComMngCarService; @@ -43,7 +45,9 @@ @Override public R addComMngCarApplet(ComMngCarAppletDTO comCvtBusinessDTO) { int count = comMngCarDAO.selectCount(new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getPlateNum, comCvtBusinessDTO.getPlateNum())); int count = comMngCarDAO.selectCount(new QueryWrapper<ComMngCarDO>().lambda() .eq(ComMngCarDO::getPlateNum, comCvtBusinessDTO.getPlateNum()) .and(wrapper->wrapper.eq(ComMngCarDO::getSource,1))); if (count > 0) { return R.ok("车辆已存在"); } @@ -88,10 +92,11 @@ @Override public R saveComMngCar(ComMngCarSaveDTO comMngCarSaveDTO) { int count = comMngCarDAO.selectCount(new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getPlateNum, comMngCarSaveDTO.getPlateNum())); if (count > 0) { ComMngCarDO exist= comMngCarDAO.selectOne(new QueryWrapper<ComMngCarDO>() .lambda().eq(ComMngCarDO::getPlateNum, comMngCarSaveDTO.getPlateNum()).and(wrapper->wrapper.eq(ComMngCarDO::getSource,2))); /*if (comMngCarSaveDTO.getId()!=0 && exist.getId()!=comMngCarSaveDTO.getId()) { return R.ok("车辆已存在"); } }*/ ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(comMngCarSaveDTO.getAreaId()); if (ObjectUtils.isEmpty(comMngStructAreaDO)) { return R.fail("小区不存在"); @@ -123,4 +128,29 @@ } return R.fail(); } @Override public R deleteComMngCar(Long id) { int delete = comMngCarDAO.deleteById(id); if (delete==0) { return R.fail("车辆信息不存在"); } return R.ok(); } @Override public R listSaveMngCarExcelVO(List<ComMngCarExcelVO> list, Long communityId) { List<ComMngCarDO> comMngCarDOS = new ArrayList<>(); list.forEach(vo->{ int count = comMngCarDAO.selectCount(new QueryWrapper<ComMngCarDO>() .lambda().eq(ComMngCarDO::getPlateNum, vo.getPlateNum()).and(wrapper->wrapper.eq(ComMngCarDO::getSource,2))); if(count==0){ ComMngCarDO comMngCarDO = new ComMngCarDO(); BeanUtils.copyProperties(vo,comMngCarDO); comMngCarDOS.add(comMngCarDO); } }); this.saveBatch(comMngCarDOS); return R.ok("共计导入车辆数量:"+comMngCarDOS.size()); } }