-- Table structure for pill_purchase
-- ----------------------------
DROP TABLE IF EXISTS `pill_purchase`;
CREATE TABLE `pill_purchase` (
  `purchase_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '进货单ID',
  `drug_id` bigint(20) NOT NULL COMMENT '药品ID（关联pill_drug.drug_id）',
  `factory_id` bigint(20) NOT NULL COMMENT '生产厂家ID（关联pill_factory.factory_id）',
  `purchase_time` datetime NOT NULL COMMENT '进货时间',
  `purchase_price` decimal(10,2) NOT NULL COMMENT '进货单价（元）',
  `purchase_num` int(10) NOT NULL COMMENT '进货数量',
  `remark` varchar(500) DEFAULT NULL COMMENT '进货备注',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(50) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`purchase_id`),
  KEY `idx_drug_id` (`drug_id`),
  KEY `idx_factory_id` (`factory_id`),
  CONSTRAINT `fk_purchase_drug` FOREIGN KEY (`drug_id`) REFERENCES `pill_drug` (`drug_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_purchase_factory` FOREIGN KEY (`factory_id`) REFERENCES `pill_factory` (`factory_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8 COMMENT='药品进货记录表';

/*
Navicat MySQL Data Transfer

Source Server         : test
Source Server Version : 50717
Source Host           : localhost:3306
Source Database       : storage1

Target Server Type    : MYSQL
Target Server Version : 50717
File Encoding         : 65001

Date: 2022-09-25 17:33:23
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for pill_drug
-- ----------------------------
DROP TABLE IF EXISTS `pill_drug`;
CREATE TABLE `pill_drug` (
  `drug_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '药品ID',
  `drug_name` varchar(50) DEFAULT NULL COMMENT '药品名称',
  `drug_code` varchar(50) DEFAULT NULL COMMENT '药品编码',
  `factory_id` bigint(20) DEFAULT NULL COMMENT '生产厂家',
  `drug_type` char(1) DEFAULT NULL COMMENT '药品类型',
  `prescription_type` char(1) DEFAULT NULL COMMENT '处方类型',
  `unit` varchar(10) DEFAULT NULL COMMENT '单位',
  `price` int(10) DEFAULT NULL COMMENT '价格',
  `num` int(10) DEFAULT NULL COMMENT '库存量',
  `warn_value` int(10) DEFAULT NULL COMMENT '预警值',
  `conversion` int(10) DEFAULT NULL COMMENT '换算量',
  `status` char(1) DEFAULT NULL COMMENT '状态',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(50) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`drug_id`)
) ENGINE=InnoDB AUTO_INCREMENT=103 DEFAULT CHARSET=utf8 COMMENT='药品信息';

-- ----------------------------
-- Records of pill_drug
-- ----------------------------
INSERT INTO `pill_drug` VALUES ('101', '十全大补丸', 'dbw0001', '101', '0', '0', '瓶', '200', '100', '50', '1', '0', 'admin', '2022-08-27 16:03:29', null, null, null);
INSERT INTO `pill_drug` VALUES ('102', '阿莫西林', 'zcy0002', '102', '1', '1', '盒', '15', '300', '50', '1', '0', 'admin', '2022-09-15 16:03:29', null, null, null);

/*
Navicat MySQL Data Transfer

Source Server         : test
Source Server Version : 50717
Source Host           : localhost:3306
Source Database       : storage

Target Server Type    : MYSQL
Target Server Version : 50717
File Encoding         : 65001

Date: 2022-09-25 15:48:01
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for pill_factory
-- ----------------------------
DROP TABLE IF EXISTS `pill_factory`;
CREATE TABLE `pill_factory` (
  `factory_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '厂家ID',
  `factory_name` varchar(50) DEFAULT NULL COMMENT '厂家名称',
  `factory_code` varchar(50) DEFAULT NULL COMMENT '厂家编码',
  `contact` varchar(30) DEFAULT NULL COMMENT '联系人',
  `phone` varchar(30) DEFAULT NULL COMMENT '电话',
  `keyword` varchar(20) DEFAULT NULL COMMENT '关键字',
  `status` char(1) DEFAULT NULL COMMENT '状态',
  `create_by` varchar(50) DEFAULT NULL COMMENT '创建者',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `update_by` varchar(50) DEFAULT NULL COMMENT '更新者',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  PRIMARY KEY (`factory_id`)
) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8 COMMENT='生产厂家信息';

-- ----------------------------
-- Records of pill_factory
-- ----------------------------
INSERT INTO `pill_factory` VALUES ('101', '云南白药集团股份有限公司', '000011', 'admin', '023-88887777', 'ynby', '0', 'admin', '2022-09-26 16:15:29', null, null, null);
INSERT INTO `pill_factory` VALUES ('102', '哈药集团股份有限公司', '000022', 'admin', '023-88887777', 'hyjt', '0', 'admin', '2022-09-26 16:15:29', 'admin', '2022-09-26 20:34:01', null);
INSERT INTO `pill_factory` VALUES ('103', '太极集团有限公司', '000033', 'admin', '023-88887777', 'tjjt', '0', 'admin', '2022-09-26 16:15:29', null, null, null);
INSERT INTO `pill_factory` VALUES ('104', '上海医药集团有限公司', '000033', 'admin', '023-99998888', 'shyy', '0', 'admin', '2022-09-26 20:12:57', null, null, null);

DROP TABLE IF EXISTS `pill_expiry_warning`;
CREATE TABLE `pill_expiry_warning` (
  `warning_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `drug_id` bigint(20) NOT NULL COMMENT '药品ID（关联pill_drug.drug_id）',
  `factory_id` bigint(20) NOT NULL COMMENT '厂家ID（关联pill_factory.factory_id）',
  `production_date` date NOT NULL COMMENT '药品生产日期',
  `validity_period` int(10) NOT NULL COMMENT '保质期（天）',
  `purchase_id` bigint(20) NOT NULL COMMENT '进货单ID（关联pill_purchase.purchase_id）',
  `stock` int(10) NOT NULL COMMENT '库存数量',
  `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '记录创建时间',
  PRIMARY KEY (`warning_id`),
  KEY `idx_drug_id` (`drug_id`),
  KEY `idx_factory_id` (`factory_id`),
  CONSTRAINT `fk_expiry_drug` FOREIGN KEY (`drug_id`) REFERENCES `pill_drug` (`drug_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_expiry_factory` FOREIGN KEY (`factory_id`) REFERENCES `pill_factory` (`factory_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_expiry_purchase` FOREIGN KEY (`purchase_id`) REFERENCES `pill_purchase` (`purchase_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='药品有效期预警表，用于监控药品保质期';
帮忙修改代码
要显示 药品名称 生产厂家 药品生产日期 保质期 进货时间（pill_purchase） 药品距离多少天过期 库存
将purchase_time由pill_purchase表联合查询，让该表时需同步
不用编写库存数量，库存数量从  `num` int(10) DEFAULT NULL COMMENT '库存量',
获取，药品id，厂家id，进货单id都需要下拉框


<template>
  <div class="app-container">
    <!-- 搜索条件 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="药品ID" prop="drugId">
        <el-input
          v-model="queryParams.drugId"
          placeholder="请输入药品ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="厂家ID" prop="factoryId">
        <el-input
          v-model="queryParams.factoryId"
          placeholder="请输入厂家ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="药品生产日期" prop="productionDate">
        <el-date-picker
          clearable
          v-model="queryParams.productionDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择药品生产日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="保质期" prop="validityPeriod">
        <el-input
          v-model="queryParams.validityPeriod"
          placeholder="请输入保质期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="进货单ID" prop="purchaseId">
        <el-input
          v-model="queryParams.purchaseId"
          placeholder="请输入进货单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库存数量" prop="stock">
        <el-input
          v-model="queryParams.stock"
          placeholder="请输入库存数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >
          搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          重置
        </el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['pill:warning:add']"
        >
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['pill:warning:edit']"
        >
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['pill:warning:remove']"
        >
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pill:warning:export']"
        >
          导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>

    <!-- 表格 -->
    <el-table
      v-loading="loading"
      :data="warningList"
      @selection-change="handleSelectionChange"
      style="width: 100%"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="warningId" />
      <el-table-column label="药品名称" align="center" prop="drugName" />
      <el-table-column label="生产厂家" align="center" prop="factoryName" />
      <el-table-column
        label="药品生产日期"
        align="center"
        prop="productionDate"
        width="140"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="保质期(天)" align="center" prop="validityPeriod" />
      <el-table-column
        label="进货时间"
        align="center"
        prop="purchaseTime"
        width="180"
      >
        <template slot-scope="scope">
          <span
          >{{ parseTime(scope.row.purchaseTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="距离过期天数" align="center" width="120">
        <template slot-scope="scope">
          <span
          >{{ getRemainingDays(scope.row.productionDate, scope.row.validityPeriod) }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="库存数量" align="center" prop="stock" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pill:warning:edit']"
          >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pill:warning:remove']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 弹窗-添加或修改 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      append-to-body
      @close="cancel"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="药品ID" prop="drugId">
          <el-input v-model="form.drugId" placeholder="请输入药品ID" />
        </el-form-item>
        <el-form-item label="厂家ID" prop="factoryId">
          <el-input v-model="form.factoryId" placeholder="请输入厂家ID" />
        </el-form-item>
        <el-form-item label="药品生产日期" prop="productionDate">
          <el-date-picker
            clearable
            v-model="form.productionDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择药品生产日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="保质期" prop="validityPeriod">
          <el-input v-model="form.validityPeriod" placeholder="请输入保质期" />
        </el-form-item>
        <el-form-item label="进货单ID" prop="purchaseId">
          <el-input v-model="form.purchaseId" placeholder="请输入进货单ID" />
        </el-form-item>
        <el-form-item label="库存数量" prop="stock">
          <el-input v-model="form.stock" placeholder="请输入库存数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listWarning,
  getWarning,
  delWarning,
  addWarning,
  updateWarning,
} from "@/api/pill/warning"

export default {
  name: "Warning",
  data() {
    return {
      loading: true,
      ids: [],
      single: true,
      multiple: true,
      showSearch: true,
      total: 0,
      warningList: [],
      title: "",
      open: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        drugId: null,
        factoryId: null,
        productionDate: null,
        validityPeriod: null,
        purchaseId: null,
        stock: null,
      },
      form: {},
      rules: {
        drugId: [{ required: true, message: "药品ID不能为空", trigger: "blur" }],
        factoryId: [
          { required: true, message: "厂家ID不能为空", trigger: "blur" },
        ],
        productionDate: [
          { required: true, message: "药品生产日期不能为空", trigger: "blur" },
        ],
        validityPeriod: [
          { required: true, message: "保质期不能为空", trigger: "blur" },
        ],
        purchaseId: [
          { required: true, message: "进货单ID不能为空", trigger: "blur" },
        ],
        stock: [{ required: true, message: "库存数量不能为空", trigger: "blur" }],
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 解析时间 */
    parseTime(time, pattern) {
      if (!time) return "-"
      // 可用dayjs或自己写，也可以用以下简单实现
      const date = new Date(time)
      const Y = date.getFullYear()
      const M = (date.getMonth() + 1).toString().padStart(2, "0")
      const D = date.getDate().toString().padStart(2, "0")
      const h = date.getHours().toString().padStart(2, "0")
      const m = date.getMinutes().toString().padStart(2, "0")
      const s = date.getSeconds().toString().padStart(2, "0")
      if (!pattern) return `${Y}-${M}-${D} ${h}:${m}:${s}`
      return pattern
        .replace("{y}", Y)
        .replace("{m}", M)
        .replace("{d}", D)
        .replace("{h}", h)
        .replace("{i}", m)
        .replace("{s}", s)
    },
    /** 计算剩余天数 */
    getRemainingDays(productionDate, validityPeriod) {
      if (!productionDate || !validityPeriod) return ""
      const prodDate = new Date(productionDate)
      // 保质期单位是天，转成ms
      const expireDate = new Date(
        prodDate.getTime() + validityPeriod * 24 * 60 * 60 * 1000
      )
      const now = new Date()
      const diffTime = expireDate.getTime() - now.getTime()
      const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24))
      return diffDays >= 0 ? `${diffDays}天` : `已过期${-diffDays}天`
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      listWarning(this.queryParams)
        .then((response) => {
          this.warningList = response.rows
          this.total = response.total
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        warningId: null,
        drugId: null,
        factoryId: null,
        productionDate: null,
        validityPeriod: null,
        purchaseId: null,
        stock: null,
      }
      this.resetForm("form")
    },
    // 重置el-form
    resetForm(refName) {
      if (this.$refs[refName]) {
        this.$refs[refName].resetFields()
      }
    },
    /** 搜索按钮 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置搜索 */
    resetQuery() {
      this.resetForm("queryForm")
      // 清空查询参数
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        drugId: null,
        factoryId: null,
        productionDate: null,
        validityPeriod: null,
        purchaseId: null,
        stock: null,
      }
      this.handleQuery()
    },
    // 表格选中
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.warningId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加药品有效期预警，用于监控药品保质期"
    },
    /** 修改 */
    handleUpdate(row) {
      this.reset()
      const warningId = row?.warningId || this.ids[0]
      getWarning(warningId).then((response) => {
        this.form = response.data
        this.open = true
        this.title = "修改药品有效期预警，用于监控药品保质期"
      })
    },
    /** 提交表单 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.warningId != null) {
            updateWarning(this.form).then(() => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addWarning(this.form).then(() => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除 */
    handleDelete(row) {
      const warningIds = row?.warningId || this.ids
      this.$modal
        .confirm(
          `是否确认删除药品有效期预警，用于监控药品保质期编号为"${warningIds}"的数据项？`
        )
        .then(() => delWarning(warningIds))
        .then(() => {
          this.getList()
          this.$modal.msgSuccess("删除成功")
        })
        .catch(() => {})
    },
    /** 导出 */
    handleExport() {
      this.download(
        "pill/warning/export",
        {
          ...this.queryParams,
        },
        `warning_${new Date().getTime()}.xlsx`
      )
    },
  },
}
</script>

