package com.thhy.staff.modules.biz.area.service.impl;
|
|
import com.alibaba.nacos.api.utils.StringUtils;
|
import com.thhy.general.config.SysUserInfo;
|
import com.thhy.general.utils.UserInfoUtils;
|
import com.thhy.staff.modules.biz.area.entity.Area;
|
import com.thhy.staff.modules.biz.area.entity.AreaDto;
|
import com.thhy.staff.modules.biz.area.entity.AreaInfoVo;
|
import com.thhy.staff.modules.biz.area.entity.AreaListVo;
|
import com.thhy.staff.modules.biz.area.mapper.AreaMapper;
|
import com.thhy.staff.modules.biz.area.service.AreaService;
|
import com.thhy.staff.modules.biz.areauser.entity.AreaUser;
|
import com.thhy.staff.modules.biz.areauser.mapper.AreaUserMapper;
|
import com.thhy.staff.modules.biz.dormuser.entity.DormUserVo;
|
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 13:28:52
|
*/
|
@Service
|
public class AreaServiceImpl implements AreaService {
|
|
|
|
@Autowired
|
private AreaMapper areaMapper;
|
|
@Autowired
|
private AreaUserMapper areaUserMapper;
|
|
public Area get(Serializable id){
|
return areaMapper.queryById(id);
|
}
|
|
public List<AreaListVo> findList(AreaDto area){
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
if(area==null)area=new AreaDto();
|
area.setCompanyId(sysUserInfo.getCompanyId());
|
return areaMapper.findList(area);
|
}
|
|
@Override
|
public AreaInfoVo queryAreaInfo(Area area) {
|
AreaInfoVo areaInfoVo = areaMapper.queryByIdHasUser(area.getId());
|
List<DormUserVo> dormUserVoList = areaUserMapper.findAreaUserList(area.getId());
|
areaInfoVo.setAreaAdminList(dormUserVoList);
|
return areaInfoVo;
|
}
|
|
/**
|
* 增加和修改
|
* @param areaDto
|
*/
|
@Transactional
|
public void addArea(AreaDto areaDto){
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
String userIds = areaDto.getUserIds();
|
Area area = new Area();
|
area.setAreaName(areaDto.getAreaName());
|
if(areaDto.getId() == null){
|
//增加操作
|
area.setCreateUser(sysUserInfo.getUserId());
|
area.setCompanyId(sysUserInfo.getCompanyId());
|
areaMapper.insert(area);
|
}else{
|
//修改操作
|
area.setId(areaDto.getId());
|
area.setUpdateUser(sysUserInfo.getUserId());
|
area.setUpdateTime(new Date());
|
areaMapper.update(area);
|
}
|
areaUserMapper.deleteById(area.getId());
|
|
if(!StringUtils.isEmpty(userIds)){
|
String[] userIdArray = new String[]{userIds};
|
if(userIds.contains(",")){
|
userIdArray = userIds.split(",");
|
}
|
for(String userId : userIdArray){
|
areaUserMapper.insert(new AreaUser(area.getId(),userId));
|
}
|
}
|
}
|
|
/**
|
* 修改
|
* @param area
|
*/
|
public void update(Area area){
|
areaMapper.update(area);
|
}
|
|
/**
|
* 删除
|
* @param id
|
*/
|
public void delete(Serializable id){
|
areaMapper.deletelogic(id);
|
}
|
}
|