123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- package com.ruoyi.system.service.impl;
- import com.ruoyi.common.constant.UserConstants;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.core.domain.entity.SysRole;
- import com.ruoyi.common.core.domain.entity.SysUser;
- import com.ruoyi.common.utils.DateUtils;
- import com.ruoyi.common.core.domain.entity.ResidentInfo;
- import com.ruoyi.common.utils.SecurityUtils;
- import com.ruoyi.system.mapper.ResidentInfoMapper;
- import com.ruoyi.system.mapper.SysRoleMapper;
- import com.ruoyi.system.service.IResidentInfoService;
- import com.ruoyi.system.service.ISysDictDataService;
- import com.ruoyi.system.service.ISysUserService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.List;
- /**
- * 居住人员信息,存储居住人员的详细信息Service业务层处理
- *
- * @author boman
- * @date 2025-02-20
- */
- @Service
- public class ResidentInfoServiceImpl implements IResidentInfoService
- {
- @Autowired
- private ResidentInfoMapper residentInfoMapper;
- @Autowired
- private SysRoleMapper roleMapper;
- @Autowired
- private ISysUserService userService;
- @Autowired
- private ISysDictDataService dictDataService;
- /**
- * 查询居住人员信息,存储居住人员的详细信息
- *
- * @param residentId 居住人员信息,存储居住人员的详细信息主键
- * @return 居住人员信息,存储居住人员的详细信息
- */
- @Override
- public ResidentInfo selectResidentInfoByResidentId(Long residentId)
- {
- return residentInfoMapper.selectResidentInfoByResidentId(residentId);
- }
- /**
- * 查询居住人员信息,存储居住人员的详细信息列表
- *
- * @param residentInfo 居住人员信息,存储居住人员的详细信息
- * @return 居住人员信息,存储居住人员的详细信息
- */
- @Override
- public List<ResidentInfo> selectResidentInfoList(ResidentInfo residentInfo)
- {
- //todo 计算每个人的年龄
- return residentInfoMapper.selectResidentInfoList(residentInfo);
- }
- /**
- * 新增居住人员信息,存储居住人员的详细信息
- *
- * @param residentInfo 居住人员信息,存储居住人员的详细信息
- * @return 结果
- */
- @Override
- public AjaxResult insertResidentInfo(ResidentInfo residentInfo)
- {
- //新增账号信息
- SysUser user = new SysUser();
- user.setUserName(residentInfo.getResidentPhone());
- if (!userService.checkUserNameUnique(user))
- {
- return AjaxResult.error(user.getUserName() + "'失败,手机号已存在");
- }
- user.setPassword(SecurityUtils.encryptPassword(UserConstants.PASSWORD));
- user.setPhonenumber(residentInfo.getResidentPhone());
- user.setNickName(residentInfo.getResidentName());
- //todo 部门 岗位
- user.setSex(String.valueOf(residentInfo.getResidentGender()-1));
- user.setStatus(UserConstants.DEPT_NORMAL);
- //查询角色id
- Long[] roleIds = {6L};
- user.setRoleIds(roleIds);
- userService.insertUser(user);
- residentInfo.setCreateTime(DateUtils.getNowDate());
- int i = residentInfoMapper.insertResidentInfo(residentInfo);
- return i > 0 ? AjaxResult.success() : AjaxResult.error();
- }
- /**
- * 修改居住人员信息,存储居住人员的详细信息
- *
- * @param residentInfo 居住人员信息,存储居住人员的详细信息
- * @return 结果
- */
- @Override
- public int updateResidentInfo(ResidentInfo residentInfo)
- {
- residentInfo.setUpdateTime(DateUtils.getNowDate());
- return residentInfoMapper.updateResidentInfo(residentInfo);
- }
- /**
- * 批量删除居住人员信息,存储居住人员的详细信息
- *
- * @param residentIds 需要删除的居住人员信息,存储居住人员的详细信息主键
- * @return 结果
- */
- @Override
- public int deleteResidentInfoByResidentIds(Long[] residentIds)
- {
- return residentInfoMapper.deleteResidentInfoByResidentIds(residentIds);
- }
- /**
- * 删除居住人员信息,存储居住人员的详细信息信息
- *
- * @param residentId 居住人员信息,存储居住人员的详细信息主键
- * @return 结果
- */
- @Override
- public int deleteResidentInfoByResidentId(Long residentId)
- {
- return residentInfoMapper.deleteResidentInfoByResidentId(residentId);
- }
- /**
- * 根据userId查询居住人员信息
- * @param userId
- * @return
- */
- @Override
- public ResidentInfo selectResidentInfoByUserId(Long userId) {
- return residentInfoMapper.selectResidentInfoByUserId(userId);
- }
- }
|