package com.thhy.staff.modules.biz.dorm.service.impl; import com.alibaba.nacos.api.utils.StringUtils; import com.thhy.general.common.BasicStatus; import com.thhy.general.config.SysUserInfo; import com.thhy.general.exception.BasicException; import com.thhy.general.utils.DeepCopyUtils; import com.thhy.general.utils.UserInfoUtils; import com.thhy.staff.modules.biz.dorm.entity.Dorm; import com.thhy.staff.modules.biz.dorm.entity.DormDto; import com.thhy.staff.modules.biz.dorm.entity.DormListVo; import com.thhy.staff.modules.biz.dorm.mapper.DormMapper; import com.thhy.staff.modules.biz.dorm.service.DormService; import com.thhy.staff.modules.biz.dormuser.entity.DormUser; import com.thhy.staff.modules.biz.dormuser.entity.DormUserVo; import com.thhy.staff.modules.biz.dormuser.mapper.DormUserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.Serializable; import java.util.Date; import java.util.List; /** * 服务实现类 * @author zhang_xiao_bo * @since 2023-04-03 12:49:45 */ @Service public class DormServiceImpl implements DormService { @Autowired private DormMapper dormMapper; @Autowired private DormUserMapper dormUserMapper; public Dorm get(Serializable id){ return dormMapper.queryById(id); } public List findList(DormDto dormDto){ SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo(); if(dormDto==null)dormDto=new DormDto(); dormDto.setCompanyId(userInfo.getCompanyId()); List list = dormMapper.findList(dormDto); for (DormListVo dormListVo :list){ List dormUserVoList = dormUserMapper.findDormUserList(dormListVo.getDormId()); dormListVo.setDormUserVos(dormUserVoList); } return list; } /** * 增加和修改 * @param dormDto */ @Transactional public void addDorm(DormDto dormDto){ SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String userIds = dormDto.getUserIds(); Dorm dorm = new Dorm(); DeepCopyUtils.copy(dormDto,dorm); List dormList = dormMapper.queryDormIdByRoom(dormDto.getRoomId()); if(dorm.getDormId() == null){ //增加操作 if(dormList.size()>0){ throw new BasicException(BasicStatus.DORM_IS_EXIST); } dorm.setCreateUser(sysUserInfo.getUserId()); dormMapper.insert(dorm); }else{ //修改操作 if(dormList.size()>1){ throw new BasicException(BasicStatus.DORM_DATA_IS_ERROR); }else if(dormList.size()==1){ if(!dormList.get(0).getDormId().equals(dormDto.getDormId())){ throw new BasicException(BasicStatus.DORM_IS_EXIST); } } dorm.setUpdateUser(sysUserInfo.getUserId()); dorm.setUpdateTime(new Date()); dormMapper.update(dorm); } if(!StringUtils.isEmpty(userIds)){ String[] userIdArray = new String[]{userIds}; if(userIds.contains(",")){ userIdArray = userIds.split(","); } if(dormDto.getBedNum() dormUserVoList = dormUserMapper.findDormUserList(dorm.getDormId()); dormDto.setDormUserVoList(dormUserVoList); return dormDto; } }