ResidentInfoServiceImpl.java 4.7 KB

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