HuRongxin 3 ay önce
ebeveyn
işleme
37cafc54c3
18 değiştirilmiş dosya ile 1443 ekleme ve 66 silme
  1. 1 1
      ruoyi-admin/src/main/resources/application.yml
  2. BIN
      ruoyi-admin/src/main/resources/download-template/foodIngredient.xlsx
  3. 6 0
      ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/BizConst.java
  4. 33 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/config/RedisUtil.java
  5. 1 1
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDiseaseLabelController.java
  6. 119 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysFoodIngredientController.java
  7. 187 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysFoodIngredient.java
  8. 179 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysFoodIngredientBo.java
  9. 3 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysFoodCategoryVo.java
  10. 240 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysFoodIngredientVo.java
  11. 0 57
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDiseaseLabel.java
  12. 15 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysFoodIngredientMapper.java
  13. 72 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysFoodIngredientService.java
  14. 1 1
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDiseaseLabelServiceImpl.java
  15. 21 6
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysFoodCategoryServiceImpl.java
  16. 511 0
      ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysFoodIngredientServiceImpl.java
  17. 7 0
      ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysFoodIngredientMapper.xml
  18. 47 0
      script/sql/biz/create.sql

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -1,7 +1,7 @@
 # 开发环境配置
 server:
   # 服务器的HTTP端口,默认为8080
-  port: 8080
+  port: 8081
   servlet:
     # 应用的访问路径
     context-path: /

BIN
ruoyi-admin/src/main/resources/download-template/foodIngredient.xlsx


+ 6 - 0
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/BizConst.java

@@ -22,4 +22,10 @@ public interface BizConst {
     String QNY_STATIC_DOMAIN = "static_domain";
 
     String QNY_CONFIG_CACHE = "qny:config";
+
+    String FOOD_INGREDIENT_CODE = "food:ingredient:code:";
+
+    String FOOD_INGREDIENT_CODE_PREFIX = "SC";
+
+    String DATE_PATTERN_FOR_SIMPLE_DAY = "yyMMdd";
 }

+ 33 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/config/RedisUtil.java

@@ -0,0 +1,33 @@
+package org.dromara.system.config;
+
+import cn.hutool.core.date.format.FastDateFormat;
+import cn.hutool.core.util.StrUtil;
+import org.dromara.common.core.constant.BizConst;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author chenYing
+ * @date 2025-06-30 17:38:53
+ **/
+@Component
+public class RedisUtil {
+    private static RedisTemplate redisTemplate;
+
+    public RedisUtil(RedisTemplate redisTemplate) {
+        RedisUtil.redisTemplate = redisTemplate;
+    }
+
+    public static String generateFoodCode() {
+        String today = FastDateFormat.getInstance(BizConst.DATE_PATTERN_FOR_SIMPLE_DAY).format(new Date());
+        String key = BizConst.FOOD_INGREDIENT_CODE + today;
+        Long val = redisTemplate.opsForValue().increment(key, 1);
+        if (Long.valueOf(1L).equals(val)) {
+            redisTemplate.expire(key, 24, TimeUnit.HOURS);
+        }
+        return BizConst.FOOD_INGREDIENT_CODE_PREFIX + today + StrUtil.padPre(String.valueOf(val), 5, "0");
+    }
+}

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysDiseaseLabelController.java

@@ -117,7 +117,7 @@ public class SysDiseaseLabelController extends BaseController {
         ExcelUtil.downLoadTemplate("diseaseLabel.xlsx", "疾病_部位标签模版", response);
     }
 
