xyh
2021-06-11 ec584b22c5756b8a2bdad9dcd0830c52d698784d
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
package com.panzhihua.service_community.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngBuildingExcelVO;
import com.panzhihua.common.model.vos.community.ComMngPopulationImportErrorVO;
import com.panzhihua.service_community.dao.ComActDAO;
import com.panzhihua.service_community.dao.ComActVillageDAO;
import com.panzhihua.service_community.dao.ComMngBuildingDAO;
import com.panzhihua.service_community.model.dos.ComActDO;
import com.panzhihua.service_community.model.dos.ComMngBuildingDO;
import com.panzhihua.service_community.model.dos.ComMngVillageDO;
import com.panzhihua.service_community.service.ComActBuildingService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
 
/**
 * @author xyh
 * @date 2021/6/10 13:46
 */
@Service
public class ComActBuildingServiceImpl extends ServiceImpl<ComMngBuildingDAO, ComMngBuildingDO> implements ComActBuildingService {
 
    @Resource
    private ComActVillageDAO comActVillageDAO;
    @Resource
    private ComActDAO comActDAO;
 
    @Override
    public R batchSaveBuilding(List<ComMngBuildingExcelVO> newVoList, Long communityId) {
        ArrayList<ComMngBuildingDO> list = Lists.newArrayList();
        int index = 2;
        List<ComMngPopulationImportErrorVO> errorList = new ArrayList<>();
        for(ComMngBuildingExcelVO vo:newVoList){
 
            ComMngVillageDO comMngVillageDO = comActVillageDAO.selectOne(new QueryWrapper<ComMngVillageDO>().eq("alley",vo.getAlley()).eq("house_num",vo.getDoorNo()).eq("community_id",communityId));
            if(comMngVillageDO == null){
                continue;
            }
            List<ComMngBuildingDO> buildingDOList = this.baseMapper.selectList(new QueryWrapper<ComMngBuildingDO>().eq("street_id",comMngVillageDO.getStreetId()).eq("act_id",communityId).eq("village_id",comMngVillageDO.getVillageId()).eq("name",vo.getName()));
            if(buildingDOList.size() > 0){
                ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
                importErrorVO.setErrorMsg("重复楼栋");
                importErrorVO.setErrorPosition("第" + index + "行");
                errorList.add(importErrorVO);
                continue;
            }
            ComMngBuildingDO comMngBuildingDO = new ComMngBuildingDO();
            BeanUtils.copyProperties(vo,comMngBuildingDO);
            comMngBuildingDO.setActId(comMngVillageDO.getCommunityId());
            comMngBuildingDO.setStreetId(comMngVillageDO.getStreetId());
            comMngBuildingDO.setVillageId(comMngVillageDO.getVillageId());
            ComActDO actDO = comActDAO.selectById(comMngVillageDO.getCommunityId());
            StringBuilder path = new StringBuilder();
            path.append(vo.getAlley()).append(">").append(actDO.getName()).append(vo.getVillageName()).append(">").append(vo.getName());
            comMngBuildingDO.setPath(path.toString());
            comMngBuildingDO.setGridId(null);
            list.add(comMngBuildingDO);
            index ++;
        }
 
        if(list.size()>0){
            this.saveBatch(list);
        }
 
        if(errorList.size() > 0){
            return R.fail(JSON.toJSONString(errorList));
        }
        return R.ok();
    }
}