From 50e1eb020efe8da670b718d865fa4c1eaa61ee7d Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期四, 20 五月 2021 19:51:09 +0800
Subject: [PATCH] 修改bug

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java |  134 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 126 insertions(+), 8 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java
index 481784d..7df411d 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java
@@ -1,21 +1,31 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.panzhihua.common.model.dtos.community.ComMngCarAppletDTO;
+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.common.utlis.ParamRegularUtil;
 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;
 import org.springframework.beans.BeanUtils;
-import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 /**
  * @description:
@@ -27,10 +37,17 @@
 
     @Resource
     private ComMngCarDAO comMngCarDAO;
+    @Resource
+    private ComMngStructAreaDAO comMngStructAreaDAO;
+    @Resource
+    private UserService userService;
+
 
     @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("车辆已存在");
         }
@@ -47,12 +64,113 @@
     @Override
     public R userComMngCarList(Long userId) {
         List<ComMngCarVO> comMngCarVOS = new ArrayList<>();
-        List<ComMngCarDO> carDOS = comMngCarDAO.selectList(new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getUserId,userId));
-        carDOS.forEach(carDO->{
+        List<ComMngCarDO> carDOS = comMngCarDAO.selectList(new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getUserId, userId));
+        carDOS.forEach(carDO -> {
             ComMngCarVO carVO = new ComMngCarVO();
-            BeanUtils.copyProperties(carDO,carVO);
+            BeanUtils.copyProperties(carDO, carVO);
             comMngCarVOS.add(carVO);
         });
         return R.ok(comMngCarVOS);
     }
+
+    @Override
+    public R pageQueryComMngCar(PageComMngCarDTO pageComMngCarDTO) {
+        Page page = new Page<>();
+        Long pageNum = pageComMngCarDTO.getPageNum();
+        Long pageSize = pageComMngCarDTO.getPageSize();
+        if (null == pageNum || 0 == pageNum) {
+            pageNum = 1l;
+        }
+        if (null == pageSize || 0 == pageSize) {
+            pageSize = 10l;
+        }
+        page.setSize(pageSize);
+        page.setCurrent(pageNum.longValue());
+        IPage<ComMngCarVO> iPage = comMngCarDAO.pageQueryComMngCar(page, pageComMngCarDTO);
+        return R.ok(iPage);
+    }
+
+    @Override
+    public R saveComMngCar(ComMngCarSaveDTO comMngCarSaveDTO) {
+        boolean carResult = ParamRegularUtil.carNumRegular(comMngCarSaveDTO.getPlateNum());
+        if (!carResult) {
+            return R.fail("车牌号有误!");
+        }
+        if (comMngCarSaveDTO.getId()==null) {
+            ComMngCarDO exist = comMngCarDAO.selectOne(new QueryWrapper<ComMngCarDO>()
+                    .lambda().eq(ComMngCarDO::getPlateNum, comMngCarSaveDTO.getPlateNum()));
+            if (exist != null) {
+                return R.ok("车辆已存在");
+            }
+        }
+        ComMngStructAreaDO comMngStructAreaDO = comMngStructAreaDAO.selectById(comMngCarSaveDTO.getAreaId());
+        if (ObjectUtils.isEmpty(comMngStructAreaDO)) {
+            return R.fail("小区不存在");
+        }
+        if (ObjectUtils.isEmpty(comMngCarSaveDTO.getMobile())) {
+            return R.fail("车主手机号码不能为空");
+        }
+        ComMngCarDO comMngCarDO = new ComMngCarDO();
+        BeanUtils.copyProperties(comMngCarSaveDTO, comMngCarDO);
+        comMngCarDO.setAreaName(comMngStructAreaDO.getAreaName());
+        comMngCarDO.setCommunityId(comMngStructAreaDO.getCommunityId());
+        comMngCarDO.setCreateAt(new Date());
+        comMngCarDO.setSource(2);
+        R<SysUserVO> sysUserVOR = userService.getSysUserVOByPhone(comMngCarSaveDTO.getMobile());
+        if (R.isOk(sysUserVOR)) {
+            SysUserVO sysUserVO = JSONObject.parseObject(JSONObject.toJSONString(sysUserVOR.getData()), SysUserVO.class);
+            comMngCarSaveDTO.setUserId(sysUserVO.getUserId());
+        }
+        if (null != comMngCarDO.getId() && comMngCarDO.getId() != 0) {
+            boolean update = this.updateById(comMngCarDO);
+            if (update) {
+                return R.ok();
+            }
+        } else {
+            boolean insert = this.save(comMngCarDO);
+            if (insert) {
+                return R.ok();
+            }
+        }
+        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<ComMngStructAreaDO> comMngStructAreaDOs = comMngStructAreaDAO.selectList(new QueryWrapper<ComMngStructAreaDO>().lambda().eq(ComMngStructAreaDO::getCommunityId, communityId));
+        Map<String, ComMngStructAreaDO> areaMap = new HashMap<>(comMngStructAreaDOs.size());
+        comMngStructAreaDOs.forEach(comMngStructAreaDO -> {
+            areaMap.put(comMngStructAreaDO.getAreaName(), comMngStructAreaDO);
+        });
+        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 && areaMap.containsKey(vo.getAreaName())) {
+                ComMngCarDO comMngCarDO = new ComMngCarDO();
+                BeanUtils.copyProperties(vo, comMngCarDO);
+                comMngCarDO.setCommunityId(communityId);
+                comMngCarDO.setAreaId(areaMap.get(vo.getAreaName()).getId());
+                R<SysUserVO> sysUserVOR = userService.getSysUserVOByPhone(vo.getMobile());
+                if (R.isOk(sysUserVOR)) {
+                    SysUserVO sysUserVO = JSONObject.parseObject(JSONObject.toJSONString(sysUserVOR.getData()), SysUserVO.class);
+                    comMngCarDO.setUserId(sysUserVO.getUserId());
+                }
+                comMngCarDO.setSource(2);
+                comMngCarDOS.add(comMngCarDO);
+            }
+        });
+        this.saveBatch(comMngCarDOS);
+        return R.ok("共计导入车辆数量:" + comMngCarDOS.size());
+    }
 }

--
Gitblit v1.7.1