-    @SaCheckPermission("system:diseaseLabel:importExcel")
+    @SaCheckPermission("system:diseaseLabel:import")
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public R<?> importExcel(MultipartFile file) throws Exception {
         return sysDiseaseLabelService.importExcel(file);

+ 119 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysFoodIngredientController.java

@@ -0,0 +1,119 @@
+package org.dromara.system.controller.system;
+
+import java.util.List;
+
+import lombok.RequiredArgsConstructor;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.constraints.*;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.validation.annotation.Validated;
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.web.core.BaseController;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.excel.utils.ExcelUtil;
+import org.dromara.system.domain.vo.SysFoodIngredientVo;
+import org.dromara.system.domain.bo.SysFoodIngredientBo;
+import org.dromara.system.service.ISysFoodIngredientService;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.springframework.web.multipart.MultipartFile;
+
+/**
+ * 食材管理
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/system/foodIngredient")
+public class SysFoodIngredientController extends BaseController {
+
+    private final ISysFoodIngredientService sysFoodIngredientService;
+
+    /**
+     * 查询食材管理列表
+     */
+    @SaCheckPermission("system:foodIngredient:list")
+    @GetMapping("/list")
+    public TableDataInfo<SysFoodIngredientVo> list(SysFoodIngredientBo bo, PageQuery pageQuery) {
+        return sysFoodIngredientService.queryPageList(bo, pageQuery);
+    }
+
+    /**
+     * 导出食材管理列表
+     */
+    @SaCheckPermission("system:foodIngredient:export")
+    @Log(title = "食材管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(SysFoodIngredientBo bo, HttpServletResponse response) {
+        List<SysFoodIngredientVo> list = sysFoodIngredientService.queryList(bo);
+        ExcelUtil.exportExcel(list, "食材管理", SysFoodIngredientVo.class, response);
+    }
+
+    /**
+     * 获取食材管理详细信息
+     *
+     * @param foodIngredientId 主键
+     */
+    @SaCheckPermission("system:foodIngredient:query")
+    @GetMapping("/{foodIngredientId}")
+    public R<SysFoodIngredientVo> getInfo(@NotNull(message = "主键不能为空")
+                                          @PathVariable Long foodIngredientId) {
+        return R.ok(sysFoodIngredientService.queryById(foodIngredientId));
+    }
+
+    /**
+     * 新增食材管理
+     */
+    @SaCheckPermission("system:foodIngredient:add")
+    @Log(title = "食材管理", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping()
+    public R<String> add(@Validated(AddGroup.class) @RequestBody SysFoodIngredientBo bo) {
+        sysFoodIngredientService.insertByBo(bo);
+        return R.ok("成功!",String.valueOf(bo.getFoodIngredientId()));
+    }
+
+    /**
+     * 修改食材管理
+     */
+    @SaCheckPermission("system:foodIngredient:edit")
+    @Log(title = "食材管理", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping()
+    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysFoodIngredientBo bo) {
+        return toAjax(sysFoodIngredientService.updateByBo(bo));
+    }
+
+    /**
+     * 删除食材管理
+     *
+     * @param foodIngredientIds 主键串
+     */
+    @SaCheckPermission("system:foodIngredient:remove")
+    @Log(title = "食材管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{foodIngredientIds}")
+    public R<Void> remove(@NotEmpty(message = "主键不能为空")
+                          @PathVariable Long[] foodIngredientIds) {
+        return toAjax(sysFoodIngredientService.deleteWithValidByIds(List.of(foodIngredientIds), true));
+    }
+
+    @SaCheckPermission("system:foodIngredient:downLoadTemplate")
+    @RequestMapping(value = "/downLoadTemplate", method = RequestMethod.GET)
+    public void downLoadTemplate(HttpServletResponse response) {
+        ExcelUtil.downLoadTemplate("foodIngredient.xlsx", "疾病_部位标签模版", response);
+    }
+
+    @SaCheckPermission("system:foodIngredient:import")
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public R<?> importExcel(MultipartFile file) throws Exception {
+        return sysFoodIngredientService.importExcel(file);
+    }
+}

+ 187 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysFoodIngredient.java

@@ -0,0 +1,187 @@
+package org.dromara.system.domain;
+
+import org.dromara.common.tenant.core.TenantEntity;
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serial;
+import java.math.BigDecimal;
+
+/**
+ * 食材管理对象 sys_food_ingredient
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName("sys_food_ingredient")
+public class SysFoodIngredient extends TenantEntity {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @TableId(value = "food_ingredient_id")
+    private Long foodIngredientId;
+
+    /**
+     * 食材分类ID
+     */
+    private String foodCategoryId;
+
+    /**
+     * 食材名称
+     */
+    private String name;
+
+    /**
+     * 食材编码
+     */
+    private String code;
+
+    /**
+     * 单位
+     */
+    private String unit;
+
+    /**
+     * 入货价格(元)
+     */
+    private BigDecimal purchasePrice;
+
+    /**
+     * 食材可食比例构成(%)
+     */
+    private BigDecimal edibleRatio;
+
+    /**
+     * 保质期(天)
+     */
+    private Long shelfLife;
+
+    /**
+     * 库存预警值(g)
+     */
+    private BigDecimal stockWarning;
+
+    /**
+     * 保质期预警(天)
+     */
+    private Long expiryWarning;
+
+    /**
+     * 食材描述
+     */
+    private String description;
+
+    /**
+     * 热量(kcal)
+     */
+    private BigDecimal calories;
+
+    /**
+     * 蛋白质(g)
+     */
+    private BigDecimal protein;
+
+    /**
+     * 脂肪(g)
+     */
+    private BigDecimal fat;
+
+    /**
+     * 碳水化合物(g)
+     */
+    private BigDecimal carbohydrate;
+
+    /**
+     * 水分(ml)
+     */
+    private BigDecimal water;
+
+    /**
+     * 维生素A(μg)
+     */
+    private BigDecimal vitaminA;
+
+    /**
+     * 维生素B2(mg)
+     */
+    private BigDecimal vitaminB2;
+
+    /**
+     * 维生素C(mg)
+     */
+    private BigDecimal vitaminC;
+
+    /**
+     * 钠(mg)
+     */
+    private BigDecimal sodium;
+
+    /**
+     * 铁(mg)
+     */
+    private BigDecimal iron;
+
+    /**
+     * 磷(mg)
+     */
+    private BigDecimal phosphorus;
+
+    /**
+     * 膳食纤维(g)
+     */
+    private BigDecimal dietaryFiber;
+
+    /**
+     * 维生素B1(mg)
+     */
+    private BigDecimal vitaminB1;
+
+    /**
+     * 烟酸(mg)
+     */
+    private BigDecimal niacin;
+
+    /**
+     * 维生素E(mg)
+     */
+    private BigDecimal vitaminE;
+
+    /**
+     * 钙(mg)
+     */
+    private BigDecimal calcium;
+
+    /**
+     * 钾(mg)
+     */
+    private BigDecimal potassium;
+
+    /**
+     * 胆固醇(g)
+     */
+    private BigDecimal cholesterol;
+
+    /**
+     * 状态(0正常 1停用)
+     */
+    private String status;
+
+    /**
+     * 删除标志(0代表存在 1代表删除)
+     */
+    @TableLogic
+    private String delFlag;
+
+    @TableField(exist = false)
+    private String bigCategory;
+
+    @TableField(exist = false)
+    private String subCategory;
+}

+ 179 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysFoodIngredientBo.java

