| | |
| | | package com.doumee.service.business.impl; |
| | | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.model.LoginUserInfo; |
| | | import com.doumee.core.model.PageData; |
| | | import com.doumee.core.model.PageWrap; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.core.utils.Utils; |
| | | import com.doumee.dao.business.YwBuildingMapper; |
| | | import com.doumee.dao.business.YwRoomMapper; |
| | | import com.doumee.dao.business.model.YwBuilding; |
| | | import com.doumee.dao.business.model.YwProject; |
| | | import com.doumee.dao.business.model.YwRoom; |
| | | import com.doumee.service.business.YwRoomService; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private YwRoomMapper ywRoomMapper; |
| | | @Autowired |
| | | private YwBuildingMapper ywBuildingMapper; |
| | | |
| | | @Override |
| | | public Integer create(YwRoom ywRoom) { |
| | | ywRoomMapper.insert(ywRoom); |
| | | return ywRoom.getId(); |
| | | public Integer create(YwRoom model) { |
| | | if(model.getBuildingId()==null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!"); |
| | | } |
| | | YwBuilding ywBuilding = ywBuildingMapper.selectById(model.getBuildingId()); |
| | | if(ywBuilding ==null ||Constants.equalsInteger(ywBuilding.getIsdeleted(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!"); |
| | | } |
| | | model.setProjectId(ywBuilding.getProjectId()); |
| | | model.setCreator(model.getLoginUserInfo().getId()); |
| | | model.setIsdeleted(Constants.ZERO); |
| | | model.setCreateDate(new Date()); |
| | | model.setStatus(Constants.ZERO); |
| | | model.setEditDate(model.getCreateDate()); |
| | | model.setEditor(model.getCreator()); |
| | | ywRoomMapper.insert(model); |
| | | return model.getId(); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteById(Integer id) { |
| | | ywRoomMapper.deleteById(id); |
| | | public void deleteById(Integer id, LoginUserInfo user) { |
| | | YwRoom model = new YwRoom(); |
| | | model.setId(id); |
| | | model.setEditDate(new Date()); |
| | | model.setEditor(user.getId()); |
| | | model.setIsdeleted(Constants.ONE); |
| | | ywRoomMapper.updateById(model); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByIdInBatch(List<Integer> ids) { |
| | | public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { |
| | | if (CollectionUtils.isEmpty(ids)) { |
| | | return; |
| | | } |
| | | ywRoomMapper.deleteBatchIds(ids); |
| | | for (Integer ywProject: ids) { |
| | | this.deleteById(ywProject,user); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void updateById(YwRoom ywRoom) { |
| | | ywRoomMapper.updateById(ywRoom); |
| | | public void updateById(YwRoom model) { |
| | | if(model.getBuildingId()==null){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!"); |
| | | } |
| | | YwBuilding ywBuilding = ywBuildingMapper.selectById(model.getBuildingId()); |
| | | if(ywBuilding ==null ||Constants.equalsInteger(ywBuilding.getIsdeleted(),Constants.ONE)){ |
| | | throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"对不起,请选择正确的楼宇信息!"); |
| | | } |
| | | model.setProjectId(ywBuilding.getProjectId()); |
| | | model.setEditDate(new Date()); |
| | | model.setEditor(model.getLoginUserInfo().getId()); |
| | | ywRoomMapper.updateById(model); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<YwRoom> findList(YwRoom ywRoom) { |
| | | QueryWrapper<YwRoom> wrapper = new QueryWrapper<>(ywRoom); |
| | | ywRoom.setIsdeleted(Constants.ZERO); |
| | | QueryWrapper<YwRoom> wrapper = new QueryWrapper< >(ywRoom); |
| | | return ywRoomMapper.selectList(wrapper); |
| | | } |
| | | |
| | |
| | | public PageData<YwRoom> findPage(PageWrap<YwRoom> pageWrap) { |
| | | IPage<YwRoom> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | QueryWrapper<YwRoom> queryWrapper = new QueryWrapper<>(); |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.lambda().eq(YwRoom::getId, pageWrap.getModel().getId()); |
| | |
| | | if (pageWrap.getModel().getBuildingId() != null) { |
| | | queryWrapper.lambda().eq(YwRoom::getBuildingId, pageWrap.getModel().getBuildingId()); |
| | | } |
| | | for(PageWrap.SortData sortData: pageWrap.getSorts()) { |
| | | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { |
| | | queryWrapper.orderByDesc(sortData.getProperty()); |
| | | } else { |
| | | queryWrapper.orderByAsc(sortData.getProperty()); |
| | | } |
| | | } |
| | | queryWrapper.lambda().orderByAsc(YwRoom::getRoomNum); |
| | | return PageData.from(ywRoomMapper.selectPage(page, queryWrapper)); |
| | | } |
| | | |