新增食材管理

This commit is contained in:
huangdeliang
2020-12-16 22:10:20 +08:00
parent 27bf41b006
commit d1786f5327
7 changed files with 346 additions and 200 deletions

View File

@ -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;
}

View File

@ -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 +
'}';
}
}

View File

@ -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 +
'}';
}
}

View File

@ -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<SysIngredientRec> ingredientRecList);
public int batchIngredientNotRec(List<SysIngredientNotRec> ingredientNotRecList);
public int deleteIngredentRecByIngredientId(Long recId);
public int deleteIngredentNotRecByIngredientId(Long notRecId);
}

View File

@ -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<SysIngredient> selectSysIngredientList(SysIngredient sysIngredient)
{
public List<SysIngredient> 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<SysIngredientRec> list = new ArrayList<SysIngredientRec>();
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<SysIngredientNotRec> list = new ArrayList<SysIngredientNotRec>();
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);
}
}