|
@@ -0,0 +1,184 @@
|
|
|
+package com.zhentao.drug.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.zhentao.common.Result;
|
|
|
+import com.zhentao.drug.dto.param.DrugParam;
|
|
|
+import com.zhentao.drug.domain.DrugInfo;
|
|
|
+import com.zhentao.drug.service.DrugInfoService;
|
|
|
+import com.zhentao.drug.mapper.DrugInfoMapper;
|
|
|
+import com.zhentao.drug.utils.IdUtil;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+* @author Administrator
|
|
|
+* @description 针对表【drug_info(药品基础信息表)】的数据库操作Service实现
|
|
|
+* @createDate 2025-05-20 16:04:39
|
|
|
+*/
|
|
|
+@Service
|
|
|
+public class DrugInfoServiceImpl extends ServiceImpl<DrugInfoMapper, DrugInfo>
|
|
|
+ implements DrugInfoService{
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result drugAll(DrugParam drugParam) {
|
|
|
+ //设置分页查询
|
|
|
+ Page<DrugInfo> page=new Page<>(drugParam.getPageNum(),drugParam.getPageSize());
|
|
|
+
|
|
|
+
|
|
|
+ //设置查询条件
|
|
|
+ QueryWrapper<DrugInfo> queryWrapper=new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(drugParam.getDrugName())){
|
|
|
+ //根据药名称模糊查询
|
|
|
+ queryWrapper.like("drug_name",drugParam.getDrugName());
|
|
|
+ }
|
|
|
+// indication
|
|
|
+ if (StringUtils.isNotBlank(drugParam.getIndication())){
|
|
|
+ //根据适应症状模糊查询
|
|
|
+ queryWrapper.like("indication",drugParam.getIndication());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理库存数量查询(只查询库存大于等于0的药品)
|
|
|
+ queryWrapper.gt("stock_quantity",1);
|
|
|
+
|
|
|
+ Page<DrugInfo> page1 = this.page(page, queryWrapper);
|
|
|
+
|
|
|
+ return Result.SUCCESS(page1);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result addDrug(DrugInfo drugInfo) {
|
|
|
+ MultipartFile imageFile = drugInfo.getImageFile();
|
|
|
+ if (imageFile != null &&!imageFile.isEmpty()) {
|
|
|
+ // 生成唯一文件名
|
|
|
+ String originalFilename = imageFile.getOriginalFilename();
|
|
|
+ System.err.println(originalFilename+"输出这是什么玩意");
|
|
|
+ String fileExtension = originalFilename.substring(originalFilename.lastIndexOf('.'));
|
|
|
+ System.err.println(fileExtension+"输出这是什么玩意");
|
|
|
+ String uniqueFileName = UUID.randomUUID().toString().replace("-","") + fileExtension;
|
|
|
+ System.err.println(uniqueFileName+"输出这是什么玩意");
|
|
|
+ // 保存图片到指定目录(这里简单示例,实际可调整为文件存储服务)
|
|
|
+// String filePath = "D:/images/医疗项目/" + uniqueFileName;
|
|
|
+ String filePath = "C:/Users/Administrator/Desktop/医疗项目/MedSmart/src/main/resources/statis/" + uniqueFileName;
|
|
|
+ try {
|
|
|
+ imageFile.transferTo(new File(filePath));
|
|
|
+ drugInfo.setImage(uniqueFileName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Result.FAIL("图片保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 这里假设你有其他业务逻辑,比如生成drugId等,先简单处理
|
|
|
+ // 保存药品信息到数据库
|
|
|
+ drugInfo.setDrugId(IdUtil.nextId());
|
|
|
+ boolean saveResult = this.save(drugInfo);
|
|
|
+ if (saveResult) {
|
|
|
+ return Result.SUCCESS("药品添加成功");
|
|
|
+ } else {
|
|
|
+ return Result.FAIL("药品添加失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //雪花算法
|
|
|
+ /* @Override
|
|
|
+ public Result addDrug(DrugParam drugParam) {
|
|
|
+ DrugInfo drugInfo = new DrugInfo();
|
|
|
+
|
|
|
+ drugInfo.setDrugId(IdUtil.nextId());
|
|
|
+ drugInfo.setDrugName(drugParam.getDrugName());
|
|
|
+ drugInfo.setTradeName(drugParam.getTradeName());
|
|
|
+ drugInfo.setManufacturer(drugParam.getManufacturer());
|
|
|
+ drugInfo.setSpecification(drugParam.getSpecification());
|
|
|
+ drugInfo.setIndication(drugParam.getIndication());
|
|
|
+ drugInfo.setContraindication(drugParam.getContraindication());
|
|
|
+ drugInfo.setSideEffect(drugParam.getSideEffect());
|
|
|
+ drugInfo.setPrice(drugParam.getPrice());
|
|
|
+ drugInfo.setCategoryId(drugParam.getCategoryId());
|
|
|
+ drugInfo.setStockQuantity(drugParam.getStockQuantity());
|
|
|
+ drugInfo.setWarningThreshold(drugParam.getWarningThreshold());
|
|
|
+ boolean save = this.save(drugInfo);
|
|
|
+
|
|
|
+ return Result.SUCCESS(save+"添加成功");
|
|
|
+ }
|
|
|
+*/
|
|
|
+ @Override
|
|
|
+ public Result updateDrug(MultipartFile imageFile, Integer id) {
|
|
|
+ DrugInfo byId = this.getById(id);
|
|
|
+
|
|
|
+ if (imageFile != null &&!imageFile.isEmpty()) {
|
|
|
+ // 生成唯一文件名
|
|
|
+ String originalFilename = imageFile.getOriginalFilename();
|
|
|
+ System.err.println(originalFilename+"输出这是什么玩意");
|
|
|
+ String fileExtension = originalFilename.substring(originalFilename.lastIndexOf('.'));
|
|
|
+ System.err.println(fileExtension+"输出这是什么玩意");
|
|
|
+ String uniqueFileName = UUID.randomUUID().toString().replace("-","") + fileExtension;
|
|
|
+ System.err.println(uniqueFileName+"输出这是什么玩意");
|
|
|
+ // 保存图片到指定目录(这里简单示例,实际可调整为文件存储服务)
|
|
|
+// String filePath = "D:/images/医疗项目/" + uniqueFileName;
|
|
|
+ String filePath = "C:/Users/Administrator/Desktop/医疗项目/MedSmart/src/main/resources/statis/" + uniqueFileName;
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ imageFile.transferTo(new File(filePath));
|
|
|
+ byId.setImage(uniqueFileName);
|
|
|
+ System.err.println("image+"+byId);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return Result.FAIL("图片保存失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 这里假设你有其他业务逻辑,比如生成drugId等,先简单处理
|
|
|
+ // 保存药品信息到数据库
|
|
|
+ System.err.println(byId);
|
|
|
+ boolean b = this.updateById(byId);
|
|
|
+ if (b) {
|
|
|
+ return Result.SUCCESS("药品修改成功");
|
|
|
+ } else {
|
|
|
+ return Result.FAIL("药品修改失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+/*
|
|
|
+ @Override
|
|
|
+ public Result updateDrug(DrugParam drugParam) {
|
|
|
+ //根据参数id,查找修改数据
|
|
|
+ QueryWrapper<DrugInfo> queryWrapper=new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("drug_id",drugParam.getDrugId());
|
|
|
+ DrugInfo byId = this.getOne(queryWrapper);
|
|
|
+ //要修改的数据
|
|
|
+ byId.setDrugName(drugParam.getDrugName());
|
|
|
+ byId.setTradeName(drugParam.getTradeName());
|
|
|
+ byId.setManufacturer(drugParam.getManufacturer());
|
|
|
+ byId.setSpecification(drugParam.getSpecification());
|
|
|
+ byId.setIndication(drugParam.getIndication());
|
|
|
+ byId.setContraindication(drugParam.getContraindication());
|
|
|
+ byId.setSideEffect(drugParam.getSideEffect());
|
|
|
+ byId.setPrice(drugParam.getPrice());
|
|
|
+ byId.setStockQuantity(drugParam.getStockQuantity());
|
|
|
+ byId.setCategoryId(drugParam.getCategoryId());
|
|
|
+ byId.setWarningThreshold(drugParam.getWarningThreshold());
|
|
|
+ boolean b = this.updateById(byId);
|
|
|
+ return Result.SUCCESS(b+"修改成功");
|
|
|
+ }
|
|
|
+*/
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result delDrug(Integer id) {
|
|
|
+ boolean b = this.removeById(id);
|
|
|
+ return Result.SUCCESS(b+"==true?'删除成功':'删除失败'");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|