all
huanghongfa
2021-02-20 2ff68802d432b0a0358814e0c1820b95a2a92e03
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
package com.panzhihua.service_user.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.user.EexcelUserDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.ComMngStructAreaVO;
import com.panzhihua.common.model.vos.community.ComMngStructHouseVO;
import com.panzhihua.common.model.vos.community.ComMngVolunteerMngVO;
import com.panzhihua.common.model.vos.user.ComMngFamilyInfoVO;
import com.panzhihua.common.model.vos.user.CommunityUserInfoVO;
import com.panzhihua.common.utlis.IdCard;
import com.panzhihua.service_user.dao.SysUserInputDAO;
import com.panzhihua.service_user.model.dos.ComMngFamilyInfoDO;
import com.panzhihua.service_user.model.dos.SysUserDO;
import com.panzhihua.service_user.model.dos.SysUserInputDO;
import com.panzhihua.service_user.service.SysUserInputService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @program: springcloud_k8s_panzhihuazhihuishequ
 * @description: 居民导入
 * @author: huang.hongfa weixin hhf9596 qq 959656820
 * @create: 2021-02-05 17:42
 **/
@Service
public class SysUserInputServiceImpl extends ServiceImpl<SysUserInputDAO, SysUserInputDO> implements SysUserInputService {
    @Resource
    private SysUserInputDAO sysUserInputDAO;
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    /**
     * 批量导入居民用户
     * @param list 居民用户集合
     * @param areaName 小区名字
     * @return 导入结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R batchSaveUser(List<EexcelUserDTO> list, StringBuffer areaName) {
        List<SysUserInputDO> sysUserInputDOS=new ArrayList<>();
        if (!ObjectUtils.isEmpty(list)) {
            ComMngStructAreaVO comMngStructAreaVO=sysUserInputDAO.selectByAreaName(areaName.toString());
//            查询该小区所有房屋信息用来进行匹配房屋编码
            String key="house_"+areaName;
            Boolean aBoolean = stringRedisTemplate.hasKey(key);
            ValueOperations<String, String> stringStringValueOperations = stringRedisTemplate.opsForValue();
            List<ComMngStructHouseVO> comMngStructHouseVOS=new ArrayList<>();
            if (aBoolean) {
                String value = stringStringValueOperations.get(key);
                 comMngStructHouseVOS= JSONArray.parseArray(value,ComMngStructHouseVO.class);
            }else{
                comMngStructHouseVOS=sysUserInputDAO.selectHouserByareaName(areaName.toString());
            }
            List<ComMngStructHouseVO> comMngStructHouseVOS1=comMngStructHouseVOS;
            list.forEach(eexcelUserDTO -> {
                SysUserInputDO sysUserInputDO=new SysUserInputDO();
                String doorNumber = eexcelUserDTO.getDoorNumber();
                List<ComMngStructHouseVO> collect = comMngStructHouseVOS1.stream().filter(comMngStructHouseVO -> comMngStructHouseVO.getHouseName().equals(doorNumber)).collect(Collectors.toList());
                if (ObjectUtils.isEmpty(collect)) {
                    throw new ServiceException("门牌号后台不存在或格式错误,错误门牌号为"+doorNumber);
                }else{
                    sysUserInputDO.setHouseCode(collect.get(0).getHouseCode());
                }
                sysUserInputDO.setAreaId(comMngStructAreaVO.getId());
                sysUserInputDO.setCommunityId(comMngStructAreaVO.getCommunityId());
                sysUserInputDO.setCompany(eexcelUserDTO.getCompany());
                sysUserInputDO.setDoorNumber(doorNumber);
                sysUserInputDO.setEducation(eexcelUserDTO.getEducation());
                sysUserInputDO.setIdCard(eexcelUserDTO.getIdCard());
                sysUserInputDO.setIsContact(eexcelUserDTO.getIsContact().equals("是")?1:0);
                sysUserInputDO.setIsPanzhihua(eexcelUserDTO.getIsPanZhiHua().equals("是")?1:0);
                sysUserInputDO.setIsRent(eexcelUserDTO.getIsRent().equals("是")?1:0);
                sysUserInputDO.setKeyPersonnel(eexcelUserDTO.getKeyPersonnel().equals("是")?1:0);
                sysUserInputDO.setLowincomeHouseholds(eexcelUserDTO.getLowIncomeHouseholds().equals("是")?1:0);
                sysUserInputDO.setLowincomePeople(eexcelUserDTO.getLowIncomePeople().equals("是")?1:0);
                sysUserInputDO.setMajor(eexcelUserDTO.getMajor().equals("是")?1:0);
                sysUserInputDO.setMaritalStatus(eexcelUserDTO.getMaritalStatus().equals("是")?1:0);
                sysUserInputDO.setName(eexcelUserDTO.getName());
                sysUserInputDO.setNation(eexcelUserDTO.getNation());
                sysUserInputDO.setOldPeople(eexcelUserDTO.getOldPeople().equals("是")?1:0);
                sysUserInputDO.setDisability(eexcelUserDTO.getDisability().equals("是")?1:0);
                sysUserInputDO.setPhone(eexcelUserDTO.getPhone());
                String politicalOutlook = eexcelUserDTO.getPoliticalOutlook();
                sysUserInputDO.setPoliticalOutlook(politicalOutlook.equals("党员")?1:politicalOutlook.equals("团员")?2:3);
                sysUserInputDO.setResidence(eexcelUserDTO.getResidence());
                sysUserInputDO.setSituation(eexcelUserDTO.getSituation());
                sysUserInputDO.setSoldier(eexcelUserDTO.getSoldier().equals("是")?1:0);
                sysUserInputDO.setSpecialServiceFamily(eexcelUserDTO.getSpecialServiceFamily().equals("是")?1:0);
 
                sysUserInputDOS.add(sysUserInputDO);
            });
            this.saveBatch(sysUserInputDOS);
        }
        return R.ok();
    }
 
    /**
     * 社区人员详情包括导入人员
     *
     * @param userId 人员id
     * @return CommunityUserInfoVO
     */
    @Override
    public CommunityUserInfoVO detailUserComunity(Long userId) {
        CommunityUserInfoVO communityUserInfoVO=new CommunityUserInfoVO();
        userId=userId-100000000l;
        SysUserInputDO sysUserInputDO = sysUserInputDAO.selectById(userId);
        if (!org.springframework.util.ObjectUtils.isEmpty(sysUserInputDO)) {
            BeanUtils.copyProperties(sysUserInputDO,communityUserInfoVO);
            String idCard = sysUserInputDO.getIdCard();
            if (!org.springframework.util.ObjectUtils.isEmpty(idCard)) {
                communityUserInfoVO.setAge(IdCard.IdNOToAge(idCard));
                communityUserInfoVO.setBirthday(IdCard.birthDay(idCard));
                communityUserInfoVO.setIdCard(idCard);
                communityUserInfoVO.setSex(IdCard.sex(idCard));
            }
            String phone = sysUserInputDO.getPhone();
            communityUserInfoVO.setPhone(phone);
            Integer keyPersonnel = sysUserInputDO.getKeyPersonnel();
            Integer specialServiceFamily = sysUserInputDO.getSpecialServiceFamily();
            Integer soldier = sysUserInputDO.getSoldier();
            Integer lowincomeHouseholds = sysUserInputDO.getLowincomeHouseholds();
            Integer lowincomePeople = sysUserInputDO.getLowincomePeople();
            Integer oldPeople = sysUserInputDO.getOldPeople();
            Integer disability = sysUserInputDO.getDisability();
 
            StringBuilder stringBuilder=new StringBuilder("");
            if (keyPersonnel.intValue()==1) {
                stringBuilder.append("重点人员,");
            }
            if (specialServiceFamily.intValue()==1) {
                stringBuilder.append("特服家庭,");
            }
            if (soldier.intValue()==1) {
                stringBuilder.append("军人,");
            }
            if (lowincomeHouseholds.intValue()==1) {
                stringBuilder.append("低保户,");
            }
            if (lowincomePeople.intValue()==1) {
                stringBuilder.append("低收入人员,");
            }
            if (oldPeople.intValue()==1) {
                stringBuilder.append("高龄老人,");
            }
            if (disability.intValue()==1) {
                stringBuilder.append("残疾人,");
            }
            communityUserInfoVO.setTags(stringBuilder.toString());
            communityUserInfoVO.setUserId(userId);
            communityUserInfoVO.setIsVolunteer(0);
            String doorNumber = sysUserInputDO.getDoorNumber();
            List<ComMngFamilyInfoVO> comMngFamilyInfoVOS = sysUserInputDAO.selectListFamily(doorNumber,userId);
            communityUserInfoVO.setComMngFamilyInfoVOS(comMngFamilyInfoVOS);
        }
        return communityUserInfoVO;
    }
}