Commit 13fc277d by 杨伟程
parents 8d3f21ab eac35281
......@@ -96,7 +96,10 @@ public enum CodeMessageEnum {
PLATFORM_ERROR_SPACE_NAME_DUPLICATE(500,"PLATFORM.ERROR.SPACE.NAME.DUPLICATE"),
PLATFORM_ERROR_SPACE_NOT_DEL(500,"PLATFORM.ERROR.SPACE.NOT.DEL"),
PLATFORM_ERROR_ROOM_EXIT_BAD(500,"PLATFORM.ERROR.ROOM.EXIT.BAD"),
PLATFORM_ERROR_ROOM_BAD_NUMBER_NOT_AUTH(500,"PLATFORM.ERROR.ROOM.BAD.NUMBER.NOT.AUTH"),
PLATFORM_ERROR_BAD_NAME_EXIT(500,"PLATFORM.ERROR.BAD.NAME.EXIT"),
PLATFORM_ERROR_BAD_NOT_DEL(500,"PLATFORM.ERROR.BAD.NOT.DEL"),
......
......@@ -92,3 +92,7 @@ PLATFORM.ERROR.ELDER.CERTIFICATENUMBER.DUPLICATE=证件号不能重复
PLATFORM.ERROR.SPACE.NAME.DUPLICATE=同一层级,空间名称不能重复
PLATFORM.ERROR.SPACE.NOT.DEL=该空间下存在下级或者房间,不可删除
PLATFORM.ERROR.ROOM.EXIT.BAD=房间中存在床位,不可删除
PLATFORM.ERROR.ROOM.BAD.NUMBER.NOT.AUTH=床位数量不能改小
PLATFORM.ERROR.BAD.NAME.EXIT=床位名称已存在
PLATFORM.ERROR.BAD.NOT.DEL=床位已绑定长者,不可删除
\ No newline at end of file
package com.makeit.module.controller.space;
import com.makeit.common.dto.BaseIdDTO;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.common.response.ApiResponseEntity;
import com.makeit.common.response.ApiResponseUtils;
import com.makeit.dto.platform.space.PlatBedEditDTO;
import com.makeit.dto.platform.space.PlatBedQueryDTO;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.service.platform.space.PlatBedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author:lzy
* @Date:2023/9/6 11:56
* @Describe:
*/
@Api(tags = "床位管理")
@RestController
@RequestMapping("/plat/bad")
public class PlatBedController {
@Autowired
private PlatBedService platBedService;
@ApiOperation("列表")
@PostMapping("page")
public ApiResponseEntity<PageVO<PlatBed>> page(@RequestBody PageReqDTO<PlatBedQueryDTO> page) {
PageVO<PlatBed> data = platBedService.page(page);
return ApiResponseUtils.success(data);
}
@ApiOperation("详情")
@PostMapping("view")
public ApiResponseEntity<PlatBed> view(@RequestBody BaseIdDTO baseIdDTO) {
PlatBed data = platBedService.view(baseIdDTO.getId());
return ApiResponseUtils.success(data);
}
@ApiOperation("编辑")
@PostMapping("edit")
public ApiResponseEntity<?> edit(@Validated @RequestBody PlatBedEditDTO dto) {
platBedService.edit(dto);
return ApiResponseUtils.success();
}
@ApiOperation("删除")
@PostMapping("del")
public ApiResponseEntity<?> del(@RequestBody BaseIdDTO baseIdDTO) {
platBedService.del(baseIdDTO.getId());
return ApiResponseUtils.success();
}
}
package com.makeit.dto.platform.space;
import com.makeit.common.dto.BaseIdDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/**
* @Author:lzy
* @Date:2023/9/6 11:45
* @Describe:
*/
@Data
@ApiModel("PlatBedEditDTO 参数")
public class PlatBedEditDTO extends BaseIdDTO {
@NotBlank(message = "名称不能为空")
@Size(max = 50, message = "名称最长为50个字符")
@ApiModelProperty(value = "名称",required = true)
private String name;
}
package com.makeit.dto.platform.space;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Author:lzy
* @Date:2023/9/6 11:39
* @Describe:
*/
@Data
@ApiModel("PlatBedQueryDTO 参数")
public class PlatBedQueryDTO {
@ApiModelProperty("名称")
private String name;
@ApiModelProperty("房间Id")
private String roomId;
}
package com.makeit.service.platform.space;
import com.baomidou.mybatisplus.extension.service.IService;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.space.PlatBedEditDTO;
import com.makeit.dto.platform.space.PlatBedQueryDTO;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
......@@ -16,4 +20,32 @@ public interface PlatBedService extends IService<PlatBed> {
* @param platRoom
*/
void add(PlatRoom platRoom);
/**
*
* @param pageReqDTO
* @return
*/
PageVO<PlatBed> page(PageReqDTO<PlatBedQueryDTO> pageReqDTO);
/**
*
* @param dto
*/
void edit(PlatBedEditDTO dto);
/**
* 详情
* @param id
* @return
*/
PlatBed view(String id);
/**
*
* @param id
*/
void del(String id);
}
package com.makeit.service.platform.space.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.space.PlatBedEditDTO;
import com.makeit.dto.platform.space.PlatBedQueryDTO;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.enums.CommonEnum;
import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.space.PlatBedMapper;
import com.makeit.service.platform.space.PlatBedService;
import com.makeit.utils.data.convert.PageUtil;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -28,16 +39,73 @@ public class PlatBedServiceImpl extends ServiceImpl<PlatBedMapper, PlatBed> impl
queryWrapper.orderByDesc(PlatBed::getSort);
List<PlatBed> list = list(queryWrapper);
if(list.isEmpty()){
for(int i=1;i<=platRoom.getBedNumber();i++){
if(platRoom.getBedNumber() >=1){
int start = 1;
int end = platRoom.getBedNumber();
if(!list.isEmpty()){
start = list.get(0).getSort()+1;
end = platRoom.getBedNumber() - list.size();
}
List<PlatBed> listBad = new ArrayList<>();
for(int i=0;i<end;i++){
int location = start+i;
PlatBed platBed = new PlatBed();
platBed.setName("床位" + location);
platBed.setSort(location);
platBed.setRoomId(platRoom.getId());
platBed.setSpaceId(platRoom.getSpaceId());
platBed.setStatus(CommonEnum.YES.getValue());
listBad.add(platBed);
}
if(!listBad.isEmpty()){
saveBatch(listBad);
}
}
}
@Override
public PageVO<PlatBed> page(PageReqDTO<PlatBedQueryDTO> pageReqDTO) {
PlatBedQueryDTO dto = pageReqDTO.getData();
Page<PlatBed> p = PageUtil.toMpPage(pageReqDTO);
LambdaQueryWrapper<PlatBed> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtil.isNotEmpty(dto.getName()),PlatBed::getName,dto.getName());
queryWrapper.eq(StringUtil.isNotEmpty(dto.getRoomId()),PlatBed::getRoomId,dto.getRoomId());
Page<PlatBed> pages = page(p,queryWrapper);
return PageUtil.toPageVO(pages.getRecords(), pages);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(PlatBedEditDTO dto) {
PlatBed platBed = getById(dto.getId());
LambdaQueryWrapper<PlatBed> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(PlatBed::getRoomId,platBed.getRoomId());
queryWrapper.eq(PlatBed::getName,dto.getName());
queryWrapper.ne(PlatBed::getId,dto.getId());
if(count(queryWrapper) >0){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_BAD_NAME_EXIT);
}
}
@Override
public PlatBed view(String id) {
return getById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void del(String id) {
PlatBed platBed = getById(id);
if(CommonEnum.NO.getValue().equals(platBed.getStatus())){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_BAD_NOT_DEL);
}
removeById(id);
}
}
......@@ -7,12 +7,17 @@ import com.makeit.common.page.PageReqDTO;
import com.makeit.common.page.PageVO;
import com.makeit.dto.platform.space.PlatRoomDTO;
import com.makeit.dto.platform.space.PlatRoomQueryDTO;
import com.makeit.entity.platform.space.PlatBed;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.space.PlatRoomMapper;
import com.makeit.service.platform.space.PlatBedService;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import com.makeit.utils.data.convert.PageUtil;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -26,25 +31,35 @@ import java.util.List;
@Service
public class PlatRoomServiceImpl extends ServiceImpl<PlatRoomMapper, PlatRoom> implements PlatRoomService {
@Autowired
private PlatBedService platBedService;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(PlatRoomDTO dto) {
PlatRoom platRoom = BeanDtoVoUtils.convert(dto,PlatRoom.class);
save(platRoom);
platBedService.add(platRoom);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void edit(PlatRoomDTO dto) {
PlatRoom platRoom = getById(dto.getId());
if(platRoom.getBedNumber() > dto.getBedNumber()){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_ROOM_BAD_NUMBER_NOT_AUTH);
}
platRoom.setName(dto.getName());
platRoom.setBedNumber(dto.getBedNumber());
platRoom.setDescription(dto.getDescription());
platRoom.setSpaceId(dto.getSpaceId());
platRoom.setSpacePath(dto.getSpacePath());
updateById(platRoom);
platBedService.add(platRoom);
}
@Override
......@@ -57,7 +72,11 @@ public class PlatRoomServiceImpl extends ServiceImpl<PlatRoomMapper, PlatRoom> i
@Override
public void del(List<String> ids) {
//TODO 判断是否有床位
LambdaQueryWrapper<PlatBed> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(PlatBed::getRoomId,ids);
if(platBedService.count(queryWrapper) > 0){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_ROOM_EXIT_BAD);
}
removeByIds(ids);
}
......
......@@ -5,13 +5,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.makeit.dto.platform.space.PlatSpaceAddDTO;
import com.makeit.dto.platform.space.PlatSpaceQueryDTO;
import com.makeit.dto.platform.space.PlatSpaceVO;
import com.makeit.entity.platform.space.PlatRoom;
import com.makeit.entity.platform.space.PlatSpace;
import com.makeit.enums.CodeMessageEnum;
import com.makeit.exception.BusinessException;
import com.makeit.mapper.platform.space.PlatSpaceMapper;
import com.makeit.service.platform.space.PlatRoomService;
import com.makeit.service.platform.space.PlatSpaceService;
import com.makeit.utils.data.convert.BeanDtoVoUtils;
import jodd.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -28,6 +31,8 @@ import java.util.stream.Collectors;
@Service
public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace> implements PlatSpaceService {
@Autowired
private PlatRoomService platRoomService;
private void check(PlatSpaceAddDTO dto){
LambdaQueryWrapper<PlatSpace> queryWrapper = new LambdaQueryWrapper<>();
......@@ -47,7 +52,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void add(PlatSpaceAddDTO dto) {
check(dto);
PlatSpace space = BeanDtoVoUtils.convert(dto, PlatSpace.class);
......@@ -55,7 +60,7 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void edit(PlatSpaceAddDTO dto) {
check(dto);
......@@ -80,6 +85,11 @@ public class PlatSpaceServiceImpl extends ServiceImpl<PlatSpaceMapper, PlatSpace
}
//TODO 房间的判断
LambdaQueryWrapper<PlatRoom> queryWrapper1 = new LambdaQueryWrapper<>();
queryWrapper1.eq(PlatRoom::getSpaceId,id);
if(platRoomService.count(queryWrapper1) > 0){
throw new BusinessException(CodeMessageEnum.PLATFORM_ERROR_SPACE_NOT_DEL);
}
this.removeById(id);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment