From 1d21a9673d47a186bd189d9cceaa6e2ea17d293d Mon Sep 17 00:00:00 2001
From: CeDo <cedoogle@gmail.com>
Date: 星期二, 15 六月 2021 14:55:44 +0800
Subject: [PATCH] Merge branch 'test'

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/EldersAuthServiceImpl.java |  354 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 349 insertions(+), 5 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/EldersAuthServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/EldersAuthServiceImpl.java
index 4b7313a..2ef4466 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/EldersAuthServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/EldersAuthServiceImpl.java
@@ -1,33 +1,53 @@
 package com.panzhihua.service_community.service.impl;
 
+import cn.hutool.core.util.IdcardUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+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.exceptions.ServiceException;
 import com.panzhihua.common.model.dtos.community.*;
+import com.panzhihua.common.model.dtos.elders.ComEldersAuthGetResultDTO;
+import com.panzhihua.common.model.dtos.elders.ComEldersAuthPageDTO;
+import com.panzhihua.common.model.dtos.elders.ComEldersAuthUserAddAppDTO;
+import com.panzhihua.common.model.helper.AESUtil;
 import com.panzhihua.common.model.vos.R;
+import com.panzhihua.common.model.vos.community.*;
 import com.panzhihua.common.model.vos.community.EldersAuthDetailsVO;
 import com.panzhihua.common.model.vos.community.EldersAuthFeedbackVO;
 import com.panzhihua.common.model.vos.community.EldersAuthVO;
+import com.panzhihua.common.model.vos.elders.ComElderAuthUserAppVO;
+import com.panzhihua.common.model.vos.partybuilding.ComEldersAuthHistoryExcelVO;
+import com.panzhihua.common.model.vos.user.SysUserVO;
+import com.panzhihua.common.utlis.AgeUtils;
+import com.panzhihua.common.utlis.DateUtils;
+import com.panzhihua.common.utlis.IdCard;
+import com.panzhihua.common.utlis.StringUtils;
 import com.panzhihua.service_community.dao.*;
 import com.panzhihua.service_community.model.dos.*;
 import com.panzhihua.service_community.service.EldersAuthService;
-import io.swagger.annotations.ApiModelProperty;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.BeanUtils;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.text.SimpleDateFormat;
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
 /**
  * @auther lyq
  * @create 2021-04-14 15:03:01
- * @describe 订单表服务实现类
+ * @describe 服务实现类
  */
 @Slf4j
 @Service
@@ -35,9 +55,22 @@
 
     @Resource
     private EldersAuthDAO eldersAuthDAO;
-
     @Resource
     private EldersAuthFeedbackDAO eldersAuthFeedbackDAO;
+    @Resource
+    private ComEldersAuthUserMapper comEldersAuthUserMapper;
+    @Resource
+    private ComEldersAuthElderlyMapper comEldersAuthElderlyMapper;
+    @Resource
+    private SysConfMapper sysConfDao;
+    @Resource
+    private ComEldersAuthHistoryRecordMapper comEldersAuthHistoryRecordMapper;
+    @Resource
+    private ComEldersAuthStatisticsMapper comEldersAuthStatisticsMapper;
+
+    @Value("${domain.aesKey:}")
+    private String aesKey;
+
     /**
      * 新增高龄认证
      * @param eldersAuthAddDTO
@@ -119,12 +152,29 @@
      * @param eldersAuthFeedbackAddDTO
      * @return 新增结果
      */