@@ -0,0 +1,179 @@
+package org.dromara.system.domain.bo;
+
+import org.dromara.system.domain.SysFoodIngredient;
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import jakarta.validation.constraints.*;
+
+import java.math.BigDecimal;
+
+/**
+ * 食材管理业务对象 sys_food_ingredient
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = SysFoodIngredient.class, reverseConvertGenerate = false)
+public class SysFoodIngredientBo extends BaseEntity {
+
+    /**
+     * 主键ID
+     */
+    private Long foodIngredientId;
+
+    /**
+     * 食材分类ID
+     */
+    @NotNull(message = "食材分类不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String foodCategoryId;
+
+    /**
+     * 食材名称
+     */
+    @NotBlank(message = "食材名称不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String name;
+
+    /**
+     * 食材编码
+     */
+    private String code;
+
+    /**
+     * 单位
+     */
+    @NotBlank(message = "单位不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String unit;
+
+    /**
+     * 入货价格(元)
+     */
+    private BigDecimal purchasePrice;
+
+    /**
+     * 食材可食比例构成(%)
+     */
+    private BigDecimal edibleRatio;
+
+    /**
+     * 保质期(天)
+     */
+    private Long shelfLife;
+
+    /**
+     * 库存预警值(g)
+     */
+    private BigDecimal stockWarning;
+
+    /**
+     * 保质期预警(天)
+     */
+    private Long expiryWarning;
+
+    /**
+     * 食材描述
+     */
+    private String description;
+
+    /**
+     * 热量(kcal)
+     */
+    private BigDecimal calories;
+
+    /**
+     * 蛋白质(g)
+     */
+    private BigDecimal protein;
+
+    /**
+     * 脂肪(g)
+     */
+    private BigDecimal fat;
+
+    /**
+     * 碳水化合物(g)
+     */
+    private BigDecimal carbohydrate;
+
+    /**
+     * 水分(ml)
+     */
+    private BigDecimal water;
+
+    /**
+     * 维生素A(μg)
+     */
+    private BigDecimal vitaminA;
+
+    /**
+     * 维生素B2(mg)
+     */
+    private BigDecimal vitaminB2;
+
+    /**
+     * 维生素C(mg)
+     */
+    private BigDecimal vitaminC;
+
+    /**
+     * 钠(mg)
+     */
+    private BigDecimal sodium;
+
+    /**
+     * 铁(mg)
+     */
+    private BigDecimal iron;
+
+    /**
+     * 磷(mg)
+     */
+    private BigDecimal phosphorus;
+
+    /**
+     * 膳食纤维(g)
+     */
+    private BigDecimal dietaryFiber;
+
+    /**
+     * 维生素B1(mg)
+     */
+    private BigDecimal vitaminB1;
+
+    /**
+     * 烟酸(mg)
+     */
+    private BigDecimal niacin;
+
+    /**
+     * 维生素E(mg)
+     */
+    private BigDecimal vitaminE;
+
+    /**
+     * 钙(mg)
+     */
+    private BigDecimal calcium;
+
+    /**
+     * 钾(mg)
+     */
+    private BigDecimal potassium;
+
+    /**
+     * 胆固醇(g)
+     */
+    private BigDecimal cholesterol;
+
+    /**
+     * 状态(0正常 1停用)
+     */
+    private String status;
+
+
+}

+ 3 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysFoodCategoryVo.java

@@ -1,5 +1,7 @@
 package org.dromara.system.domain.vo;
 
+import com.alibaba.fastjson.annotation.JSONField;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import org.dromara.system.domain.SysFoodCategory;
 import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
 import cn.idev.excel.annotation.ExcelProperty;
@@ -32,6 +34,7 @@ public class SysFoodCategoryVo implements Serializable {
      * 主键ID
      */
     @ExcelProperty(value = "主键ID")
+    @JsonFormat(shape = JsonFormat.Shape.STRING)
     private Long foodCategoryId;
 
     private Integer isDefault;

+ 240 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysFoodIngredientVo.java

@@ -0,0 +1,240 @@
+package org.dromara.system.domain.vo;
+
+import org.dromara.system.domain.SysFoodIngredient;
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
+import cn.idev.excel.annotation.ExcelProperty;
+import org.dromara.common.excel.annotation.ExcelDictFormat;
+import org.dromara.common.excel.convert.ExcelDictConvert;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+
+/**
+ * 食材管理视图对象 sys_food_ingredient
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+@Data
+@ExcelIgnoreUnannotated
+@AutoMapper(target = SysFoodIngredient.class)
+public class SysFoodIngredientVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键ID
+     */
+    @ExcelProperty(value = "主键ID")
+    private Long foodIngredientId;
+
+    /**
+     * 食材分类ID
+     */
+    @ExcelProperty(value = "食材分类ID")
+    private String foodCategoryId;
+
+    private String bigCategory;
+
+    private String subCategory;
+
+    /**
+     * 食材名称
+     */
+    @ExcelProperty(value = "食材名称")
+    private String name;
+
+    /**
+     * 食材编码
+     */
+    @ExcelProperty(value = "食材编码")
+    private String code;
+
+    /**
+     * 单位
+     */
+    @ExcelProperty(value = "单位")
+    private String unit;
+
+    /**
+     * 入货价格(元)
+     */
+    @ExcelProperty(value = "入货价格", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "元=")
+    private BigDecimal purchasePrice;
+
+    /**
+     * 食材可食比例构成(%)
+     */
+    @ExcelProperty(value = "食材可食比例构成", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "%=")
+    private BigDecimal edibleRatio;
+
+    /**
+     * 保质期(天)
+     */
+    @ExcelProperty(value = "保质期", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "天=")
+    private Long shelfLife;
+
+    /**
+     * 库存预警值(g)
+     */
+    @ExcelProperty(value = "库存预警值", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal stockWarning;
+
+    /**
+     * 保质期预警(天)
+     */
+    @ExcelProperty(value = "保质期预警", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "天=")
+    private Long expiryWarning;
+
+    /**
+     * 食材描述
+     */
+    @ExcelProperty(value = "食材描述")
+    private String description;
+
+    /**
+     * 热量(kcal)
+     */
+    @ExcelProperty(value = "热量", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "k=cal")
+    private BigDecimal calories;
+
+    /**
+     * 蛋白质(g)
+     */
+    @ExcelProperty(value = "蛋白质", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal protein;
+
+    /**
+     * 脂肪(g)
+     */
+    @ExcelProperty(value = "脂肪", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal fat;
+
+    /**
+     * 碳水化合物(g)
+     */
+    @ExcelProperty(value = "碳水化合物", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal carbohydrate;
+
+    /**
+     * 水分(ml)
+     */
+    @ExcelProperty(value = "水分", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=l")
+    private BigDecimal water;
+
+    /**
+     * 维生素A(μg)
+     */
+    @ExcelProperty(value = "维生素A", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "μ=g")
+    private BigDecimal vitaminA;
+
+    /**
+     * 维生素B2(mg)
+     */
+    @ExcelProperty(value = "维生素B2", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal vitaminB2;
+
+    /**
+     * 维生素C(mg)
+     */
+    @ExcelProperty(value = "维生素C", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal vitaminC;
+
+    /**
+     * 钠(mg)
+     */
+    @ExcelProperty(value = "钠", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal sodium;
+
+    /**
+     * 铁(mg)
+     */
+    @ExcelProperty(value = "铁", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal iron;
+
+    /**
+     * 磷(mg)
+     */
+    @ExcelProperty(value = "磷", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal phosphorus;
+
+    /**
+     * 膳食纤维(g)
+     */
+    @ExcelProperty(value = "膳食纤维", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal dietaryFiber;
+
+    /**
+     * 维生素B1(mg)
+     */
+    @ExcelProperty(value = "维生素B1", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal vitaminB1;
+
+    /**
+     * 烟酸(mg)
+     */
+    @ExcelProperty(value = "烟酸", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal niacin;
+
+    /**
+     * 维生素E(mg)
+     */
+    @ExcelProperty(value = "维生素E", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal vitaminE;
+
+    /**
+     * 钙(mg)
+     */
+    @ExcelProperty(value = "钙", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal calcium;
+
+    /**
+     * 钾(mg)
+     */
+    @ExcelProperty(value = "钾", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "m=g")
+    private BigDecimal potassium;
+
+    /**
+     * 胆固醇(g)
+     */
+    @ExcelProperty(value = "胆固醇", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "g=")
+    private BigDecimal cholesterol;
+
+    /**
+     * 状态(0正常 1停用)
+     */
+    @ExcelProperty(value = "状态", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "0=正常,1=停用")
+    private String status;
+
+
+}

+ 0 - 57
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDiseaseLabel.java

@@ -1,57 +0,0 @@
-package org.dromara.system.mapper;
-
-import org.dromara.common.tenant.core.TenantEntity;
-import com.baomidou.mybatisplus.annotation.*;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.io.Serial;
-
-/**
- * 疾病/部位标签对象 sys_disease_label
- *
- * @author Lion Li
- * @date 2025-06-26
- */
-@Data
-@EqualsAndHashCode(callSuper = true)
-@TableName("sys_disease_label")
-public class SysDiseaseLabel extends TenantEntity {
-
-    @Serial
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 主键ID
-     */
-    @TableId(value = "label_id")
-    private Long labelId;
-
-    /**
-     * 疾病/部位名称
-     */
-    private String labelName;
-
-    /**
-     * 疾病/部位编码
-     */
-    private String labelCode;
-
-    /**
-     * 所属分类
-     */
-    private String category;
-
-    /**
-     * 状态(0正常 1停用)
-     */
-    private String status;
-
-    /**
-     * 删除标志(0代表存在 1代表删除)
-     */
-    @TableLogic
-    private String delFlag;
-
-
-}

+ 15 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysFoodIngredientMapper.java

@@ -0,0 +1,15 @@
+package org.dromara.system.mapper;
+
+import org.dromara.system.domain.SysFoodIngredient;
+import org.dromara.system.domain.vo.SysFoodIngredientVo;
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+
+/**
+ * 食材管理Mapper接口
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+public interface SysFoodIngredientMapper extends BaseMapperPlus<SysFoodIngredient, SysFoodIngredientVo> {
+
+}

+ 72 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysFoodIngredientService.java

@@ -0,0 +1,72 @@
+package org.dromara.system.service;
+
+import org.dromara.common.core.domain.R;
+import org.dromara.system.domain.vo.SysFoodIngredientVo;
+import org.dromara.system.domain.bo.SysFoodIngredientBo;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 食材管理Service接口
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+public interface ISysFoodIngredientService {
+
+    /**
+     * 查询食材管理
+     *
+     * @param foodIngredientId 主键
+     * @return 食材管理
+     */
+    SysFoodIngredientVo queryById(Long foodIngredientId);
+
+    /**
+     * 分页查询食材管理列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 食材管理分页列表
+     */
+    TableDataInfo<SysFoodIngredientVo> queryPageList(SysFoodIngredientBo bo, PageQuery pageQuery);
+
+    /**
+     * 查询符合条件的食材管理列表
+     *
+     * @param bo 查询条件
+     * @return 食材管理列表
+     */
+    List<SysFoodIngredientVo> queryList(SysFoodIngredientBo bo);
+
+    /**
+     * 新增食材管理
+     *
+     * @param bo 食材管理
+     * @return 是否新增成功
+     */
+    Boolean insertByBo(SysFoodIngredientBo bo);
+
+    /**
+     * 修改食材管理
+     *
+     * @param bo 食材管理
+     * @return 是否修改成功
+     */
+    Boolean updateByBo(SysFoodIngredientBo bo);
+
+    /**
+     * 校验并批量删除食材管理信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    R<?> importExcel(MultipartFile file) throws Exception;
+}

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDiseaseLabelServiceImpl.java

@@ -212,7 +212,7 @@ public class SysDiseaseLabelServiceImpl implements ISysDiseaseLabelService {
         } else {
             return R.fail("以下行数据不完整:" + builder);
         }
-        
+
         return R.ok("导入成功!");
     }
 }

+ 21 - 6
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysFoodCategoryServiceImpl.java

@@ -23,6 +23,8 @@ import org.dromara.system.service.ISysFoodCategoryService;
 import java.util.List;
 import java.util.Map;
 import java.util.Collection;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * 食材分类Service业务层处理
@@ -43,17 +45,30 @@ public class SysFoodCategoryServiceImpl implements ISysFoodCategoryService {
         if (StrUtil.isNotBlank(bo.getName())) {
             foodCategoryList = baseMapper.selectList(Wrappers.lambdaQuery(SysFoodCategory.class)
                 .like(SysFoodCategory::getName, bo.getName()));
-            List<SysFoodCategory> parentList = CollUtil.newArrayList();
-            for (int i = foodCategoryList.size() - 1; i >= 0; i--) {
-                SysFoodCategory category = foodCategoryList.get(i);
-//                if () {
-//
-//                }
+            if (CollUtil.isEmpty(foodCategoryList)) {
+                return TableDataInfo.build();
+            }
+
+            Set<Long> parentIdSet = foodCategoryList.stream()
+                .filter(v -> ObjUtil.isNotNull(v.getParentId()) && v.getParentId() > 0)
+                .map(SysFoodCategory::getParentId).collect(Collectors.toSet());
+
+            if (CollUtil.isNotEmpty(parentIdSet)) {
+                Map<Long, SysFoodCategory> parentMap = baseMapper
+                    .selectList(Wrappers.lambdaQuery(SysFoodCategory.class)
+                        .in(SysFoodCategory::getFoodCategoryId, parentIdSet))
+                    .stream().collect(Collectors.toMap(k1 -> k1.getFoodCategoryId(), k2 -> k2, (k1, k2) -> k1));
+
+                foodCategoryList.forEach(v -> {
+                    parentMap.remove(v.getFoodCategoryId());
+                });
+                foodCategoryList.addAll(parentMap.values());
             }
         } else {
             foodCategoryList = baseMapper.selectList();
         }
 
+        foodCategoryList.sort((o1, o2) -> o1.getParentId().compareTo(o2.getParentId()));
         List<SysFoodCategoryVo> treeList = CollUtil.newArrayList();
         Map<Long, SysFoodCategoryVo> foodMap = MapUtil.newHashMap(foodCategoryList.size());
         foodCategoryList.forEach(v -> {

+ 511 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysFoodIngredientServiceImpl.java

@@ -0,0 +1,511 @@
+package org.dromara.system.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.NumberUtil;
+import cn.hutool.core.util.ObjUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.idev.excel.FastExcel;
+import org.dromara.common.core.constant.BizConst;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.core.exception.ServiceException;
+import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.system.config.RedisUtil;
+import org.dromara.system.domain.SysDiseaseLabel;
+import org.dromara.system.domain.SysFoodCategory;
+import org.dromara.system.mapper.SysFoodCategoryMapper;
+import org.springframework.stereotype.Service;
+import org.dromara.system.domain.bo.SysFoodIngredientBo;
+import org.dromara.system.domain.vo.SysFoodIngredientVo;
+import org.dromara.system.domain.SysFoodIngredient;
+import org.dromara.system.mapper.SysFoodIngredientMapper;
+import org.dromara.system.service.ISysFoodIngredientService;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Collection;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * 食材管理Service业务层处理
+ *
+ * @author Lion Li
+ * @date 2025-06-30
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class SysFoodIngredientServiceImpl implements ISysFoodIngredientService {
+
+    private final SysFoodIngredientMapper baseMapper;
+
+    private final SysFoodCategoryMapper categoryMapper;
+
+    /**
+     * 查询食材管理
+     *
+     * @param foodIngredientId 主键
+     * @return 食材管理
+     */
+    @Override
+    public SysFoodIngredientVo queryById(Long foodIngredientId) {
+        return baseMapper.selectVoById(foodIngredientId);
+    }
+
+    /**
+     * 分页查询食材管理列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 食材管理分页列表
+     */
+    @Override
+    public TableDataInfo<SysFoodIngredientVo> queryPageList(SysFoodIngredientBo bo, PageQuery pageQuery) {
+        LambdaQueryWrapper<SysFoodIngredient> lqw = buildQueryWrapper(bo);
+        Page<SysFoodIngredientVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
+
+        if (CollUtil.isNotEmpty(result.getRecords())) {
+            Set<Long> ids = CollUtil.newHashSet();
+            result.getRecords().forEach(v -> {
+                Arrays.stream(v.getFoodCategoryId().split(",")).forEach(id -> {
+                    ids.add(Long.valueOf(id));
+                });
+            });
+
+            List<SysFoodCategory> categoryList = categoryMapper.selectList(Wrappers.lambdaQuery(SysFoodCategory.class)
+                .in(SysFoodCategory::getFoodCategoryId, ids));
+            Map<String, String> categoryMap = categoryList.stream().collect(Collectors.toMap(k1 -> String.valueOf(k1.getFoodCategoryId()), k2 -> k2.getName(), (k1, k2) -> k1));
+            result.getRecords().forEach(v -> {
+                String[] arr = v.getFoodCategoryId().split(",");
+                if (arr.length >= 1) {
+                    v.setBigCategory(categoryMap.get(arr[0]));
+                }
+                if (arr.length >= 2) {
+                    v.setSubCategory(categoryMap.get(arr[1]));
+                }
+            });
+        }
+
+        return TableDataInfo.build(result);
+    }
+
+    /**
+     * 查询符合条件的食材管理列表
+     *
+     * @param bo 查询条件
+     * @return 食材管理列表
+     */
+    @Override
+    public List<SysFoodIngredientVo> queryList(SysFoodIngredientBo bo) {
+        LambdaQueryWrapper<SysFoodIngredient> lqw = buildQueryWrapper(bo);
+        return baseMapper.selectVoList(lqw);
+    }
+
+    private LambdaQueryWrapper<SysFoodIngredient> buildQueryWrapper(SysFoodIngredientBo bo) {
+        Map<String, Object> params = bo.getParams();
+        LambdaQueryWrapper<SysFoodIngredient> lqw = Wrappers.lambdaQuery();
+        lqw.orderByAsc(SysFoodIngredient::getFoodIngredientId);
+//        lqw.eq(bo.getFoodCategoryId() != null, SysFoodIngredient::getFoodCategoryId, bo.getFoodCategoryId());
+        if (StrUtil.isNotBlank(bo.getFoodCategoryId())) {
+            lqw.apply("find_in_set({0},food_category_id)", bo.getFoodCategoryId());
+        }
+        lqw.like(StringUtils.isNotBlank(bo.getName()), SysFoodIngredient::getName, bo.getName());
+        lqw.eq(StringUtils.isNotBlank(bo.getCode()), SysFoodIngredient::getCode, bo.getCode());
+        lqw.eq(StringUtils.isNotBlank(bo.getUnit()), SysFoodIngredient::getUnit, bo.getUnit());
+        lqw.eq(bo.getPurchasePrice() != null, SysFoodIngredient::getPurchasePrice, bo.getPurchasePrice());
+        lqw.eq(bo.getEdibleRatio() != null, SysFoodIngredient::getEdibleRatio, bo.getEdibleRatio());
+        lqw.eq(bo.getShelfLife() != null, SysFoodIngredient::getShelfLife, bo.getShelfLife());
+        lqw.eq(bo.getStockWarning() != null, SysFoodIngredient::getStockWarning, bo.getStockWarning());
+        lqw.eq(bo.getExpiryWarning() != null, SysFoodIngredient::getExpiryWarning, bo.getExpiryWarning());
+        lqw.eq(StringUtils.isNotBlank(bo.getDescription()), SysFoodIngredient::getDescription, bo.getDescription());
+        lqw.eq(bo.getCalories() != null, SysFoodIngredient::getCalories, bo.getCalories());
+        lqw.eq(bo.getProtein() != null, SysFoodIngredient::getProtein, bo.getProtein());
+        lqw.eq(bo.getFat() != null, SysFoodIngredient::getFat, bo.getFat());
+        lqw.eq(bo.getCarbohydrate() != null, SysFoodIngredient::getCarbohydrate, bo.getCarbohydrate());
+        lqw.eq(bo.getWater() != null, SysFoodIngredient::getWater, bo.getWater());
+        lqw.eq(bo.getVitaminA() != null, SysFoodIngredient::getVitaminA, bo.getVitaminA());
+        lqw.eq(bo.getVitaminB2() != null, SysFoodIngredient::getVitaminB2, bo.getVitaminB2());
+        lqw.eq(bo.getVitaminC() != null, SysFoodIngredient::getVitaminC, bo.getVitaminC());
+        lqw.eq(bo.getSodium() != null, SysFoodIngredient::getSodium, bo.getSodium());
+        lqw.eq(bo.getIron() != null, SysFoodIngredient::getIron, bo.getIron());
+        lqw.eq(bo.getPhosphorus() != null, SysFoodIngredient::getPhosphorus, bo.getPhosphorus());
+        lqw.eq(bo.getDietaryFiber() != null, SysFoodIngredient::getDietaryFiber, bo.getDietaryFiber());
+        lqw.eq(bo.getVitaminB1() != null, SysFoodIngredient::getVitaminB1, bo.getVitaminB1());
+        lqw.eq(bo.getNiacin() != null, SysFoodIngredient::getNiacin, bo.getNiacin());
+        lqw.eq(bo.getVitaminE() != null, SysFoodIngredient::getVitaminE, bo.getVitaminE());
+        lqw.eq(bo.getCalcium() != null, SysFoodIngredient::getCalcium, bo.getCalcium());
+        lqw.eq(bo.getPotassium() != null, SysFoodIngredient::getPotassium, bo.getPotassium());
+        lqw.eq(bo.getCholesterol() != null, SysFoodIngredient::getCholesterol, bo.getCholesterol());
+        lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysFoodIngredient::getStatus, bo.getStatus());
+        return lqw;
+    }
+
+    /**
+     * 新增食材管理
+     *
+     * @param bo 食材管理
+     * @return 是否新增成功
+     */
+    @Override
+    public Boolean insertByBo(SysFoodIngredientBo bo) {
+        SysFoodIngredient add = MapstructUtils.convert(bo, SysFoodIngredient.class);
+        validEntityBeforeSave(add);
+        add.setCode(RedisUtil.generateFoodCode());
+        boolean flag = baseMapper.insert(add) > 0;
+        if (flag) {
+            bo.setFoodIngredientId(add.getFoodIngredientId());
+        }
+        return flag;
+    }
+
+    /**
+     * 修改食材管理
+     *
+     * @param bo 食材管理
+     * @return 是否修改成功
+     */
+    @Override
+    public Boolean updateByBo(SysFoodIngredientBo bo) {
+        SysFoodIngredient update = MapstructUtils.convert(bo, SysFoodIngredient.class);
+        validEntityBeforeSave(update);
+        return baseMapper.updateById(update) > 0;
+    }
+
+    /**
+     * 保存前的数据校验
+     */
+    private void validEntityBeforeSave(SysFoodIngredient entity) {
+        List<SysFoodIngredient> foodIngredients = baseMapper.selectList(Wrappers.lambdaQuery(SysFoodIngredient.class)
+            .eq(SysFoodIngredient::getName, entity.getName()));
+        if (ObjUtil.isNull(entity.getFoodIngredientId())) {
+            if (CollUtil.isNotEmpty(foodIngredients)) {
+                throw new ServiceException("食材名称已经存在!");
+            }
+        } else {
+            if (foodIngredients.size() > 1) {
+                throw new ServiceException("食材名称已经存在!");
+            }
+            if (!foodIngredients.get(0).getFoodIngredientId().equals(entity.getFoodIngredientId())) {
+                throw new ServiceException("食材名称已经存在!");
+            }
+        }
+    }
+
+    /**
+     * 校验并批量删除食材管理信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if (isValid) {
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return baseMapper.deleteByIds(ids) > 0;
+    }
+
+    @Override
+    public R<?> importExcel(MultipartFile file) throws Exception {
+        if (ObjUtil.isNull(file)) {
+            return R.fail("请选择文件!");
+        }
+
+        List<Map<Integer, String>> excelList = FastExcel.read(file.getInputStream())
+            .headRowNumber(3)
+            .sheet().doReadSync();
+
+        log.info("开始导入数据");
+        if (CollUtil.isEmpty(excelList)) {
+            return R.fail("读取数据为空!");
+        }
+        log.info("size:" + excelList.size());
+
+        List<SysFoodCategory> categoryList = categoryMapper.selectList(
+            Wrappers.lambdaQuery(SysFoodCategory.class).select(SysFoodCategory::getFoodCategoryId, SysFoodCategory::getName));
+        Map<String, String> categoryMap = categoryList.stream()
+            .collect(Collectors.toMap(k1 -> k1.getName(), k2 -> String.valueOf(k2.getFoodCategoryId()), (k1, k2) -> k1));
+        List<SysFoodIngredient> foodList = new ArrayList<>();
+        StringBuilder builder = new StringBuilder();
+        excelList.forEach(v -> {
+            if (MapUtil.isEmpty(v) || v.size() < 4) {
+                builder.append(foodList.size() + 4).append("、");
+                return;
+            }
+            SysFoodIngredient foodIngredient = new SysFoodIngredient();
+            foodIngredient.setName(v.get(0));
+            foodIngredient.setBigCategory(categoryMap.get(v.get(1)));
+            foodIngredient.setSubCategory(categoryMap.get(v.get(2)));
+            foodIngredient.setUnit(v.get(3));
+
+            String colVal = v.get(4);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行4列、");
+                    return;
+                } else {
+                    foodIngredient.setPurchasePrice(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(5);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行5列、");
+                    return;
+                } else {
+                    foodIngredient.setEdibleRatio(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(6);
+            if (StrUtil.isNotBlank(colVal)) {
+                foodIngredient.setDescription(colVal);
+            }
+
+            colVal = v.get(7);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行7列、");
+                    return;
+                } else {
+                    foodIngredient.setShelfLife(Long.valueOf(colVal));
+                }
+            }
+
+            colVal = v.get(8);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行8列、");
+                    return;
+                } else {
+                    foodIngredient.setExpiryWarning(Long.valueOf(colVal));
+                }
+            }
+
+            colVal = v.get(9);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行9列、");
+                    return;
+                } else {
+                    foodIngredient.setStockWarning(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(10);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行10列、");
+                    return;
+                } else {
+                    foodIngredient.setCalories(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(11);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行11列、");
+                    return;
+                } else {
+                    foodIngredient.setProtein(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(12);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行12列、");
+                    return;
+                } else {
+                    foodIngredient.setFat(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(13);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行13列、");
+                    return;
+                } else {
+                    foodIngredient.setCarbohydrate(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(14);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行14列、");
+                    return;
+                } else {
+                    foodIngredient.setWater(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(15);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行15列、");
+                    return;
+                } else {
+                    foodIngredient.setVitaminA(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(16);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行16列、");
+                    return;
+                } else {
+                    foodIngredient.setVitaminB2(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(17);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行17列、");
+                    return;
+                } else {
+                    foodIngredient.setVitaminC(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(18);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行18列、");
+                    return;
+                } else {
+                    foodIngredient.setSodium(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(19);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行19列、");
+                    return;
+                } else {
+                    foodIngredient.setIron(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(20);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行20列、");
+                    return;
+                } else {
+                    foodIngredient.setPhosphorus(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(21);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行21列、");
+                    return;
+                } else {
+                    foodIngredient.setDietaryFiber(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(22);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行22列、");
+                    return;
+                } else {
+                    foodIngredient.setVitaminB1(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(23);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行23列、");
+                    return;
+                } else {
+                    foodIngredient.setNiacin(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(24);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行24列、");
+                    return;
+                } else {
+                    foodIngredient.setVitaminE(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(25);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行25列、");
+                    return;
+                } else {
+                    foodIngredient.setCalcium(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(26);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("26、");
+                    return;
+                } else {
+                    foodIngredient.setPotassium(new BigDecimal(colVal));
+                }
+            }
+
+            colVal = v.get(27);
+            if (StrUtil.isNotBlank(colVal)) {
+                if (!NumberUtil.isNumber(colVal)) {
+                    builder.append(foodList.size() + 4).append("行27列、");
+                    return;
+                } else {
+                    foodIngredient.setCholesterol(new BigDecimal(colVal));
+                }
+            }
+
+            if (StrUtil.isBlank(foodIngredient.getName()) || StrUtil.isBlank(foodIngredient.getBigCategory())
+                || StrUtil.isBlank(foodIngredient.getSubCategory()) || StrUtil.isBlank(foodIngredient.getUnit())) {
+                builder.append(foodList.size() + 4).append("、");
+                return;
+            }
+            foodIngredient.setFoodCategoryId(foodIngredient.getBigCategory() + "," + foodIngredient.getSubCategory());
+            foodList.add(foodIngredient);
+        });
+
+        if (builder.length() == 0) {
+            foodList.forEach(fd -> {
+                fd.setCode(RedisUtil.generateFoodCode());
+            });
+            baseMapper.insertBatch(foodList);
+        } else {
+            return R.fail("以下行数据不完整:" + builder);
+        }
+
+        return R.ok("导入成功!");
+    }
+}

+ 7 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysFoodIngredientMapper.xml

@@ -0,0 +1,7 @@
+<?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="org.dromara.system.mapper.SysFoodIngredientMapper">
+
+</mapper>

+ 47 - 0
script/sql/biz/create.sql

@@ -80,3 +80,50 @@ INSERT INTO sys_food_category (name, parent_id, create_by, update_by) VALUES ('
 INSERT INTO sys_food_category (name, parent_id, create_by, update_by) VALUES ('全谷物和杂豆', 0, '1', '1');
 INSERT INTO sys_food_category (name, parent_id, create_by, update_by) VALUES ('薯类', 0, '1', '1');
 INSERT INTO sys_food_category (name, parent_id, create_by, update_by) VALUES ('水', 0, '1', '1');
+
+
+CREATE TABLE sys_food_ingredient (
+    food_ingredient_id     BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID',
+    food_category_id       VARCHAR(200) NOT NULL COMMENT '食材分类ID',
+    tenant_id varchar(20) default '000000' null comment '租户编号',
+    name                  VARCHAR(100) NOT NULL COMMENT '食材名称',
+    code                  VARCHAR(50) NOT NULL COMMENT '食材编码',
+    unit                  VARCHAR(20) NOT NULL COMMENT '单位',
+    purchase_price        DECIMAL(10,2)   COMMENT '入货价格(元)',
+    edible_ratio          DECIMAL(5,2) DEFAULT 100.00 COMMENT '食材可食比例构成(%)',
+    shelf_life            INT COMMENT '保质期(天)',
+    stock_warning         DECIMAL(10,2) COMMENT '库存预警值(g)',
+    expiry_warning        INT COMMENT '保质期预警(天)',
+    description           TEXT COMMENT '食材描述',
+
+    -- 营养成分
+    calories              DECIMAL(8,2) DEFAULT 0.00 COMMENT '热量(kcal)',
+    protein               DECIMAL(8,2) DEFAULT 0.00 COMMENT '蛋白质(g)',
+    fat                   DECIMAL(8,2) DEFAULT 0.00 COMMENT '脂肪(g)',
+    carbohydrate          DECIMAL(8,2) DEFAULT 0.00 COMMENT '碳水化合物(g)',
+    water                 DECIMAL(8,2) DEFAULT 0.00 COMMENT '水分(ml)',
+    vitamin_a             DECIMAL(8,2) DEFAULT 0.00 COMMENT '维生素A(μg)',
+    vitamin_b2            DECIMAL(8,2) DEFAULT 0.00 COMMENT '维生素B2(mg)',
+    vitamin_c             DECIMAL(8,2) DEFAULT 0.00 COMMENT '维生素C(mg)',
+    sodium                DECIMAL(8,2) DEFAULT 0.00 COMMENT '钠(mg)',
+    iron                  DECIMAL(8,2) DEFAULT 0.00 COMMENT '铁(mg)',
+    phosphorus            DECIMAL(8,2) DEFAULT 0.00 COMMENT '磷(mg)',
+    dietary_fiber         DECIMAL(8,2) DEFAULT 0.00 COMMENT '膳食纤维(g)',
+    vitamin_b1            DECIMAL(8,2) DEFAULT 0.00 COMMENT '维生素B1(mg)',
+    niacin                DECIMAL(8,2) DEFAULT 0.00 COMMENT '烟酸(mg)',
+    vitamin_e             DECIMAL(8,2) DEFAULT 0.00 COMMENT '维生素E(mg)',
+    calcium               DECIMAL(8,2) DEFAULT 0.00 COMMENT '钙(mg)',
+    potassium             DECIMAL(8,2) DEFAULT 0.00 COMMENT '钾(mg)',
+    cholesterol           DECIMAL(8,2) DEFAULT 0.00 COMMENT '胆固醇(g)',
+
+    -- 系统字段
+    status CHAR(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
+    del_flag char default '0' null comment '删除标志(0代表存在 1代表删除)',
+    create_dept  bigint null comment '创建部门',
+    create_by VARCHAR(64) DEFAULT '' COMMENT '创建者',
+    create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+    update_by VARCHAR(64) DEFAULT '' COMMENT '更新者',
+    update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间'
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='食材管理表';
+
+