| | |
| | | package com.ruoyi.service.impl; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.domain.MarryUser; |
| | | import com.ruoyi.domain.ZMarry; |
| | | import com.ruoyi.domain.dto.MarryInfoDto; |
| | | import com.ruoyi.mapper.ZMarryMapper; |
| | | import com.ruoyi.service.MarryUserService; |
| | | import com.ruoyi.service.ZMarryService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | | * 服务实现类 |
| | | * 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author ojq |
| | |
| | | @Service |
| | | public class ZMarryServiceImpl extends ServiceImpl<ZMarryMapper, ZMarry> implements ZMarryService { |
| | | |
| | | @Resource |
| | | MarryUserService marryUserService; |
| | | |
| | | @Autowired |
| | | ZMarryServiceImpl zMarryService; |
| | | |
| | | @Override |
| | | public AjaxResult getNow() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | //先查询个人信息 |
| | | LambdaQueryWrapper<MarryUser> marryUserLambdaQueryWrapper1 = new LambdaQueryWrapper<>(); |
| | | marryUserLambdaQueryWrapper1.eq(MarryUser::getMyId, userId); |
| | | MarryUser myself = marryUserService.getOne(marryUserLambdaQueryWrapper1); |
| | | |
| | | //再查询中间表信息 |
| | | if (myself == null) { |
| | | throw new RuntimeException("您暂时还未在婚姻表中添加个人信息"); |
| | | } |
| | | LambdaQueryWrapper<ZMarry> zMarryLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | zMarryLambdaQueryWrapper.eq(ZMarry::getUserId, myself.getMyId()) |
| | | .eq(ZMarry::getDeleteStatus, 0); |
| | | ZMarry myMarryInfo = getOne(zMarryLambdaQueryWrapper);//只能有一个配偶 |
| | | |
| | | //根据中间表信息查询配偶信息 |
| | | if (myMarryInfo == null) { |
| | | throw new RuntimeException("您暂时还未在婚姻表中添加婚姻信息"); |
| | | } |
| | | String spouseId = myMarryInfo.getSpouseId(); |
| | | LambdaQueryWrapper<MarryUser> marryUserLambdaQueryWrapper2 = new LambdaQueryWrapper<>(); |
| | | marryUserLambdaQueryWrapper2.eq(MarryUser::getId, spouseId); |
| | | MarryUser spouse = marryUserService.getOne(marryUserLambdaQueryWrapper2); |
| | | if (spouse == null) { |
| | | throw new RuntimeException("您暂时还未在婚姻表中添加配偶信息"); |
| | | } |
| | | |
| | | //根据中间表信息查询前任信息 |
| | | LambdaQueryWrapper<ZMarry> zMarryOldLQW = new LambdaQueryWrapper<>(); |
| | | zMarryOldLQW.eq(ZMarry::getUserId,myself.getMyId()) |
| | | .eq(ZMarry::getDeleteStatus,1); |
| | | List<ZMarry> oldList = list(zMarryOldLQW); |
| | | |
| | | //前任信息表 |
| | | List<MarryUser> oldSpouseList = new ArrayList<>(); |
| | | for (ZMarry zMarry : oldList) { |
| | | String spouseId1 = zMarry.getSpouseId(); |
| | | MarryUser oldSpouse = marryUserService.getById(spouseId1); |
| | | oldSpouseList.add(oldSpouse); |
| | | } |
| | | |
| | | //统一封装返回 |
| | | HashMap<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("myInfo",myself); |
| | | resultMap.put("spouseInfo",spouse); |
| | | resultMap.put("marryInfo",myMarryInfo); |
| | | resultMap.put("oldSpouseInfo",oldSpouseList); |
| | | |
| | | return AjaxResult.success(resultMap); |
| | | } |
| | | |
| | | @Transactional |
| | | public AjaxResult addInfo(MarryInfoDto marryInfoDto){ |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | |
| | | String meId= IdUtils.simpleUUID(); |
| | | String spouseId = IdUtils.simpleUUID(); |
| | | |
| | | //添加自己的信息 |
| | | MarryUser myself = new MarryUser(); |
| | | myself.setId(meId); |
| | | myself.setName(marryInfoDto.getName()); |
| | | myself.setBirthday(marryInfoDto.getBirthday()); |
| | | myself.setAddress(marryInfoDto.getAddress()); |
| | | myself.setWorkAddress(marryInfoDto.getWorkAddress()); |
| | | myself.setMarryStatus(marryInfoDto.getMarryStatus()); |
| | | myself.setSex(marryInfoDto.getSex()); |
| | | myself.setMyId(userId); |
| | | myself.setNation(marryInfoDto.getNation()); |
| | | myself.setPhone(marryInfoDto.getPhone()); |
| | | marryUserService.save(myself); |
| | | |
| | | //添加配偶的信息 |
| | | MarryUser spouse = new MarryUser(); |
| | | spouse.setId(spouseId); |
| | | spouse.setName(marryInfoDto.getSpouseName()); |
| | | spouse.setBirthday(marryInfoDto.getSpouseBirthday()); |
| | | spouse.setAddress(marryInfoDto.getSpouseAddress()); |
| | | spouse.setWorkAddress(marryInfoDto.getSpouseWorkAddress()); |
| | | spouse.setMarryStatus(marryInfoDto.getSpouseMarryStatus()); |
| | | spouse.setSex(marryInfoDto.getSpouseSex()); |
| | | spouse.setNation(marryInfoDto.getSpouseNation()); |
| | | spouse.setPhone(marryInfoDto.getSpousePhone()); |
| | | marryUserService.save(spouse); |
| | | |
| | | //添加生育情况(中间表)信息 |
| | | ZMarry zMarry = new ZMarry(); |
| | | zMarry.setUserId(userId); |
| | | zMarry.setSpouseId(spouseId); |
| | | zMarry.setMarryTime(marryInfoDto.getMarryTime()); |
| | | zMarry.setBearStatus(marryInfoDto.getBearStatus()); |
| | | zMarry.setHandbookStatus(marryInfoDto.getHandbookStatus()); |
| | | zMarry.setHandbookTime(marryInfoDto.getHandbookTime()); |
| | | zMarry.setOneBorn(marryInfoDto.getOneBorn()); |
| | | zMarry.setOneBornTime(marryInfoDto.getOneBornTime()); |
| | | zMarry.setContent(marryInfoDto.getContent()); |
| | | zMarry.setRemark(marryInfoDto.getRemark()); |
| | | zMarry.setDeleteStatus(0); |
| | | zMarryService.save(zMarry); |
| | | |
| | | |
| | | List<MarryUser> oldSpouseList = marryInfoDto.getOldSpouseList(); |
| | | |
| | | //添加前任的信息 |
| | | if(oldSpouseList!=null&&oldSpouseList.size()!=0){ |
| | | for (MarryUser marryUser : oldSpouseList) { |
| | | //先添加配偶用户信息 |
| | | String spId = IdUtils.simpleUUID(); |
| | | marryUser.setId(spId); |
| | | marryUserService.save(marryUser); |
| | | |
| | | //再添加中间表信息 |
| | | ZMarry oldMarry = new ZMarry(); |
| | | oldMarry.setUserId(userId); |
| | | oldMarry.setSpouseId(spId); |
| | | oldMarry.setDeleteStatus(1); |
| | | zMarryService.save(oldMarry); |
| | | } |
| | | } |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | @Transactional |
| | | public AjaxResult updateInfo(MarryInfoDto marryInfoDto){ |
| | | |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | Long userId = user.getUserId(); |
| | | //更新自己的信息 |
| | | MarryUser myself = new MarryUser(); |
| | | myself.setId(marryInfoDto.getId()); |
| | | myself.setName(marryInfoDto.getName()); |
| | | myself.setBirthday(marryInfoDto.getBirthday()); |
| | | myself.setAddress(marryInfoDto.getAddress()); |
| | | myself.setWorkAddress(marryInfoDto.getWorkAddress()); |
| | | myself.setMarryStatus(marryInfoDto.getMarryStatus()); |
| | | myself.setSex(marryInfoDto.getSex()); |
| | | myself.setNation(marryInfoDto.getNation()); |
| | | myself.setPhone(marryInfoDto.getPhone()); |
| | | marryUserService.updateById(myself); |
| | | |
| | | //更新配偶的信息 |
| | | |
| | | //先查询是更新配偶信息还是换配偶,因为配偶只能有一个 |
| | | //这里暂时用名字来判断吧,如果有重名的人就会有bug |
| | | //先查询 |
| | | String spouseName = marryInfoDto.getSpouseName(); |
| | | MarryUser marry = marryUserService.getById(marryInfoDto.getSpouseId()); |
| | | String marryName = marry.getName(); |
| | | if(!spouseName.equals(marryName)){ |
| | | |
| | | //如果正妻子换人了,就新增而不是修改,同时删除旧纪录 |
| | | //将现在中间表的妻子改成前妻 |
| | | LambdaQueryWrapper<ZMarry> lqw = new LambdaQueryWrapper<>(); |
| | | lqw.eq(ZMarry::getUserId,userId) |
| | | .eq(ZMarry::getSpouseId,marryInfoDto.getSpouseId()); |
| | | ZMarry one = getOne(lqw); |
| | | one.setDeleteStatus(1); |
| | | zMarryService.updateById(one); |
| | | |
| | | //新增用户信息表 |
| | | String spouseId = IdUtils.simpleUUID(); |
| | | MarryUser spouse = new MarryUser(); |
| | | spouse.setId(spouseId); |
| | | spouse.setName(marryInfoDto.getSpouseName()); |
| | | spouse.setBirthday(marryInfoDto.getSpouseBirthday()); |
| | | spouse.setAddress(marryInfoDto.getSpouseAddress()); |
| | | spouse.setWorkAddress(marryInfoDto.getSpouseWorkAddress()); |
| | | spouse.setMarryStatus(marryInfoDto.getSpouseMarryStatus()); |
| | | spouse.setSex(marryInfoDto.getSpouseSex()); |
| | | spouse.setNation(marryInfoDto.getSpouseNation()); |
| | | spouse.setPhone(marryInfoDto.getSpousePhone()); |
| | | marryUserService.save(spouse); |
| | | |
| | | //新增中间表 |
| | | //添加生育情况(中间表)信息 |
| | | ZMarry zMarry = new ZMarry(); |
| | | zMarry.setUserId(userId); |
| | | zMarry.setSpouseId(spouseId); |
| | | zMarry.setMarryTime(marryInfoDto.getMarryTime()); |
| | | zMarry.setBearStatus(marryInfoDto.getBearStatus()); |
| | | zMarry.setHandbookStatus(marryInfoDto.getHandbookStatus()); |
| | | zMarry.setHandbookTime(marryInfoDto.getHandbookTime()); |
| | | zMarry.setOneBorn(marryInfoDto.getOneBorn()); |
| | | zMarry.setOneBornTime(marryInfoDto.getOneBornTime()); |
| | | zMarry.setContent(marryInfoDto.getContent()); |
| | | zMarry.setRemark(marryInfoDto.getRemark()); |
| | | zMarry.setDeleteStatus(0); |
| | | zMarryService.save(zMarry); |
| | | |
| | | |
| | | |
| | | }else { |
| | | |
| | | MarryUser spouse = new MarryUser(); |
| | | spouse.setId(marryInfoDto.getSpouseId()); |
| | | spouse.setName(marryInfoDto.getSpouseName()); |
| | | spouse.setBirthday(marryInfoDto.getSpouseBirthday()); |
| | | spouse.setAddress(marryInfoDto.getSpouseAddress()); |
| | | spouse.setWorkAddress(marryInfoDto.getSpouseWorkAddress()); |
| | | spouse.setMarryStatus(marryInfoDto.getSpouseMarryStatus()); |
| | | spouse.setSex(marryInfoDto.getSpouseSex()); |
| | | spouse.setNation(marryInfoDto.getSpouseNation()); |
| | | spouse.setPhone(marryInfoDto.getSpousePhone()); |
| | | marryUserService.updateById(spouse); |
| | | |
| | | //更新生育情况信息 |
| | | ZMarry zMarry = new ZMarry(); |
| | | zMarry.setId(marryInfoDto.getMarryId()); |
| | | zMarry.setMarryTime(marryInfoDto.getMarryTime()); |
| | | zMarry.setBearStatus(marryInfoDto.getBearStatus()); |
| | | zMarry.setHandbookStatus(marryInfoDto.getHandbookStatus()); |
| | | zMarry.setHandbookTime(marryInfoDto.getHandbookTime()); |
| | | zMarry.setOneBorn(marryInfoDto.getOneBorn()); |
| | | zMarry.setOneBornTime(marryInfoDto.getOneBornTime()); |
| | | zMarry.setContent(marryInfoDto.getContent()); |
| | | zMarry.setRemark(marryInfoDto.getRemark()); |
| | | zMarry.setDeleteStatus(0); |
| | | zMarryService.updateById(zMarry); |
| | | } |
| | | |
| | | //更新前任信息 |
| | | List<MarryUser> oldSpouseList = marryInfoDto.getOldSpouseList(); |
| | | if(oldSpouseList!=null&&oldSpouseList.size()!=0){ |
| | | for (MarryUser marryUser : oldSpouseList) { |
| | | //修改用户前任信息 |
| | | marryUserService.updateById(marryUser); |
| | | //中间表不需要修改 |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | public AjaxResult deleteOld(String spouseId){ |
| | | marryUserService.removeById(spouseId); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | } |