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
package com.panzhihua.service_community.service.impl;
 
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.community.DisabledPersonsDTO;
import com.panzhihua.common.model.helper.AESUtil;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.service_community.dao.DisablePersonDAO;
import com.panzhihua.service_community.model.dos.ComMngPopulationDO;
import com.panzhihua.service_community.model.dos.DisabledPersonsDO;
import com.panzhihua.service_community.service.ComMngPopulationService;
import com.panzhihua.service_community.service.DisabledPersonsService;
 
/**
 * 残疾人服务
 *
 * @author manailin
 * @date 2021/6/11 16:05
 */
@Service
public class DisabledPersonsServiceImpl extends ServiceImpl<DisablePersonDAO, DisabledPersonsDO>
    implements DisabledPersonsService {
 
    @Value("${domain.aesKey:}")
    private String aesKey;
 
    @Resource
    private ComMngPopulationService comMngPopulationService;
 
    /**
     * description 批量保存重点人群人员信息
     *
     * @param list
     *            重点人群信息
     * @return R 保存结果
     * @author manailin
     * @date 2021/6/10 17:00
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R saveBatchDisabledPerson(List<DisabledPersonsDTO> list) {
        list.forEach(disabledPersonsDTO -> {
            DisabledPersonsDO dbKeyPerson = checkExistFromDb(disabledPersonsDTO);
            ComMngPopulationDO population =
                comMngPopulationService.getPopulationByCardNo(disabledPersonsDTO.getCardNo());
            if (population != null) {
                disabledPersonsDTO.setUserId(population.getId());
            }
            if (dbKeyPerson != null) {
                // 已经存在数据,进行数据更新操作
                DisabledPersonsDO disabledPersonsDO = new DisabledPersonsDO();
                BeanUtils.copyProperties(disabledPersonsDTO, disabledPersonsDO);
                disabledPersonsDO.setId(dbKeyPerson.getId());
                try {
                    String aesCardNo = AESUtil.encrypt128(disabledPersonsDTO.getCardNo(), aesKey);
                    String phone = AESUtil.encrypt128(disabledPersonsDTO.getPhone(), aesKey);
                    String guardianPhone = AESUtil.encrypt128(disabledPersonsDTO.getGuardianPhone(), aesKey);
                    disabledPersonsDO.setCardNo(aesCardNo);
                    disabledPersonsDO.setPhone(phone);
                    disabledPersonsDO.setGuardianPhone(guardianPhone);
                    updateById(disabledPersonsDO);
                } catch (Exception e) {
                    log.error("根据身份证查询残疾人群业务-加密证件信息出错");
                }
            } else {
                DisabledPersonsDO disabledPersonsDO = new DisabledPersonsDO();
                BeanUtils.copyProperties(disabledPersonsDTO, disabledPersonsDO);
                save(disabledPersonsDO);
            }
        });
        return R.ok();
    }
 
    private DisabledPersonsDO checkExistFromDb(DisabledPersonsDTO DisabledPersonsDO) {
        try {
            String aesCardNo = AESUtil.encrypt128(DisabledPersonsDO.getCardNo(), aesKey);
            return baseMapper.selectOne(new QueryWrapper<DisabledPersonsDO>().eq("act_id", DisabledPersonsDO.getActId())
                .eq("card_no", aesCardNo));
        } catch (Exception e) {
            log.error("根据身份证查询残疾人群业务-加密证件信息出错");
        }
        return null;
    }
}