+    @Transactional(rollbackFor = Exception.class)
     public R addFeedback(EldersAuthFeedbackAddDTO eldersAuthFeedbackAddDTO){
+        EldersAuthDO eldersAuthDO = eldersAuthDAO.selectById(eldersAuthFeedbackAddDTO.getAuthId());
+        if(eldersAuthDO==null){
+            return R.fail("认证记录不存在");
+        }
+        if(eldersAuthDO.getType()==null){
+            return R.fail("认证方式未知");
+        }
+        if(eldersAuthDO.getType().intValue()!=1){
+            return R.fail("当前认证方式不能进行反馈");
+        }
         EldersAuthFeedbackDO eldersAuthFeedbackDO = new EldersAuthFeedbackDO();
         eldersAuthFeedbackDO.setCreateBy(eldersAuthFeedbackAddDTO.getUserId());
         eldersAuthFeedbackDO.setCreateAt(new Date());
         BeanUtils.copyProperties(eldersAuthFeedbackAddDTO, eldersAuthFeedbackDO);
         if(eldersAuthFeedbackDAO.insert(eldersAuthFeedbackDO)>0){
+            eldersAuthDO.setStatus("1");
+            eldersAuthDO.setIdCard(null);
+            int updated = eldersAuthDAO.updateById(eldersAuthDO);
+            if(updated!=1){
+                throw new ServiceException("更新认证记录状态失败");
+            }
             return R.ok();
         }
         return R.fail();
@@ -147,4 +197,298 @@
     public String queryDomicile(String idCard) {
         return eldersAuthDAO.selectDomicile(idCard);
     }
+
+    @Override
+    public R queryEldersRecord(PageComEldersRecordsDTO pageComEldersRecordsDTO) {
+        Page page = new Page<>();
+        page.setSize(pageComEldersRecordsDTO.getPageSize());
+        page.setCurrent(pageComEldersRecordsDTO.getPageNum());
+        List<ComEldersAuthRecordVO> eldersAuthDOList = eldersAuthDAO.selectEldersRecordByPage(page, pageComEldersRecordsDTO);
+        return R.ok(eldersAuthDOList);
+    }
+
+    @Override
+    public R<ComEldersAuthElderlyDetailsVO> comEldersAuthElderlyDetails(Long id) {
+        EldersAuthDO eldersAuthDO = eldersAuthDAO.selectById(id);
+        if(eldersAuthDO == null){
+            return R.fail("未查询到认证记录");
+        }
+        ComEldersAuthElderlyDetailsVO comEldersAuthElderlyDetailsVO = new ComEldersAuthElderlyDetailsVO();
+        BeanUtils.copyProperties(eldersAuthDO, comEldersAuthElderlyDetailsVO);
+
+        String communityName = eldersAuthDAO.selectCommunityNameByAuth(id);
+        comEldersAuthElderlyDetailsVO.setCommunityName(communityName);
+
+        List<EldersAuthFeedbackDO> eldersAuthFeedbackDOList = eldersAuthFeedbackDAO.selectList(new LambdaQueryWrapper<EldersAuthFeedbackDO>().eq(EldersAuthFeedbackDO::getAuthId, id));
+        List<EldersAuthFeedbackVO> eldersAuthFeedbackVOList = new ArrayList<>();
+        eldersAuthFeedbackDOList.forEach(edo ->{
+            EldersAuthFeedbackVO eldersAuthFeedbackVO = new EldersAuthFeedbackVO();
+            BeanUtils.copyProperties(edo, eldersAuthFeedbackVO);
+            eldersAuthFeedbackVOList.add(eldersAuthFeedbackVO);
+        });
+        comEldersAuthElderlyDetailsVO.setFeedback(eldersAuthFeedbackVOList);
+        return R.ok(comEldersAuthElderlyDetailsVO);
+    }
+
+    @Override
+    public R communityAuthType(EldersAuthTypeQueryDTO eldersAuthTypeQueryDTO) {
+        Long communityId = eldersAuthTypeQueryDTO.getCommunityId();
+        List<SysConfDO> confDOList =
+                sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>().eq(SysConfDO::getCommunityId, communityId)
+                .orderByDesc(SysConfDO::getCreateAt));
+        if(confDOList==null || confDOList.size()==0){
+            SysConfDO sysConfDO = new SysConfDO();
+            sysConfDO.setCode("ELDER_AUTH_TYPE");
+            sysConfDO.setName("高龄认证类型");
+            sysConfDO.setValue(2+"");//核验类型(1.视频认证 2.人脸核验)
+            sysConfDO.setDescription("高龄认证默认添加的核验类型");
+            sysConfDO.setCommunityId(communityId);
+            sysConfDO.setCreateBy(eldersAuthTypeQueryDTO.getUserId());
+            int inserted = sysConfDao.insert(sysConfDO);
+            if(inserted!=1){
+                throw new ServiceException("添加高龄认证默认添加的核验类型失败");
+            }
+            confDOList =
+                    sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>().eq(SysConfDO::getCommunityId, eldersAuthTypeQueryDTO.getOperUserId())
+                            .orderByDesc(SysConfDO::getCreateAt));
+        }
+        if(confDOList!=null && confDOList.size()>0){
+            SysConfDO  latest = confDOList.get(0);
+            SysConfVO sysConfVO = new SysConfVO();
+            BeanUtils.copyProperties(latest, sysConfVO);
+            return R.ok(sysConfVO.getValue());
+        }
+        return R.ok();
+    }
+
+    /**
+     * 人脸核验新增高龄认证记录
+     * @param authGetResultDTO  请求参数
+     * @return  新增结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R addAuthByEldersApp(ComEldersAuthGetResultDTO authGetResultDTO) throws Exception{
+        ComEldersAuthUserDO authUserDO = comEldersAuthUserMapper.selectById(authGetResultDTO.getAuthUserId());
+        if(authUserDO != null){
+            String idCard = authUserDO.getIdCard();
+            EldersAuthDO eldersAuthDO = new EldersAuthDO();
+            eldersAuthDO.setIdCard(idCard);
+            eldersAuthDO.setAuthUserName(authUserDO.getName());
+            eldersAuthDO.setCreateBy(authGetResultDTO.getUserId());
+            eldersAuthDO.setCreateAt(new Date());
+            eldersAuthDO.setSumitUserId(authGetResultDTO.getUserId());
+            String domicile = this.baseMapper.selectDomicile(idCard);
+            if(org.springframework.util.StringUtils.isEmpty(domicile)){
+                domicile = "暂无";
+            }
+            eldersAuthDO.setDomicile(domicile);
+            eldersAuthDO.setBirthDay(IdcardUtil.getBirthDate(idCard));
+            eldersAuthDO.setFamilyUserId(authUserDO.getId());
+            Integer age = IdcardUtil.getAgeByIdCard(idCard);
+
+            eldersAuthDO.setAge(age);
+            eldersAuthDO.setType(2);
+            eldersAuthDO.setVerificationResult(authGetResultDTO.getVerificationResult());
+
+            this.baseMapper.insert(eldersAuthDO);
+
+            //认证成功  添加认证记录
+            List<ComEldersAuthHistoryRecordDO> authHistoryRecordDOList = comEldersAuthHistoryRecordMapper.selectList(new QueryWrapper<ComEldersAuthHistoryRecordDO>()
+                    .lambda().eq(ComEldersAuthHistoryRecordDO::getIdCard,eldersAuthDO.getIdCard()).ge(ComEldersAuthHistoryRecordDO::getCreateAt, DateUtils.getFirstDayOfMonth()));
+            if(authHistoryRecordDOList.isEmpty()){
+                ComEldersAuthHistoryRecordDO authHistoryRecordDO = new ComEldersAuthHistoryRecordDO();
+                authHistoryRecordDO.setUserId(authGetResultDTO.getAuthUserId());
+                authHistoryRecordDO.setAuthId(eldersAuthDO.getId());
+                BeanUtils.copyProperties(eldersAuthDO,authHistoryRecordDO);
+                authHistoryRecordDO.setId(null);
+                authHistoryRecordDO.setBrithday(AgeUtils.getAgeFormatBirthday(IdcardUtil.getBirthByIdCard(idCard)));
+                authHistoryRecordDO.setAge(age);
+                authHistoryRecordDO.setIsAuth(1);
+                authHistoryRecordDO.setDomicile(domicile);
+                comEldersAuthHistoryRecordMapper.insert(authHistoryRecordDO);
+            }
+
+            authUserDO.setIsAuth(ComEldersAuthUserDO.isAuth.yes);
+            authUserDO.setIdCard(AESUtil.encrypt128(authUserDO.getIdCard(), aesKey));
+            comEldersAuthUserMapper.updateById(authUserDO);
+
+            return R.ok(eldersAuthDO.getId());
+        }
+        log.error("人脸核验新增认证记录失败,错误原因:未查询到老人记录,老人id:" + authGetResultDTO.getAuthUserId());
+        return R.fail();
+    }
+
+    /**
+     * 高龄认证分页接口
+     * @param authPageDTO   请求参数
+     * @return  查询结果
+     */
+    @Override
+    public R pageEldersByApp(ComEldersAuthPageDTO authPageDTO) throws Exception{
+        //判断当前用户是否是高龄老人,如果是则将这个人新增到高龄老人的列表里
+        SysUserVO userVO = this.eldersAuthDAO.getSysUserByUserId(authPageDTO.getUserId());
+        if(userVO != null){
+            String idCard = userVO.getIdCard();
+            userVO.setIdCard(AESUtil.encrypt128(userVO.getIdCard(), aesKey));
+            //查询当前用户是否已存在用户关联中
+            ComEldersAuthUserDO oldAuthUserDO = comEldersAuthUserMapper.selectOne(new QueryWrapper<ComEldersAuthUserDO>().lambda()
+                    .eq(ComEldersAuthUserDO::getIdCard, userVO.getIdCard()));
+            if(oldAuthUserDO == null){
+                //查询老人库是否存在当前用户信息
+                ComEldersAuthElderlyDO authElderlyDO = comEldersAuthElderlyMapper.selectOne(new QueryWrapper<ComEldersAuthElderlyDO>().lambda()
+                        .eq(ComEldersAuthElderlyDO::getIdCard,userVO.getIdCard()));
+                if(authElderlyDO != null){
+                    ComEldersAuthUserDO authUserDO = new ComEldersAuthUserDO();
+                    authUserDO.setUserId(userVO.getUserId());
+                    authUserDO.setRelation(ComEldersAuthUserDO.relation.br);
+                    authUserDO.setName(userVO.getName());
+                    authUserDO.setIdCard(idCard);
+                    authUserDO.setCommunityId(authElderlyDO.getCommunityId());
+                    authUserDO.setBigAgeId(authElderlyDO.getId());
+                    comEldersAuthUserMapper.insert(authUserDO);
+                }
+            }
+        }
+
+        IPage<ComElderAuthUserAppVO> authUserAppVOIPage = comEldersAuthUserMapper.findByPage(new Page(authPageDTO.getPageNum(),authPageDTO.getPageSize()),authPageDTO.getUserId());
+        if(!authUserAppVOIPage.getRecords().isEmpty()){
+            authUserAppVOIPage.getRecords().forEach(authUser -> {
+
+                if(authUser.getIsAuth().equals(ComEldersAuthUserDO.isAuth.yes)){
+                    List<EldersAuthDO> authDOS = eldersAuthDAO.selectList(new QueryWrapper<EldersAuthDO>().lambda()
+                            .eq(EldersAuthDO::getSumitUserId,authPageDTO.getUserId()).orderByDesc(EldersAuthDO::getCreateAt));
+                    if(!authDOS.isEmpty()){
+                        EldersAuthDO authDO = authDOS.get(0);
+                        if(authDO.getType().equals(1)){//视频认证
+                            Integer count = eldersAuthFeedbackDAO.selectCount(new QueryWrapper<EldersAuthFeedbackDO>().lambda()
+                                    .eq(EldersAuthFeedbackDO::getAuthId,authDO.getId()));
+                            if(count > 0){
+                                authUser.setIsFeedback(1);
+                            }
+                        }
+                    }
+                }
+
+                ComEldersAuthUserDO authUserDO = comEldersAuthUserMapper.selectById(authUser.getElderId());
+                if(authUserDO != null){
+                    try {
+                        authUser.setAge(IdcardUtil.getAgeByIdCard(authUserDO.getIdCard()));
+                    }catch (NullPointerException e){
+                        log.error("获取用户年龄出错了:" + authUser.getIdCard());
+                    }
+                }
+            });
+        }
+        return R.ok(authUserAppVOIPage);
+    }
+
+    /**
+     * 添加高龄老人接口
+     * @param authUserAddAppDTO 请求参数
+     * @return  添加结果
+     */
+    @Override
+    public R addEldersByApp(ComEldersAuthUserAddAppDTO authUserAddAppDTO){
+
+        ComEldersAuthUserDO authUserDO = comEldersAuthUserMapper.selectOne(new QueryWrapper<ComEldersAuthUserDO>().lambda()
+                .eq(ComEldersAuthUserDO::getIdCard,authUserAddAppDTO.getIdCard()));
+        if(authUserDO != null){
+            return R.fail("当前老人已存在");
+        }
+
+        String encryptedIdCard =authUserAddAppDTO.getIdCard();
+        try {
+            encryptedIdCard =  AESUtil.encrypt128(authUserAddAppDTO.getIdCard(), aesKey);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        ComEldersAuthElderlyDO authElderlyDO = comEldersAuthElderlyMapper.selectOne(new QueryWrapper<ComEldersAuthElderlyDO>().lambda()
+                .eq(ComEldersAuthElderlyDO::getIdCard, encryptedIdCard));
+        if(authElderlyDO == null){
+            return R.fail("未在系统找到相符的高龄老人!请检查信息是否正确,或联系社区工作人员");
+        }
+
+        authUserDO = new ComEldersAuthUserDO();
+        BeanUtils.copyProperties(authUserAddAppDTO,authUserDO);
+        authUserDO.setBigAgeId(authElderlyDO.getId());
+        authUserDO.setName(authElderlyDO.getName());
+        if(comEldersAuthUserMapper.insert(authUserDO) > 0){
+            return R.ok(authUserDO.getId());
+        }
+
+        return R.fail("添加失败");
+    }
+
+    /**
+     * 修改高龄老人接口
+     * @param authUserAddAppDTO 请求参数
+     * @return  修改结果
+     */
+    @Override
+    public R editEldersByApp(ComEldersAuthUserAddAppDTO authUserAddAppDTO){
+
+        ComEldersAuthUserDO authUserDO = comEldersAuthUserMapper.selectById(authUserAddAppDTO.getElderId());
+        if(authUserDO == null){
+            return R.fail("未查询到老人信息");
+        }
+        if(StringUtils.isNotEmpty(authUserAddAppDTO.getName())){
+            authUserDO.setName(authUserAddAppDTO.getName());
+        }
+        if(authUserAddAppDTO.getRelation() != null){
+            authUserDO.setRelation(authUserAddAppDTO.getRelation());
+        }
+        if(comEldersAuthUserMapper.updateById(authUserDO) > 0){
+            return R.ok();
+        }
+        return R.fail();
+    }
+
+    @Override
+    public R pageQueryEldersAuthRecord(PageEldersAuthRecordDTO pageEldersAuthElderlyDTO) {
+        Page page = new Page();
+        page.setCurrent(pageEldersAuthElderlyDTO.getPageNum());
+        page.setSize(pageEldersAuthElderlyDTO.getPageSize());
+        IPage<ComEldersAuthRecordForCommunityVO> ipage = eldersAuthDAO.selectCommunityEldersRecordByPage(page, pageEldersAuthElderlyDTO);
+        return R.ok(ipage);
+    }
+    @Override
+    public R setCommunityAuthType(Long communityId, Integer type) {
+        List<SysConfDO> authConf =
+                sysConfDao.selectList(new LambdaQueryWrapper<SysConfDO>()
+                        .eq(SysConfDO::getCommunityId, communityId)
+                        .eq(SysConfDO::getCode, "ELDER_AUTH_TYPE")
+                        .orderByDesc(SysConfDO::getCreateAt));
+        if(authConf!=null && authConf.size()>0){
+            SysConfDO first = authConf.get(0);
+            first.setValue(type+"");
+            int updated = sysConfDao.updateById(first);
+            if(updated == 1){
+                return R.ok();
+            }
+        }
+        return R.fail();
+    }
+
+    @Override
+    public R getAuthHistoryList(PageEldersAuthHistoryDTO pageEldersAuthElderlyDTO){
+        return R.ok(comEldersAuthStatisticsMapper.findByPage(new Page(pageEldersAuthElderlyDTO.getPageNum(),pageEldersAuthElderlyDTO.getPageSize()),pageEldersAuthElderlyDTO));
+    }
+
+    public R getAuthHistoryExport(PageEldersAuthHistoryDTO pageEldersAuthElderlyDTO){
+        Date startTime = DateUtils.getYearMonthStart(pageEldersAuthElderlyDTO.getYear(),pageEldersAuthElderlyDTO.getMonth());
+        Date endTime = DateUtils.getYearMonthEnd(pageEldersAuthElderlyDTO.getYear(),pageEldersAuthElderlyDTO.getMonth());
+
+        List<ComEldersAuthHistoryRecordDO> userList = comEldersAuthHistoryRecordMapper.selectList(new QueryWrapper<ComEldersAuthHistoryRecordDO>().lambda()
+                .eq(ComEldersAuthHistoryRecordDO::getCommunityId,pageEldersAuthElderlyDTO.getCommunityId())
+                .ge(ComEldersAuthHistoryRecordDO::getCreateAt,startTime).le(ComEldersAuthHistoryRecordDO::getCreateAt,endTime));
+
+        List<ComEldersAuthHistoryExcelVO> authHistoryExcelVOS = new ArrayList<>();
+        userList.forEach(user -> {
+            ComEldersAuthHistoryExcelVO authHistoryExcelVO = new ComEldersAuthHistoryExcelVO();
+            BeanUtils.copyProperties(user,authHistoryExcelVO);
+            authHistoryExcelVOS.add(authHistoryExcelVO);
+        });
+        return R.ok(authHistoryExcelVOS);
+    }
 }

--
Gitblit v1.7.1