| | |
| | | package com.sinata.system.service.impl; |
| | | |
| | | import cn.idev.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.common.entity.PageDTO; |
| | | import com.sinata.common.exception.ServiceException; |
| | | import com.sinata.common.utils.BeanUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.system.domain.MwStagingRoom; |
| | | import com.sinata.system.domain.dto.MwStagingRoomDTO; |
| | | import com.sinata.system.domain.query.CheckoutRecordQuery; |
| | | import com.sinata.system.domain.query.MwStagingRoomQuery; |
| | | import com.sinata.system.domain.query.StorageRecordQuery; |
| | | import com.sinata.system.domain.vo.MwCheckoutRecordVO; |
| | | import com.sinata.system.domain.vo.MwStagingRoomVO; |
| | | import com.sinata.system.domain.vo.MwStorageRecordVO; |
| | | import com.sinata.system.mapper.MwStagingRoomMapper; |
| | | import com.sinata.system.service.MwStagingRoomService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-12-02 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MwStagingRoomServiceImpl extends ServiceImpl<MwStagingRoomMapper, MwStagingRoom> implements MwStagingRoomService { |
| | | private final SysDepartmentService sysDepartmentService; |
| | | |
| | | /** |
| | | * 暂存间分页列表 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwStagingRoomVO> pageList(MwStagingRoomQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwStagingRoomVO> page = baseMapper.pagelist(new Page<>(query.getPageCurr(), query.getPageSize()), treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 新增暂存间 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void add(MwStagingRoomDTO dto) { |
| | | MwStagingRoom mwStagingRoom = BeanUtils.copyBean(dto, MwStagingRoom.class); |
| | | Long count = this.lambdaQuery().eq(MwStagingRoom::getDepartmentId, mwStagingRoom.getDepartmentId()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("当前医院已存在暂存间,请勿重复添加"); |
| | | } |
| | | save(mwStagingRoom); |
| | | } |
| | | |
| | | /** |
| | | * 编辑暂存间 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void edit(MwStagingRoomDTO dto) { |
| | | if (Objects.isNull(dto.getId())) { |
| | | throw new ServiceException("暂存间id不能为空"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据医院id查询暂存间 |
| | | * |
| | | * @param departmentId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MwStagingRoomVO getByHospitalId(Long departmentId) { |
| | | MwStagingRoom one = this.lambdaQuery().eq(MwStagingRoom::getDepartmentId, departmentId).one(); |
| | | return BeanUtils.copyBean(one, MwStagingRoomVO.class); |
| | | } |
| | | |
| | | /** |
| | | * 暂存间入库记录 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwStorageRecordVO> storageRecord(StorageRecordQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwStorageRecordVO> page = baseMapper.storageRecordPage(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 暂存间入库记录导出 |
| | | * |
| | | * @param query |
| | | * @param response |
| | | */ |
| | | @Override |
| | | public void storageRecordExport(StorageRecordQuery query, HttpServletResponse response) throws IOException { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return; |
| | | } |
| | | List<MwStorageRecordVO> list = baseMapper.storageRecordList(query, treeCode); |
| | | // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("暂存间入库记录", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), MwStorageRecordVO.class).sheet("暂存间入库记录").doWrite(list); |
| | | } |
| | | |
| | | /** |
| | | * 暂存间出库记录 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwCheckoutRecordVO> checkoutRecord(CheckoutRecordQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwCheckoutRecordVO> page = baseMapper.checkoutRecordPage(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 暂存间出库记录导出 |
| | | * |
| | | * @param query |
| | | * @param response |
| | | */ |
| | | @Override |
| | | public void checkoutRecordExport(CheckoutRecordQuery query, HttpServletResponse response) throws IOException { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return; |
| | | } |
| | | List<MwCheckoutRecordVO> list = baseMapper.checkoutRecordList(query, treeCode); |
| | | // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("暂存间出库记录", "UTF-8").replaceAll("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), MwCheckoutRecordVO.class).sheet("暂存间出库记录").doWrite(list); |
| | | } |
| | | } |