ResidentInfoServiceImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.ruoyi.system.service.impl;
  2. import com.ruoyi.common.constant.UserConstants;
  3. import com.ruoyi.common.core.domain.AjaxResult;
  4. import com.ruoyi.common.core.domain.entity.SysRole;
  5. import com.ruoyi.common.core.domain.entity.SysUser;
  6. import com.ruoyi.common.utils.DateUtils;
  7. import com.ruoyi.common.core.domain.entity.ResidentInfo;
  8. import com.ruoyi.common.utils.SecurityUtils;
  9. import com.ruoyi.system.mapper.ResidentInfoMapper;
  10. import com.ruoyi.system.mapper.SysRoleMapper;
  11. import com.ruoyi.system.service.IResidentInfoService;
  12. import com.ruoyi.system.service.ISysDictDataService;
  13. import com.ruoyi.system.service.ISysUserService;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import java.util.List;
  17. /**
  18. * 居住人员信息,存储居住人员的详细信息Service业务层处理
  19. *
  20. * @author boman
  21. * @date 2025-02-20
  22. */
  23. @Service
  24. public class ResidentInfoServiceImpl implements IResidentInfoService
  25. {
  26. @Autowired
  27. private ResidentInfoMapper residentInfoMapper;
  28. @Autowired
  29. private SysRoleMapper roleMapper;
  30. @Autowired
  31. private ISysUserService userService;
  32. @Autowired
  33. private ISysDictDataService dictDataService;
  34. /**
  35. * 查询居住人员信息,存储居住人员的详细信息
  36. *
  37. * @param residentId 居住人员信息,存储居住人员的详细信息主键
  38. * @return 居住人员信息,存储居住人员的详细信息
  39. */
  40. @Override
  41. public ResidentInfo selectResidentInfoByResidentId(Long residentId)
  42. {
  43. return residentInfoMapper.selectResidentInfoByResidentId(residentId);
  44. }
  45. /**
  46. * 查询居住人员信息,存储居住人员的详细信息列表
  47. *
  48. * @param residentInfo 居住人员信息,存储居住人员的详细信息
  49. * @return 居住人员信息,存储居住人员的详细信息
  50. */
  51. @Override
  52. public List<ResidentInfo> selectResidentInfoList(ResidentInfo residentInfo)
  53. {
  54. //todo 计算每个人的年龄
  55. return residentInfoMapper.selectResidentInfoList(residentInfo);
  56. }
  57. /**
  58. * 新增居住人员信息,存储居住人员的详细信息
  59. *
  60. * @param residentInfo 居住人员信息,存储居住人员的详细信息
  61. * @return 结果
  62. */
  63. @Override
  64. public AjaxResult insertResidentInfo(ResidentInfo residentInfo)
  65. {
  66. //新增账号信息
  67. SysUser user = new SysUser();
  68. user.setUserName(residentInfo.getResidentPhone());
  69. if (!userService.checkUserNameUnique(user))
  70. {
  71. return AjaxResult.error(user.getUserName() + "'失败,手机号已存在");
  72. }
  73. user.setPassword(SecurityUtils.encryptPassword(UserConstants.PASSWORD));
  74. user.setPhonenumber(residentInfo.getResidentPhone());
  75. user.setNickName(residentInfo.getResidentName());
  76. //todo 部门 岗位
  77. user.setSex(String.valueOf(residentInfo.getResidentGender()-1));
  78. user.setStatus(UserConstants.DEPT_NORMAL);
  79. //查询角色id
  80. Long[] roleIds = {6L};
  81. user.setRoleIds(roleIds);
  82. userService.insertUser(user);
  83. residentInfo.setCreateTime(DateUtils.getNowDate());
  84. int i = residentInfoMapper.insertResidentInfo(residentInfo);
  85. return i > 0 ? AjaxResult.success() : AjaxResult.error();
  86. }
  87. /**
  88. * 修改居住人员信息,存储居住人员的详细信息
  89. *
  90. * @param residentInfo 居住人员信息,存储居住人员的详细信息
  91. * @return 结果
  92. */
  93. @Override
  94. public int updateResidentInfo(ResidentInfo residentInfo)
  95. {
  96. residentInfo.setUpdateTime(DateUtils.getNowDate());
  97. return residentInfoMapper.updateResidentInfo(residentInfo);
  98. }
  99. /**
  100. * 批量删除居住人员信息,存储居住人员的详细信息
  101. *
  102. * @param residentIds 需要删除的居住人员信息,存储居住人员的详细信息主键
  103. * @return 结果
  104. */
  105. @Override
  106. public int deleteResidentInfoByResidentIds(Long[] residentIds)
  107. {
  108. return residentInfoMapper.deleteResidentInfoByResidentIds(residentIds);
  109. }
  110. /**
  111. * 删除居住人员信息,存储居住人员的详细信息信息
  112. *
  113. * @param residentId 居住人员信息,存储居住人员的详细信息主键
  114. * @return 结果
  115. */
  116. @Override
  117. public int deleteResidentInfoByResidentId(Long residentId)
  118. {
  119. return residentInfoMapper.deleteResidentInfoByResidentId(residentId);
  120. }
  121. /**
  122. * 根据userId查询居住人员信息
  123. * @param userId
  124. * @return
  125. */
  126. @Override
  127. public ResidentInfo selectResidentInfoByUserId(Long userId) {
  128. return residentInfoMapper.selectResidentInfoByUserId(userId);
  129. }
  130. }