import request from '@/utils/request'

// 查询药品有效期预警，用于监控药品保质期列表
export function listWarning(query) {
  return request({
    url: '/pill/warning/list',
    method: 'get',
    params: query
  })
}

// 查询药品有效期预警，用于监控药品保质期详细
export function getWarning(warningId) {
  return request({
    url: '/pill/warning/' + warningId,
    method: 'get'
  })
}

// 新增药品有效期预警，用于监控药品保质期
export function addWarning(data) {
  return request({
    url: '/pill/warning',
    method: 'post',
    data: data
  })
}

// 修改药品有效期预警，用于监控药品保质期
export function updateWarning(data) {
  return request({
    url: '/pill/warning',
    method: 'put',
    data: data
  })
}

// 删除药品有效期预警，用于监控药品保质期
export function delWarning(warningId) {
  return request({
    url: '/pill/warning/' + warningId,
    method: 'delete'
  })
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.pill.mapper.PillExpiryWarningMapper">

    <resultMap id="PillExpiryWarningResult" type="com.ruoyi.pill.domain.PillExpiryWarning">
        <result property="warningId"    column="warning_id"    />
        <result property="drugId"    column="drug_id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="productionDate"    column="production_date"    />
        <result property="validityPeriod"    column="validity_period"    />
        <result property="purchaseId"    column="purchase_id"    />
        <result property="stock"    column="stock"    />
        <result property="createTime"    column="create_time"    />
        <!-- 新增 -->
        <result property="drugName" column="drug_name"/>
        <result property="factoryName" column="factory_name"/>
        <result property="purchaseTime" column="purchase_time"/>
        <result property="daysToExpire" column="days_to_expire"/>
    </resultMap>

    <sql id="BaseSelectSql">
        select
            pe.warning_id,
            pe.drug_id,
            pe.factory_id,
            pe.production_date,
            pe.validity_period,
            pe.purchase_id,
            pe.stock,
            pe.create_time,
            pd.drug_name,
            pf.factory_name,
            pp.purchase_time,
            -- 计算距离过期天数：有效期截止日期 - 当前日期
            datediff(date_add(pe.production_date, interval pe.validity_period day), curdate()) as days_to_expire
        from pill_expiry_warning pe
                 LEFT JOIN pill_drug pd ON pe.drug_id = pd.drug_id
                 LEFT JOIN pill_factory pf ON pe.factory_id = pf.factory_id
                 LEFT JOIN pill_purchase pp ON pe.purchase_id = pp.purchase_id
    </sql>

    <select id="selectPillExpiryWarningList" parameterType="com.ruoyi.pill.domain.PillExpiryWarning" resultMap="PillExpiryWarningResult">
        <include refid="BaseSelectSql"/>
        <where>
            <if test="drugId != null "> and pe.drug_id = #{drugId}</if>
            <if test="factoryId != null "> and pe.factory_id = #{factoryId}</if>
            <if test="productionDate != null "> and pe.production_date = #{productionDate}</if>
            <if test="validityPeriod != null "> and pe.validity_period = #{validityPeriod}</if>
            <if test="purchaseId != null "> and pe.purchase_id = #{purchaseId}</if>
            <if test="stock != null "> and pe.stock = #{stock}</if>
        </where>
    </select>

    <select id="selectPillExpiryWarningByWarningId" parameterType="Long" resultMap="PillExpiryWarningResult">
        <include refid="BaseSelectSql"/>
        where pe.warning_id = #{warningId}
    </select>

    <insert id="insertPillExpiryWarning" parameterType="com.ruoyi.pill.domain.PillExpiryWarning" useGeneratedKeys="true" keyProperty="warningId">
        insert into pill_expiry_warning
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="drugId != null">drug_id,</if>
            <if test="factoryId != null">factory_id,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="validityPeriod != null">validity_period,</if>
            <if test="purchaseId != null">purchase_id,</if>
            <if test="stock != null">stock,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="drugId != null">#{drugId},</if>
            <if test="factoryId != null">#{factoryId},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="validityPeriod != null">#{validityPeriod},</if>
            <if test="purchaseId != null">#{purchaseId},</if>
            <if test="stock != null">#{stock},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updatePillExpiryWarning" parameterType="com.ruoyi.pill.domain.PillExpiryWarning">
        update pill_expiry_warning
        <trim prefix="SET" suffixOverrides=",">
            <if test="drugId != null">drug_id = #{drugId},</if>
            <if test="factoryId != null">factory_id = #{factoryId},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="validityPeriod != null">validity_period = #{validityPeriod},</if>
            <if test="purchaseId != null">purchase_id = #{purchaseId},</if>
            <if test="stock != null">stock = #{stock},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where warning_id = #{warningId}
    </update>

    <delete id="deletePillExpiryWarningByWarningId" parameterType="Long">
        delete from pill_expiry_warning where warning_id = #{warningId}
    </delete>

    <delete id="deletePillExpiryWarningByWarningIds" parameterType="Long[]">
        delete from pill_expiry_warning where warning_id in
        <foreach item="warningId" collection="array" open="(" separator="," close=")">
            #{warningId}
        </foreach>
    </delete>
</mapper>