101captain
2021-12-23 5a8a90c095280fbd2106869ecd2bad10e01a57a6
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComMngCarServiceImpl.java
@@ -1,5 +1,15 @@
package com.panzhihua.service_community.service.impl;
import java.util.*;
import javax.annotation.Resource;
import com.panzhihua.common.utlis.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -7,7 +17,9 @@
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.ExportComMngCarExcelDTO;
import com.panzhihua.common.model.dtos.community.PageComMngCarDTO;
import com.panzhihua.common.model.helper.AESUtil;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngCarExcelVO;
import com.panzhihua.common.model.vos.community.ComMngCarVO;
@@ -16,16 +28,11 @@
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.dao.ComMngVillageDAO;
import com.panzhihua.service_community.model.dos.ComMngCarDO;
import com.panzhihua.service_community.model.dos.ComMngStructAreaDO;
import com.panzhihua.service_community.model.dos.ComMngVillageDO;
import com.panzhihua.service_community.service.ComMngCarService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.util.*;
/**
 * @description:
@@ -40,14 +47,17 @@
    @Resource
    private ComMngStructAreaDAO comMngStructAreaDAO;
    @Resource
    private ComMngVillageDAO comMngVillageDAO;
    @Resource
    private UserService userService;
    @Value("${domain.aesKey:}")
    private String aesKey;
    @Override
    public R addComMngCarApplet(ComMngCarAppletDTO comCvtBusinessDTO) {
        int count = comMngCarDAO.selectCount(new QueryWrapper<ComMngCarDO>().lambda()
                .eq(ComMngCarDO::getPlateNum, comCvtBusinessDTO.getPlateNum())
                .and(wrapper->wrapper.eq(ComMngCarDO::getSource,1)));
        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("车辆已存在");
        }
@@ -64,10 +74,11 @@
    @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);
@@ -93,38 +104,62 @@
    @Override
    public R saveComMngCar(ComMngCarSaveDTO comMngCarSaveDTO) {
        boolean carResult = ParamRegularUtil.carNumRegular(comMngCarSaveDTO.getPlateNum());
        if(!carResult){
        if (!carResult) {
            return R.fail("车牌号有误!");
        }
        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)) {
        if (comMngCarSaveDTO.getId() == null) {
            List<ComMngCarDO> existList = comMngCarDAO.selectList(
                new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getPlateNum, comMngCarSaveDTO.getPlateNum()));
            if (!existList.isEmpty()) {
                return R.ok("车辆已存在");
            }
        }
        ComMngVillageDO comMngVillageDO = comMngVillageDAO.selectById(comMngCarSaveDTO.getAreaId());
        if (ObjectUtils.isEmpty(comMngVillageDO)) {
            return R.fail("小区不存在");
        }
        if (ObjectUtils.isEmpty(comMngCarSaveDTO.getMobile())) {
            return R.fail("车主手机号码不能为空");
        }
        if (ObjectUtils.isEmpty(comMngCarSaveDTO.getCardNo())) {
            return R.fail("车主身份证号码不能为空");
        }
        ComMngCarDO comMngCarDO = new ComMngCarDO();
        BeanUtils.copyProperties(comMngCarSaveDTO, comMngCarDO);
        comMngCarDO.setAreaName(comMngStructAreaDO.getAreaName());
        comMngCarDO.setCommunityId(comMngStructAreaDO.getCommunityId());
        //如果小区没有名字,则将街路巷和地区号拼接起来
        if(comMngVillageDO.getName() != null && StringUtils.isNotEmpty(comMngVillageDO.getName())){
            comMngCarDO.setAreaName(comMngVillageDO.getName());
        }else{
            StringBuilder sb = new StringBuilder();
            sb.append(comMngVillageDO.getAlley());
            if(!comMngVillageDO.getHouseNum().contains("号")){
                sb.append(comMngVillageDO.getHouseNum() + "号");
            }
            comMngCarDO.setAreaName(sb.toString());
        }
//        if(comMngVillageDO.getGroupAt() == null){
//            comMngCarDO.setAreaName(comMngVillageDO.getGroupAt());
//        }
        comMngCarDO.setCommunityId(comMngVillageDO.getCommunityId());
        try {
            comMngCarDO.setCardNo(AESUtil.encrypt128(comMngCarSaveDTO.getCardNo(), aesKey));
        } catch (Exception e) {
        }
        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);
        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){
        if (null != comMngCarDO.getId() && comMngCarDO.getId() != 0) {
            boolean update = this.updateById(comMngCarDO);
            if (update) {
                return R.ok();
            }
        }else{
        } else {
            boolean insert = this.save(comMngCarDO);
            if (insert) {
                return R.ok();
@@ -136,7 +171,7 @@
    @Override
    public R deleteComMngCar(Long id) {
        int delete = comMngCarDAO.deleteById(id);
        if (delete==0) {
        if (delete == 0) {
            return R.fail("车辆信息不存在");
        }
        return R.ok();
@@ -144,24 +179,31 @@
    @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<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())){
        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);
                BeanUtils.copyProperties(vo, comMngCarDO);
                try {
                    comMngCarDO.setCardNo(AESUtil.encrypt128(vo.getCardNo(), aesKey));
                } catch (Exception e) {
                }
                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);
                if (R.isOk(sysUserVOR)) {
                    SysUserVO sysUserVO =
                        JSONObject.parseObject(JSONObject.toJSONString(sysUserVOR.getData()), SysUserVO.class);
                    comMngCarDO.setUserId(sysUserVO.getUserId());
                }
                comMngCarDO.setSource(2);
@@ -169,6 +211,12 @@
            }
        });
        this.saveBatch(comMngCarDOS);
        return R.ok("共计导入车辆数量:"+comMngCarDOS.size());
        return R.ok("共计导入车辆数量:" + comMngCarDOS.size());
    }
    @Override
    public R exportRealCar(ExportComMngCarExcelDTO exportComMngCarExcelDTO) {
        List<ComMngCarExcelVO> list = comMngCarDAO.exportRealCar(exportComMngCarExcelDTO);
        return R.ok(list);
    }
}