mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
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;
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.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;
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.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;
 
/**
 * @description:
 * @author: Null
 * @date: 2021/3/16 14:33
 */
@Service
public class ComMngCarServiceImpl extends ServiceImpl<ComMngCarDAO, ComMngCarDO> implements ComMngCarService {
 
    @Resource
    private ComMngCarDAO comMngCarDAO;
    @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)));
        if (count > 0) {
            return R.ok("车辆已存在");
        }
        ComMngCarDO comMngCarDO = new ComMngCarDO();
        BeanUtils.copyProperties(comCvtBusinessDTO, comMngCarDO);
        comMngCarDO.setCreateAt(new Date());
        boolean insert = this.save(comMngCarDO);
        if (insert) {
            return R.ok();
        }
        return R.fail();
    }
 
    @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 -> {
            ComMngCarVO carVO = new ComMngCarVO();
            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) {
            List<ComMngCarDO> existList = comMngCarDAO.selectList(
                new QueryWrapper<ComMngCarDO>().lambda().eq(ComMngCarDO::getPlateNum, comMngCarSaveDTO.getPlateNum()));
            if (!existList.isEmpty()) {
                return R.fail("车辆已存在");
            }
        }
        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);
        //如果小区没有名字,则将街路巷和地区号拼接起来
        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);
            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<ComMngVillageDO> comMngVillageDOS = comMngVillageDAO.selectList(
            new QueryWrapper<ComMngVillageDO>().lambda().eq(ComMngVillageDO::getCommunityId, communityId));
        Map<String, ComMngVillageDO> areaMap = new HashMap<>(comMngVillageDOS.size());
        comMngVillageDOS.forEach(comMngVillageDO -> {
            areaMap.put(comMngVillageDO.getName(),comMngVillageDO);
        });
        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)));
            ComMngCarDO comMngCarDO = new ComMngCarDO();
            BeanUtils.copyProperties(vo, comMngCarDO);
            if (count == 0 ) {
                if(StringUtils.isNotEmpty(vo.getAreaName())&&areaMap.containsKey(vo.getAreaName())){
                    comMngCarDO.setAreaId(areaMap.get(vo.getAreaName()).getVillageId());
                }
                try {
                    comMngCarDO.setCardNo(AESUtil.encrypt128(vo.getCardNo(), aesKey));
                } catch (Exception e) {
 
                }
                comMngCarDO.setCommunityId(communityId);
                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);
            }
        });
        if(comMngCarDOS.isEmpty()){
            return R.fail("导入数据有误");
        }
        else {
            this.saveBatch(comMngCarDOS);
            return R.ok("共计导入车辆数量:" + comMngCarDOS.size());
        }
    }
 
    @Override
    public R exportRealCar(ExportComMngCarExcelDTO exportComMngCarExcelDTO) {
        List<ComMngCarExcelVO> list = comMngCarDAO.exportRealCar(exportComMngCarExcelDTO);
        return R.ok(list);
    }
}