CeDo
2021-05-19 0d248bc79c25c38dbdbda49dbcb5a6595cbca379
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
package com.panzhihua.service_community.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.vaccines.EnrollUserByAppDTO;
import com.panzhihua.common.model.dtos.vaccines.VaccinesEnrollByAdminDTO;
import com.panzhihua.common.model.dtos.vaccines.VaccinesEnrollByAppDTO;
import com.panzhihua.common.model.dtos.vaccines.VaccinesEnrollUserByAppDTO;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.vaccines.VaccinesEnrollByAdminVO;
import com.panzhihua.common.model.vos.vaccines.VaccinesEnrollUserByAppVO;
import com.panzhihua.common.utlis.AgeUtils;
import com.panzhihua.common.utlis.IdCard;
import com.panzhihua.service_community.dao.ComMngVaccinesDAO;
import com.panzhihua.service_community.dao.ComMngVaccinesEnrollRecordDAO;
import com.panzhihua.service_community.model.dos.ComMngVaccinesDO;
import com.panzhihua.service_community.model.dos.ComMngVaccinesEnrollRecordDO;
import com.panzhihua.service_community.service.ComMngVaccinesEnrollRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @auther lyq
 * @create 2021-05-19 14:17:53
 * @describe 疫苗报名记录表服务实现类
 */
@Slf4j
@Service
public class ComMngVaccinesEnrollRecordServiceImpl extends ServiceImpl<ComMngVaccinesEnrollRecordDAO, ComMngVaccinesEnrollRecordDO> implements ComMngVaccinesEnrollRecordService {
 
    @Resource
    private ComMngVaccinesDAO comMngVaccinesDAO;
 
    /**
     * 小程序-疫苗类型对应家庭成员接种列表
     * @return  疫苗类型对应家庭成员接种列表
     */
    @Override
    public R getVaccinesUserListByApp(VaccinesEnrollUserByAppDTO enrollUserByAppDTO){
        //查询当前用户的家庭成员列表
        List<VaccinesEnrollUserByAppVO> userLists = new ArrayList<>();
        //将自己的信息组装进家庭成员列表中
        VaccinesEnrollUserByAppVO ownUser = this.baseMapper.getSysUser(enrollUserByAppDTO.getUserId());
        if(ownUser != null){
            ownUser.setIsUser(1);
            //计算年龄
            ownUser.setAge(IdCard.IdNOToAge(ownUser.getIdCard()));
            userLists.add(ownUser);
        }
        List<VaccinesEnrollUserByAppVO> userList = this.baseMapper.getFamilyUserList(enrollUserByAppDTO.getUserId());
        if(!userList.isEmpty()){
            userLists.addAll(userList);
        }
 
        if(!userLists.isEmpty()){
            userLists.forEach(user -> {
                if(user.getIsUser() == null){
                    user.setIsUser(2);
                }
                //查询当前用户是否已经报名
                ComMngVaccinesEnrollRecordDO enrollRecordDO = this.baseMapper.selectOne(new QueryWrapper<ComMngVaccinesEnrollRecordDO>()
                        .lambda().eq(ComMngVaccinesEnrollRecordDO::getFamilyUserId,user.getUserId()).eq(ComMngVaccinesEnrollRecordDO::getType,enrollUserByAppDTO.getVaccinesId()));
                if(enrollRecordDO != null){
                    user.setIsEnroll(VaccinesEnrollUserByAppVO.isEnroll.yes);
                }else{
                    user.setIsEnroll(VaccinesEnrollUserByAppVO.isEnroll.no);
                }
 
            });
        }
        return R.ok(userLists);
    }
 
    /**
     * 用户疫苗报名
     * @param enrollByAppDTO    请求参数
     * @return  报名结果
     */
    @Override
    public R VaccinesEnrollByApp(VaccinesEnrollByAppDTO enrollByAppDTO){
        //查询疫苗信息
        ComMngVaccinesDO vaccinesDO = comMngVaccinesDAO.selectById(enrollByAppDTO.getVaccinesId());
        if(vaccinesDO == null){
            return R.fail("未找到到疫苗信息");
        }
        List<ComMngVaccinesEnrollRecordDO> vaccinesEnrollRecordDOList = new ArrayList<>();
        if(!enrollByAppDTO.getEnrollUserList().isEmpty()){
            for (EnrollUserByAppDTO userByAppDTO:enrollByAppDTO.getEnrollUserList()) {
                ComMngVaccinesEnrollRecordDO enrollRecordDO = this.baseMapper.selectOne(new QueryWrapper<ComMngVaccinesEnrollRecordDO>()
                        .lambda().eq(ComMngVaccinesEnrollRecordDO::getFamilyUserType,userByAppDTO.getIsUser())
                        .eq(ComMngVaccinesEnrollRecordDO::getFamilyUserId,userByAppDTO.getUserId())
                        .eq(ComMngVaccinesEnrollRecordDO::getUserId,enrollByAppDTO.getUserId())
                        .eq(ComMngVaccinesEnrollRecordDO::getType,enrollByAppDTO.getVaccinesId()));
                if(enrollRecordDO != null){
                    continue;
                }
                //报名疫苗填充对象
                ComMngVaccinesEnrollRecordDO vaccinesEnrollRecordDO = new ComMngVaccinesEnrollRecordDO();
                if(userByAppDTO.getIsUser().equals(EnrollUserByAppDTO.isUser.yes)){
                    vaccinesEnrollRecordDO.setFamilyUserType(ComMngVaccinesEnrollRecordDO.familyUserType.mini);
                }
                vaccinesEnrollRecordDO.setUserId(enrollByAppDTO.getUserId());
                vaccinesEnrollRecordDO.setFamilyUserId(userByAppDTO.getUserId());
                vaccinesEnrollRecordDO.setType(enrollByAppDTO.getVaccinesId());
                vaccinesEnrollRecordDOList.add(vaccinesEnrollRecordDO);
            }
        }
        if(!vaccinesEnrollRecordDOList.isEmpty()){
            this.saveBatch(vaccinesEnrollRecordDOList);
        }
        return R.ok();
    }
 
    /**
     * 查询疫苗登记列表
     * @param vaccinesByAdminDTO 请求参数
     * @return  登记列表
     */
    public R getVaccinesEnrollListByAdmin(VaccinesEnrollByAdminDTO vaccinesByAdminDTO){
        return R.ok(this.baseMapper.getVaccinesEnrollListByAdmin(new Page<VaccinesEnrollByAdminVO>(vaccinesByAdminDTO.getPageNum(),vaccinesByAdminDTO.getPageSize()),vaccinesByAdminDTO));
    }
}