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 77494dfc4..26c48fc85 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 @@ -63,7 +63,27 @@ public class SysIngredient extends BaseEntity @Excel(name = "推荐") private String recommend; - public void setId(Long id) + private Long[] recIds; + + private Long[] notRecIds; + + public Long[] getRecIds() { + return recIds; + } + + public Long[] getNotRecIds() { + return notRecIds; + } + + public void setNotRecIds(Long[] notRecIds) { + this.notRecIds = notRecIds; + } + + public void setRedIds(Long[] recIds) { + this.recIds = recIds; + } + + public void setId(Long id) { this.id = id; } @@ -153,21 +173,21 @@ public class SysIngredient extends BaseEntity { return area; } - public void setNotRec(String notRec) + public void setNotRec(String notRec) { this.notRec = notRec; } - public String getNotRec() + public String getNotRec() { return notRec; } - public void setRecommend(String recommend) + public void setRecommend(String recommend) { this.recommend = recommend; } - public String getRecommend() + public String getRecommend() { return recommend; } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java new file mode 100644 index 000000000..059347528 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientNotRec.java @@ -0,0 +1,30 @@ +package com.stdiet.custom.domain; + +public class SysIngredientNotRec { + private Long ingredientId; + private Long notRecommandId; + + public Long getIngredientId() { + return ingredientId; + } + + public void setIngredientId(Long ingredientId) { + this.ingredientId = ingredientId; + } + + public Long getRecommandId() { + return notRecommandId; + } + + public void setRecommandId(Long recommandId) { + this.notRecommandId = recommandId; + } + + @Override + public String toString() { + return "SysIngredientRec{" + + "ingredientId=" + ingredientId + + ", notRecommandId=" + notRecommandId + + '}'; + } +} diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java new file mode 100644 index 000000000..c1cb0ec09 --- /dev/null +++ b/stdiet-custom/src/main/java/com/stdiet/custom/domain/SysIngredientRec.java @@ -0,0 +1,30 @@ +package com.stdiet.custom.domain; + +public class SysIngredientRec { + private Long ingredientId; + private Long recommandId; + + public Long getIngredientId() { + return ingredientId; + } + + public void setIngredientId(Long ingredientId) { + this.ingredientId = ingredientId; + } + + public Long getRecommandId() { + return recommandId; + } + + public void setRecommandId(Long recommandId) { + this.recommandId = recommandId; + } + + @Override + public String toString() { + return "SysIngredientRec{" + + "ingredientId=" + ingredientId + + ", recommandId=" + recommandId + + '}'; + } +} 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 4a8ee6f04..8c8c527f8 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 @@ -2,6 +2,8 @@ package com.stdiet.custom.mapper; import java.util.List; import com.stdiet.custom.domain.SysIngredient; +import com.stdiet.custom.domain.SysIngredientNotRec; +import com.stdiet.custom.domain.SysIngredientRec; /** * 食材Mapper接口 @@ -58,4 +60,12 @@ public interface SysIngredientMapper * @return 结果 */ public int deleteSysIngredientByIds(Long[] ids); + + public int batchIngredientRec(List ingredientRecList); + + public int batchIngredientNotRec(List ingredientNotRecList); + + public int deleteIngredentRecByIngredientId(Long recId); + + public int deleteIngredentNotRecByIngredientId(Long notRecId); } \ 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 b8f3ae61d..1838b4128 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 @@ -1,96 +1,146 @@ 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.SysIngredient; +import com.stdiet.custom.domain.SysIngredientNotRec; +import com.stdiet.custom.domain.SysIngredientRec; +import com.stdiet.custom.mapper.SysIngredientMapper; +import com.stdiet.custom.service.ISysIngredientService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.stdiet.custom.mapper.SysIngredientMapper; -import com.stdiet.custom.domain.SysIngredient; -import com.stdiet.custom.service.ISysIngredientService; + +import java.util.ArrayList; +import java.util.List; /** * 食材Service业务层处理 - * + * * @author wonder * @date 2020-12-15 */ @Service -public class SysIngredientServiceImpl implements ISysIngredientService -{ +public class SysIngredientServiceImpl implements ISysIngredientService { @Autowired private SysIngredientMapper sysIngredientMapper; /** * 查询食材 - * + * * @param id 食材ID * @return 食材 */ @Override - public SysIngredient selectSysIngredientById(Long id) - { + public SysIngredient selectSysIngredientById(Long id) { return sysIngredientMapper.selectSysIngredientById(id); } /** * 查询食材列表 - * + * * @param sysIngredient 食材 * @return 食材 */ @Override - public List selectSysIngredientList(SysIngredient sysIngredient) - { + public List selectSysIngredientList(SysIngredient sysIngredient) { return sysIngredientMapper.selectSysIngredientList(sysIngredient); } /** * 新增食材 - * + * * @param sysIngredient 食材 * @return 结果 */ @Override - public int insertSysIngredient(SysIngredient sysIngredient) - { + public int insertSysIngredient(SysIngredient sysIngredient) { sysIngredient.setCreateTime(DateUtils.getNowDate()); - return sysIngredientMapper.insertSysIngredient(sysIngredient); + int rows = sysIngredientMapper.insertSysIngredient(sysIngredient); + // + insertRecommand(sysIngredient); + // + insertNotRecommand(sysIngredient); + return rows; + } + + /** + * 新增推荐标签 + * @param ingredient + */ + public void insertRecommand(SysIngredient ingredient) { + Long[] recIds = ingredient.getRecIds(); + if(StringUtils.isNotNull(recIds)) { + List list = new ArrayList(); + for(Long recId: recIds) { + SysIngredientRec rec = new SysIngredientRec(); + rec.setIngredientId(ingredient.getId()); + rec.setRecommandId(recId); + list.add(rec); + } + if(list.size() > 0) { + sysIngredientMapper.batchIngredientRec(list); + } + } + } + + /** + * 新增不推荐标签 + * @param ingredient + */ + public void insertNotRecommand(SysIngredient ingredient) { + Long[] notRecIds = ingredient.getNotRecIds(); + if(StringUtils.isNotNull(notRecIds)) { + List list = new ArrayList(); + for(Long recId: notRecIds) { + SysIngredientNotRec notRec = new SysIngredientNotRec(); + notRec.setIngredientId(ingredient.getId()); + notRec.setRecommandId(recId); + list.add(notRec); + } + if(list.size() > 0) { + sysIngredientMapper.batchIngredientNotRec(list); + } + } } /** * 修改食材 - * + * * @param sysIngredient 食材 * @return 结果 */ @Override - public int updateSysIngredient(SysIngredient sysIngredient) - { + public int updateSysIngredient(SysIngredient sysIngredient) { sysIngredient.setUpdateTime(DateUtils.getNowDate()); + Long ingredientId = sysIngredient.getId(); + sysIngredientMapper.deleteIngredentNotRecByIngredientId(ingredientId); + insertNotRecommand(sysIngredient); + sysIngredientMapper.deleteIngredentRecByIngredientId(ingredientId); + insertRecommand(sysIngredient); return sysIngredientMapper.updateSysIngredient(sysIngredient); } /** * 批量删除食材 - * + * * @param ids 需要删除的食材ID * @return 结果 */ @Override - public int deleteSysIngredientByIds(Long[] ids) - { + public int deleteSysIngredientByIds(Long[] ids) { return sysIngredientMapper.deleteSysIngredientByIds(ids); } /** * 删除食材信息 - * + * * @param id 食材ID * @return 结果 */ @Override - public int deleteSysIngredientById(Long id) - { + public int deleteSysIngredientById(Long id) { + sysIngredientMapper.deleteIngredentRecByIngredientId(id); + sysIngredientMapper.deleteIngredentNotRecByIngredientId(id); return sysIngredientMapper.deleteSysIngredientById(id); } } \ No newline at end of file diff --git a/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml b/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml index 890f60ccc..c0a372b9c 100644 --- a/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml +++ b/stdiet-custom/src/main/resources/mapper/custom/SysIngredientMapper.xml @@ -8,16 +8,11 @@ - - - - - - + @@ -25,7 +20,7 @@ - select id, name, type, rec_estimation, rec_est_unit, rec_portion, protein_ratio, fat_ratio, carbon_ratio, remark, area, not_rec, recommend, create_by, create_time, update_by, update_time from sys_ingredient + select id, name, type, protein_ratio, fat_ratio, carbon_ratio, area, remark, create_by, create_time, update_by, update_time from sys_ingredient @@ -49,16 +42,11 @@ name, type, - rec_estimation, - rec_est_unit, - rec_portion, protein_ratio, fat_ratio, carbon_ratio, - remark, area, - not_rec, - recommend, + remark, create_by, create_time, update_by, @@ -67,16 +55,11 @@ #{name}, #{type}, - #{recEstimation}, - #{recEstUnit}, - #{recPortion}, #{proteinRatio}, #{fatRatio}, #{carbonRatio}, - #{remark}, #{area}, - #{notRec}, - #{recommend}, + #{remark}, #{createBy}, #{createTime}, #{updateBy}, @@ -84,21 +67,38 @@ + + insert into sys_ingredient_rec(ingredient_id, rec_id) values + + (#{item.ingredientId},#{item.recommandId}) + + + + + insert into sys_ingredient_not_rec(ingredient_id, not_rec_id) values + + (#{item.ingredientId},#{item.notRecommandId}) + + + + + delete from sys_ingredient_rec where ingredient_id=#{ingredientId} + + + + delete from sys_ingredient_not_rec where ingredient_id=#{ingredientId} + + update sys_ingredient name = #{name}, type = #{type}, - rec_estimation = #{recEstimation}, - rec_est_unit = #{recEstUnit}, - rec_portion = #{recPortion}, protein_ratio = #{proteinRatio}, fat_ratio = #{fatRatio}, carbon_ratio = #{carbonRatio}, - remark = #{remark}, area = #{area}, - not_rec = #{notRec}, - recommend = #{recommend}, + remark = #{remark}, create_by = #{createBy}, create_time = #{createTime}, update_by = #{updateBy}, diff --git a/stdiet-ui/src/views/custom/ingredient/index.vue b/stdiet-ui/src/views/custom/ingredient/index.vue index 4003b523f..1ad31bbfa 100644 --- a/stdiet-ui/src/views/custom/ingredient/index.vue +++ b/stdiet-ui/src/views/custom/ingredient/index.vue @@ -44,28 +44,31 @@ size="mini" @click="handleAdd" v-hasPermi="['custom:ingredient:add']" - >新增 - - - 修改 - - - 删除 + >新增 + + + + + + + + + + + + + + + + + + + + + + + 导出 + >导出 + - - - - - - - - - - - - - - + + + + + + + + + + + @@ -122,80 +125,87 @@ /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{dict.dictLabel}} - - - - - - - {{dict.dictLabel}} - - - - - - - + + + + + + + + + + + + /100g + + + + + + /100g + + + + + + /100g + + + + + + + + + + + + + + + + + + + + + {{dict.dictLabel}} + + + + + + + + + {{dict.dictLabel}} + + + + + + + + + + +