diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/fantang/controller/FtCateringDaoController.java b/ruoyi-system/src/main/java/com/ruoyi/system/fantang/controller/FtCateringDaoController.java index d544628b6..135044c17 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/fantang/controller/FtCateringDaoController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/fantang/controller/FtCateringDaoController.java @@ -1,6 +1,7 @@ package com.ruoyi.system.fantang.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -8,7 +9,9 @@ import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.fantang.domain.FtCateringDao; +import com.ruoyi.system.fantang.domain.FtFoodDemandDao; import com.ruoyi.system.fantang.service.IFtCateringDaoService; +import com.ruoyi.system.fantang.service.IFtFoodDemandDaoService; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; @@ -31,6 +34,8 @@ public class FtCateringDaoController extends BaseController { private final IFtCateringDaoService iFtCateringDaoService; + private final IFtFoodDemandDaoService iFtFoodDemandDaoService; + /** * 查询配餐功能列表 */ @@ -74,8 +79,9 @@ public class FtCateringDaoController extends BaseController { public AjaxResult add(@RequestBody FtCateringDao ftCateringDao) { List types = ftCateringDao.getTypes(); for (Integer type : types) { + Long patientId = ftCateringDao.getPatientId(); FtCateringDao ftCatering = new FtCateringDao(); - ftCatering.setPatientId(ftCateringDao.getPatientId()); + ftCatering.setPatientId(patientId); ftCatering.setNumber(ftCateringDao.getNumber()); ftCatering.setFrequency(ftCateringDao.getFrequency()); ftCatering.setCateringUsage(ftCateringDao.getCateringUsage()); @@ -83,6 +89,26 @@ public class FtCateringDaoController extends BaseController { ftCatering.setCreateAt(new Date()); ftCatering.setType(type); iFtCateringDaoService.save(ftCatering); + + // 如果属于加餐,新增一条病患配餐记录,否则修改 + if (type == 4) { + FtFoodDemandDao foodDemandDao = new FtFoodDemandDao(); + foodDemandDao.setPatientId(patientId); + foodDemandDao.setType(type); + foodDemandDao.setNutritionFoodId(ftCateringDao.getNumber()); + foodDemandDao.setNutritionFoodFlag(1); + foodDemandDao.setCreateAt(new Date()); + iFtFoodDemandDaoService.save(foodDemandDao); + } else { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("patient_id", patientId); + wrapper.eq("type", type); + FtFoodDemandDao foodDemandDao = iFtFoodDemandDaoService.getOne(wrapper); + foodDemandDao.setNutritionFoodId(ftCateringDao.getNumber()); + foodDemandDao.setNutritionFoodFlag(1); + foodDemandDao.setUpdateAt(new Date()); + iFtFoodDemandDaoService.updateById(foodDemandDao); + } } return AjaxResult.success("新增成功"); @@ -95,6 +121,20 @@ public class FtCateringDaoController extends BaseController { @Log(title = "配餐功能", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody FtCateringDao ftCateringDao) { + + Long patientId = ftCateringDao.getPatientId(); + Integer type = ftCateringDao.getType(); + Long number = ftCateringDao.getNumber(); + + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("patient_id", patientId); + wrapper.eq("type", type); + FtFoodDemandDao foodDemandDao = iFtFoodDemandDaoService.getOne(wrapper); + foodDemandDao.setNutritionFoodId(number); + foodDemandDao.setNutritionFoodFlag(1); + foodDemandDao.setUpdateAt(new Date()); + iFtFoodDemandDaoService.updateById(foodDemandDao); + return toAjax(iFtCateringDaoService.updateById(ftCateringDao) ? 1 : 0); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/fantang/domain/FtFoodDemandDao.java b/ruoyi-system/src/main/java/com/ruoyi/system/fantang/domain/FtFoodDemandDao.java index 034a0f1ac..abcc64f46 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/fantang/domain/FtFoodDemandDao.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/fantang/domain/FtFoodDemandDao.java @@ -52,7 +52,7 @@ public class FtFoodDemandDao extends BasePatient implements Serializable { * 正餐类型 */ @Excel(name = "正餐类型") - private Long type; + private Integer type; /** * 创建时间 diff --git a/ruoyi-ui/src/views/fantang/foodDemand/index.vue b/ruoyi-ui/src/views/fantang/foodDemand/index.vue index 030bfed98..22e838178 100644 --- a/ruoyi-ui/src/views/fantang/foodDemand/index.vue +++ b/ruoyi-ui/src/views/fantang/foodDemand/index.vue @@ -274,23 +274,25 @@ export default { // 格式化菜单回显文字 formatFoods(row) { const _this = this; - let arr = row.foods.split(",").map(Number); - let ret = arr.map(item => { - let obj = _this.foodList.find((value => { - return value.foodId === item; - })); - return obj.name; - }); - let str = ret.toString(); - if (row.vegetables > 0) - str += ",加菜"; - if (row.rice > 0) - str += ",加饭" - if (row.meat > 0) - str += ",加肉" - if (row.egg > 0) - str += ",加蛋" + row.egg; - return str; + if (row.foods!=null){ + let arr = row.foods.split(",").map(Number); + let ret = arr.map(item => { + let obj = _this.foodList.find((value => { + return value.foodId === item; + })); + return obj.name; + }); + let str = ret.toString(); + if (row.vegetables > 0) + str += ",加菜"; + if (row.rice > 0) + str += ",加饭" + if (row.meat > 0) + str += ",加肉" + if (row.egg > 0) + str += ",加蛋" + row.egg; + return str; + } }, formatVegetables(row) { if (row.vegetables) @@ -319,8 +321,8 @@ export default { listFoodDemand(this.queryParams).then(response => { this.foodDemandList = response.rows; this.total = response.total; - this.loading = false; + console.log(response.rows) }); }, // 正餐类型字典翻译 @@ -385,7 +387,9 @@ export default { const id = row.id || this.ids getFoodDemand(id).then(response => { this.form = response.data; - this.form.foods = this.form.foods.split(",").map(Number); + if (this.form.foods!=null){ + this.form.foods = this.form.foods.split(",").map(Number); + } this.form.type = this.selectDictLabel(this.typeOptions, row.type); this.open = true; this.title = "修改病人报餐";