123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package com.care.client.service;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.care.client.vo.HouseContactVO;
- import com.care.common.entity.*;
- import com.care.common.enums.RelationTypeEnum;
- import com.care.common.service.*;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.compress.utils.Lists;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.Date;
- import java.util.List;
- /**
- * @Author: lilt
- * @Date: 2021/6/7
- * @Desc:
- */
- @Slf4j
- @Service
- public class PinanbaoContactService {
- @Resource
- private CareMemberInfoService careMemberInfoService;
- @Resource
- private CareHouseContactService careHouseContactService;
- /**
- * 查询紧急联系人
- * @param memberId
- * @return
- */
- public List<HouseContactVO> queryContactByMemberId(Long memberId){
- List<HouseContactVO> vos = Lists.newArrayList();
- QueryWrapper<CareHouseContact> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(CareHouseContact::getMemberId, memberId)
- .orderByAsc(CareHouseContact::getContactLevel);
- List<CareHouseContact> contacts = this.careHouseContactService.list(queryWrapper);
- if (CollUtil.isNotEmpty(contacts)){
- contacts.forEach(item -> {
- HouseContactVO vo = new HouseContactVO();
- BeanUtil.copyProperties(item,vo);
- vo.setRelationTypeDesc(RelationTypeEnum.getCodeToName(vo.getRelationType()));
- vo.setName(item.getContactName());
- vo.setPhone(item.getContactPhone());
- vos.add(vo);
- });
- }
- return vos;
- }
- /**
- * 新增紧急联系人
- * @param memberId
- * @return
- */
- @Transactional(rollbackFor = Exception.class)
- public Boolean createMyContact(Long memberId,HouseContactVO vo){
- //保存被监护人
- CareHouseContact careContact = new CareHouseContact();
- BeanUtil.copyProperties(vo,careContact);
- careContact.setMemberId(memberId);
- careContact.setCreateTime(new Date());
- return this.careHouseContactService.save(careContact);
- }
- /**
- * 查询紧急联系人详情
- * @param id
- * @return
- */
- public HouseContactVO getContactInfo(Long id){
- CareHouseContact careContact = this.careHouseContactService.getById(id);
- HouseContactVO vo = new HouseContactVO();
- BeanUtil.copyProperties(careContact,vo);
- vo.setRelationTypeDesc(RelationTypeEnum.getCodeToName(vo.getRelationType()));
- return vo;
- }
- /**
- * 修改紧急联系人
- * @param vo
- */
- @Transactional(rollbackFor = Exception.class)
- public Boolean updateMyContact(HouseContactVO vo){
- //修改紧急联系人
- CareHouseContact careContact = this.careHouseContactService.getById(vo.getId());
- BeanUtil.copyProperties(vo,careContact);
- careContact.setModifyTime(new Date());
- return this.careHouseContactService.updateById(careContact);
- }
- /**
- * 删除紧急联系人
- * @param id
- * @return
- */
- public boolean deleteById(Long id){
- return this.careHouseContactService.removeById(id);
- }
- }
|