|
@@ -0,0 +1,170 @@
|
|
|
+package com.om.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.om.entity.dto.DiaMenuQueryPageDTO;
|
|
|
+import com.om.entity.dto.DiagnosticMenuDTO;
|
|
|
+import com.om.entity.po.Client;
|
|
|
+import com.om.entity.po.DiagnosticMenu;
|
|
|
+import com.om.entity.po.DiagnosticMenuVO;
|
|
|
+import com.om.entity.po.Distributor;
|
|
|
+import com.om.entity.vo.DiaMenuQueryPageVO;
|
|
|
+import com.om.entity.vo.DiaMenuUploadVO;
|
|
|
+import com.om.entity.vo.DistributorQueryPageVO;
|
|
|
+import com.om.exception.BadReqException;
|
|
|
+import com.om.mapper.DiagnosticMenuMapper;
|
|
|
+import com.om.service.IClientService;
|
|
|
+import com.om.service.IDiagnosticMenuService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.om.utils.FileSizeConverter;
|
|
|
+import com.om.utils.HuaweiObsUtil;
|
|
|
+import com.om.utils.Result;
|
|
|
+import org.springframework.context.annotation.Bean;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.om.constant.UploadConstant.DIAGNOSTIC_MENU_PREFIX;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author bmmx
|
|
|
+ * @since 2024-03-05
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DiagnosticMenuServiceImpl extends ServiceImpl<DiagnosticMenuMapper, DiagnosticMenu> implements IDiagnosticMenuService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private HuaweiObsUtil obsUtil;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IClientService clientService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result createDiaMenu(DiagnosticMenuDTO dto) {
|
|
|
+ if (BeanUtil.isEmpty(dto)) {
|
|
|
+ throw new BadReqException("数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ DiagnosticMenu diagnosticMenu = BeanUtil.copyProperties(dto, DiagnosticMenu.class);
|
|
|
+ diagnosticMenu.setCreateTime(LocalDateTime.now());
|
|
|
+ diagnosticMenu.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ this.save(diagnosticMenu);
|
|
|
+
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<DiaMenuUploadVO> uploadDiaMenu(MultipartFile file) {
|
|
|
+ long fileSize = file.getSize();
|
|
|
+ String size = FileSizeConverter.convertBytes(fileSize);
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+
|
|
|
+ //上传文件
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ int year = now.getYear();
|
|
|
+ int monthValue = now.getMonthValue();
|
|
|
+ int day = now.getDayOfMonth();
|
|
|
+ String prefix = DIAGNOSTIC_MENU_PREFIX + "/" + year + "/" + monthValue + "/" + day;
|
|
|
+ try {
|
|
|
+ String upload = obsUtil.upload(file, prefix);
|
|
|
+ DiaMenuUploadVO vo = new DiaMenuUploadVO();
|
|
|
+ vo.setFileName(filename);
|
|
|
+ vo.setFileSize(size);
|
|
|
+ vo.setSavePath(upload);
|
|
|
+ return Result.ok(vo);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result deleteDiaMenu(Integer id) {
|
|
|
+ //根据id查询
|
|
|
+ DiagnosticMenu diagnosticMenu = this.getById(id);
|
|
|
+ if (BeanUtil.isEmpty(diagnosticMenu)) {
|
|
|
+ throw new BadReqException("该诊断菜单不存在");
|
|
|
+ }
|
|
|
+ //根据id删除
|
|
|
+ this.removeById(id);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updateStatus(Integer id, Integer status) {
|
|
|
+ //根据id查询
|
|
|
+ DiagnosticMenu diagnosticMenu = this.getById(id);
|
|
|
+ if (BeanUtil.isEmpty(diagnosticMenu)) {
|
|
|
+ throw new BadReqException("该诊断菜单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ diagnosticMenu.setEnableStatus(status);
|
|
|
+ diagnosticMenu.setUpdateTime(LocalDateTime.now());
|
|
|
+ //修改
|
|
|
+ this.updateById(diagnosticMenu);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<DiaMenuQueryPageVO> getPageList(DiaMenuQueryPageDTO dto) {
|
|
|
+ //从dto中获取数据
|
|
|
+ Integer pageSize = dto.getPageSize();
|
|
|
+ Integer pageIndex = dto.getPageIndex();
|
|
|
+ String fileName = dto.getFileName();
|
|
|
+ String versionNum = dto.getVersionNum();
|
|
|
+
|
|
|
+ //分页查询数据库
|
|
|
+ Page<DiagnosticMenu> page = this.lambdaQuery()
|
|
|
+ .like(fileName != null, DiagnosticMenu::getFileName, fileName)
|
|
|
+ .like(versionNum != null, DiagnosticMenu::getVersionNum, versionNum)
|
|
|
+ .orderByDesc(DiagnosticMenu::getCreateTime)
|
|
|
+ .page(new Page<>(pageIndex, pageSize));
|
|
|
+
|
|
|
+ //封装vo
|
|
|
+ DiaMenuQueryPageVO vo = new DiaMenuQueryPageVO();
|
|
|
+ vo.setCurrent((int) page.getCurrent());
|
|
|
+ vo.setSize((int) page.getSize());
|
|
|
+ vo.setPages((int) page.getPages());
|
|
|
+ vo.setTotal((int) page.getTotal());
|
|
|
+ if (fileName !=null || versionNum !=null){
|
|
|
+ vo.setSearchCount(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<DiagnosticMenu> records = page.getRecords();
|
|
|
+ List<DiagnosticMenuVO> voList = new ArrayList<>();
|
|
|
+ for (DiagnosticMenu diagnosticMenu : records) {
|
|
|
+ DiagnosticMenuVO diagnosticMenuVO = BeanUtil.copyProperties(diagnosticMenu, DiagnosticMenuVO.class);
|
|
|
+
|
|
|
+ List<Integer> clientIds = Arrays.stream(diagnosticMenu.getClientIds().split(","))
|
|
|
+ .map(Integer::parseInt)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //根据id集合批量查询 客户端
|
|
|
+ List<Client> clients = clientService.listByIds(clientIds);
|
|
|
+ List<String> clientNames = clients.stream().map(c -> c.getName()).collect(Collectors.toList());
|
|
|
+ List<String> clientNums = clients.stream().map(c -> c.getNumber()).collect(Collectors.toList());
|
|
|
+ if (clients!=null){
|
|
|
+ diagnosticMenuVO.setClientNames(clientNames);
|
|
|
+ diagnosticMenuVO.setClientNums(clientNums);
|
|
|
+ }
|
|
|
+ voList.add(diagnosticMenuVO);
|
|
|
+ }
|
|
|
+ vo.setRecords(voList);
|
|
|
+ return Result.ok(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|