From 46f2b7c46f1798039ccf010f35dad9180bdbb820 Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 31 Dec 2020 16:11:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=8F=9C=E5=93=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/SysDishesController.java | 62 ++--- .../custom/SysIngredientController.java | 8 + .../com/stdiet/custom/domain/SysDishes.java | 12 + .../custom/domain/SysDishesIngredient.java | 76 ++++++ .../stdiet/custom/domain/SysIngredient.java | 45 ---- .../stdiet/custom/mapper/SysDishesMapper.java | 12 + .../custom/mapper/SysIngredientMapper.java | 4 + .../custom/service/ISysDishesService.java | 4 + .../service/impl/SysDishesServiceImpl.java | 85 ++++--- .../impl/SysIngredientServiceImpl.java | 2 + .../mapper/custom/SysDishesMapper.xml | 65 +++++ .../mapper/custom/SysIngredientMapper.xml | 14 ++ stdiet-ui/src/api/custom/ingredient.js | 13 + stdiet-ui/src/views/custom/dishes/index.vue | 223 ++++++++++++++---- 14 files changed, 480 insertions(+), 145 deletions(-) create mode 100644 stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishesIngredient.java diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysDishesController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysDishesController.java index 6366a249c..f4254c312 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysDishesController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysDishesController.java @@ -1,35 +1,33 @@ package com.stdiet.web.controller.custom; -import java.util.List; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.stdiet.common.annotation.Log; import com.stdiet.common.core.controller.BaseController; import com.stdiet.common.core.domain.AjaxResult; -import com.stdiet.common.enums.BusinessType; -import com.stdiet.custom.domain.SysDishes; -import com.stdiet.custom.service.ISysDishesService; -import com.stdiet.common.utils.poi.ExcelUtil; import com.stdiet.common.core.page.TableDataInfo; +import com.stdiet.common.enums.BusinessType; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.common.utils.poi.ExcelUtil; +import com.stdiet.custom.domain.SysDishes; +import com.stdiet.custom.domain.SysDishesIngredient; +import com.stdiet.custom.domain.SysIngredient; +import com.stdiet.custom.service.ISysDishesService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; /** * 菜品Controller - * + * * @author wonder * @date 2020-12-28 */ @RestController @RequestMapping("/custom/dishes") -public class SysDishesController extends BaseController -{ +public class SysDishesController extends BaseController { @Autowired private ISysDishesService sysDishesService; @@ -38,10 +36,17 @@ public class SysDishesController extends BaseController */ @PreAuthorize("@ss.hasPermi('custom:dishes:list')") @GetMapping("/list") - public TableDataInfo list(SysDishes sysDishes) - { + public TableDataInfo list(SysDishes sysDishes) { startPage(); List list = sysDishesService.selectSysDishesList(sysDishes); + for (SysDishes dishes : list) { + List ingredients = sysDishesService.selectSysIngreditentsById(dishes.getId()); + if (StringUtils.isNull(ingredients)) { + dishes.setIgdList(new ArrayList<>()); + } else { + dishes.setIgdList(ingredients); + } + } return getDataTable(list); } @@ -51,8 +56,7 @@ public class SysDishesController extends BaseController @PreAuthorize("@ss.hasPermi('custom:dishes:export')") @Log(title = "菜品", businessType = BusinessType.EXPORT) @GetMapping("/export") - public AjaxResult export(SysDishes sysDishes) - { + public AjaxResult export(SysDishes sysDishes) { List list = sysDishesService.selectSysDishesList(sysDishes); ExcelUtil util = new ExcelUtil(SysDishes.class); return util.exportExcel(list, "dishes"); @@ -63,8 +67,7 @@ public class SysDishesController extends BaseController */ @PreAuthorize("@ss.hasPermi('custom:dishes:query')") @GetMapping(value = "/{id}") - public AjaxResult getInfo(@PathVariable("id") Long id) - { + public AjaxResult getInfo(@PathVariable("id") Long id) { return AjaxResult.success(sysDishesService.selectSysDishesById(id)); } @@ -74,8 +77,7 @@ public class SysDishesController extends BaseController @PreAuthorize("@ss.hasPermi('custom:dishes:add')") @Log(title = "菜品", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody SysDishes sysDishes) - { + public AjaxResult add(@RequestBody SysDishes sysDishes) { return toAjax(sysDishesService.insertSysDishes(sysDishes)); } @@ -85,8 +87,7 @@ public class SysDishesController extends BaseController @PreAuthorize("@ss.hasPermi('custom:dishes:edit')") @Log(title = "菜品", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody SysDishes sysDishes) - { + public AjaxResult edit(@RequestBody SysDishes sysDishes) { return toAjax(sysDishesService.updateSysDishes(sysDishes)); } @@ -95,9 +96,8 @@ public class SysDishesController extends BaseController */ @PreAuthorize("@ss.hasPermi('custom:dishes:remove')") @Log(title = "菜品", businessType = BusinessType.DELETE) - @DeleteMapping("/{ids}") - public AjaxResult remove(@PathVariable Long[] ids) - { + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) { return toAjax(sysDishesService.deleteSysDishesByIds(ids)); } } \ No newline at end of file diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java index a4ec6ab63..f8100f17f 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/SysIngredientController.java @@ -45,6 +45,14 @@ public class SysIngredientController extends BaseController return getDataTable(list); } + @PreAuthorize("@ss.hasPermi('custom:ingredient:list')") + @PostMapping("/listAll") + public TableDataInfo listAll(@RequestBody SysIngredient sysIngredient) + { + List list = sysIngredientService.selectSysIngredientList(sysIngredient); + return getDataTable(list); + } + /** * 导出食材列表 */ diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishes.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishes.java index cd23e764a..f4b9f2b81 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishes.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishes.java @@ -5,6 +5,8 @@ import org.apache.commons.lang3.builder.ToStringStyle; import com.stdiet.common.annotation.Excel; import com.stdiet.common.core.domain.BaseEntity; +import java.util.List; + /** * 菜品对象 sys_dishes * @@ -30,6 +32,8 @@ public class SysDishes extends BaseEntity @Excel(name = "做法") private String methods; + private List igdList; + public void setId(Long id) { this.id = id; @@ -67,6 +71,14 @@ public class SysDishes extends BaseEntity return methods; } + public void setIgdList(List ingredientList) { + this.igdList = ingredientList; + } + + public List getIgdList() { + return igdList; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishesIngredient.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishesIngredient.java new file mode 100644 index 000000000..fec0ce9db --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysDishesIngredient.java @@ -0,0 +1,76 @@ +package com.stdiet.custom.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; + +/** + * 菜品对象 sys_dishes + * + * @author wonder + * @date 2020-12-28 + */ +public class SysDishesIngredient extends SysIngredient { + + private Long ingredientId; + + private Long dishesId; + + private Long cusUnit; + + private BigDecimal cusWeight; + + private BigDecimal weight; + + public Long getIngredientId() { + return ingredientId; + } + + public void setIngredientId(Long ingredientId) { + this.ingredientId = ingredientId; + } + + public Long getDishesId() { + return dishesId; + } + + public void setDishesId(Long dishesId) { + this.dishesId = dishesId; + } + + public BigDecimal getWeight() { + return weight; + } + + public void setWeight(BigDecimal weight) { + this.weight = weight; + } + + public BigDecimal getCusWeight() { + return cusWeight; + } + + public void setCusWeight(BigDecimal cusWeight) { + this.cusWeight = cusWeight; + } + + public Long getCusUnit() { + return cusUnit; + } + + public void setCusUnit(Long cusUnit) { + this.cusUnit = cusUnit; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("ingredientId", getIngredientId()) + .append("dishesId", getDishesId()) + .append("weight", getWeight()) + .append("cusWeight", getCusWeight()) + .append("cusUnit", getCusUnit()) + .toString(); + } +} \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java index e199f4de1..716a7614f 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredient.java @@ -33,24 +33,6 @@ public class SysIngredient extends BaseEntity { @Excel(name = "食材类别") private String type; - /** - * 推荐分量估算 - */ - @Excel(name = "推荐分量估算") - private Long recEstimation; - - /** - * 推荐分量估算单位id - */ - @Excel(name = "推荐分量估算单位id") - private Long recEstUnit; - - /** - * 推荐分量 - */ - @Excel(name = "推荐分量") - private Long recPortion; - /** * 蛋白质比例 */ @@ -123,30 +105,6 @@ public class SysIngredient extends BaseEntity { this.type = type; } - public Long getRecEstimation() { - return recEstimation; - } - - public void setRecEstimation(Long recEstimation) { - this.recEstimation = recEstimation; - } - - public Long getRecEstUnit() { - return recEstUnit; - } - - public void setRecEstUnit(Long recEstUnit) { - this.recEstUnit = recEstUnit; - } - - public Long getRecPortion() { - return recPortion; - } - - public void setRecPortion(Long recPortion) { - this.recPortion = recPortion; - } - public BigDecimal getProteinRatio() { return proteinRatio; } @@ -201,9 +159,6 @@ public class SysIngredient extends BaseEntity { .append("id", getId()) .append("name", getName()) .append("type", getType()) - .append("recEstimation", getRecEstimation()) - .append("recEstUnit", getRecEstUnit()) - .append("recPortion", getRecPortion()) .append("proteinRatio", getProteinRatio()) .append("fatRatio", getFatRatio()) .append("carbonRatio", getCarbonRatio()) diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysDishesMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysDishesMapper.java index e24d49a5b..262325752 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysDishesMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysDishesMapper.java @@ -1,7 +1,11 @@ package com.stdiet.custom.mapper; +import java.lang.reflect.Array; +import java.util.ArrayList; import java.util.List; import com.stdiet.custom.domain.SysDishes; +import com.stdiet.custom.domain.SysDishesIngredient; +import com.stdiet.custom.domain.SysIngredient; /** * 菜品Mapper接口 @@ -19,6 +23,8 @@ public interface SysDishesMapper */ public SysDishes selectSysDishesById(Long id); + public ArrayList selectSysIngreditentsById(Long id); + /** * 查询菜品列表 * @@ -58,4 +64,10 @@ public interface SysDishesMapper * @return 结果 */ public int deleteSysDishesByIds(Long[] ids); + + public int deleteIngredientById(Long id); + + public int deleteIngredientByIds(Long[] ids); + + public int bashInsertDishesIngredent(List sysDishesIngredients); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java index 8c8c527f8..bb6c4aa5b 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/mapper/SysIngredientMapper.java @@ -68,4 +68,8 @@ public interface SysIngredientMapper public int deleteIngredentRecByIngredientId(Long recId); public int deleteIngredentNotRecByIngredientId(Long notRecId); + + public int deleteIngredentRecByIngredientIds(Long[] id); + + public int deleteIngredentNotRecByIngredientIds(Long[] id); } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysDishesService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysDishesService.java index c3def4487..e279b2eac 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysDishesService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/ISysDishesService.java @@ -2,6 +2,8 @@ package com.stdiet.custom.service; import java.util.List; import com.stdiet.custom.domain.SysDishes; +import com.stdiet.custom.domain.SysDishesIngredient; +import com.stdiet.custom.domain.SysIngredient; /** * 菜品Service接口 @@ -19,6 +21,8 @@ public interface ISysDishesService */ public SysDishes selectSysDishesById(Long id); + public List selectSysIngreditentsById(Long id); + /** * 查询菜品列表 * diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysDishesServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysDishesServiceImpl.java index bcdcbbd2a..4d6945f3c 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysDishesServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysDishesServiceImpl.java @@ -1,96 +1,127 @@ package com.stdiet.custom.service.impl; -import java.util.List; import com.stdiet.common.utils.DateUtils; +import com.stdiet.common.utils.StringUtils; +import com.stdiet.custom.domain.SysDishes; +import com.stdiet.custom.domain.SysDishesIngredient; +import com.stdiet.custom.mapper.SysDishesMapper; +import com.stdiet.custom.service.ISysDishesService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.stdiet.custom.mapper.SysDishesMapper; -import com.stdiet.custom.domain.SysDishes; -import com.stdiet.custom.service.ISysDishesService; + +import java.util.ArrayList; +import java.util.List; /** * 菜品Service业务层处理 - * + * * @author wonder * @date 2020-12-28 */ @Service -public class SysDishesServiceImpl implements ISysDishesService -{ +public class SysDishesServiceImpl implements ISysDishesService { @Autowired private SysDishesMapper sysDishesMapper; /** * 查询菜品 - * + * * @param id 菜品ID * @return 菜品 */ @Override - public SysDishes selectSysDishesById(Long id) - { - return sysDishesMapper.selectSysDishesById(id); + public SysDishes selectSysDishesById(Long id) { + SysDishes dishes = sysDishesMapper.selectSysDishesById(id); + if (StringUtils.isNotNull(dishes)) { + List ingredientArray = selectSysIngreditentsById(id); + if (StringUtils.isNull(ingredientArray)) { + dishes.setIgdList(new ArrayList<>()); + } else { + dishes.setIgdList(ingredientArray); + } + + } + return dishes; + } + + @Override + public List selectSysIngreditentsById(Long id) { + return sysDishesMapper.selectSysIngreditentsById(id); } /** * 查询菜品列表 - * + * * @param sysDishes 菜品 * @return 菜品 */ @Override - public List selectSysDishesList(SysDishes sysDishes) - { + public List selectSysDishesList(SysDishes sysDishes) { return sysDishesMapper.selectSysDishesList(sysDishes); } /** * 新增菜品 - * + * * @param sysDishes 菜品 * @return 结果 */ @Override - public int insertSysDishes(SysDishes sysDishes) - { + public int insertSysDishes(SysDishes sysDishes) { sysDishes.setCreateTime(DateUtils.getNowDate()); - return sysDishesMapper.insertSysDishes(sysDishes); + int rows = sysDishesMapper.insertSysDishes(sysDishes); + // + insertDishesIngredient(sysDishes); + return rows; + } + + public void insertDishesIngredient(SysDishes sysDishes) { + if (StringUtils.isNotNull(sysDishes.getIgdList())) { + List list = sysDishes.getIgdList(); + for (SysDishesIngredient dishesIngredient : list) { + dishesIngredient.setDishesId(sysDishes.getId()); + dishesIngredient.setIngredientId(dishesIngredient.getId()); + } + sysDishesMapper.bashInsertDishesIngredent(list); + } } /** * 修改菜品 - * + * * @param sysDishes 菜品 * @return 结果 */ @Override - public int updateSysDishes(SysDishes sysDishes) - { + public int updateSysDishes(SysDishes sysDishes) { sysDishes.setUpdateTime(DateUtils.getNowDate()); + Long dishesId = sysDishes.getId(); + sysDishesMapper.deleteIngredientById(dishesId); + insertDishesIngredient(sysDishes); return sysDishesMapper.updateSysDishes(sysDishes); } /** * 批量删除菜品 - * + * * @param ids 需要删除的菜品ID * @return 结果 */ @Override - public int deleteSysDishesByIds(Long[] ids) - { + public int deleteSysDishesByIds(Long[] ids) { + sysDishesMapper.deleteIngredientByIds(ids); return sysDishesMapper.deleteSysDishesByIds(ids); } /** * 删除菜品信息 - * + * * @param id 菜品ID * @return 结果 */ @Override - public int deleteSysDishesById(Long id) - { + public int deleteSysDishesById(Long id) { + sysDishesMapper.deleteIngredientById(id); return sysDishesMapper.deleteSysDishesById(id); } } \ No newline at end of file diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java index 1838b4128..eff3414a4 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/SysIngredientServiceImpl.java @@ -128,6 +128,8 @@ public class SysIngredientServiceImpl implements ISysIngredientService { */ @Override public int deleteSysIngredientByIds(Long[] ids) { + sysIngredientMapper.deleteIngredentRecByIngredientIds(ids); + sysIngredientMapper.deleteIngredentNotRecByIngredientIds(ids); return sysIngredientMapper.deleteSysIngredientByIds(ids); } diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysDishesMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysDishesMapper.xml index 32b0dce05..dc144f090 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysDishesMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysDishesMapper.xml @@ -15,6 +15,21 @@ + + + + + + + + + + + + + + + select id, name, type, methods, create_by, create_time, update_by, update_time from sys_dishes @@ -27,6 +42,38 @@ + + SELECT * FROM( + SELECT ingredient_id AS id, ingredient_weight AS weight, cus_weight, cus_unit + FROM sys_dishes_ingredient + WHERE dishes_id = #{id} + ) dishes + LEFT JOIN ( + SELECT id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, not_rec, rec + FROM sys_ingredient igd + LEFT JOIN ( + SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') not_rec FROM( + SELECT physical_signs_id as id, ingredient_id + FROM sys_ingredient_not_rec + ) notRec JOIN sys_physical_signs phy USING(id) + GROUP BY id + ) notRecT USING(id) + LEFT JOIN ( + SELECT ingredient_id as id, GROUP_CONCAT(name SEPARATOR ',') rec FROM( + SELECT physical_signs_id as id, ingredient_id + FROM sys_ingredient_rec + ) rec JOIN sys_physical_signs phy USING(id) + GROUP BY id + ) recT USING(id) + ) ing USING(id) + + + +