当前菜谱bind
This commit is contained in:
parent
d62a462c9a
commit
d9bfcc0c30
|
|
@ -2,6 +2,8 @@ package com.bonus.canteen.core.cook.mapper;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import com.bonus.canteen.core.cook.domain.CookAppRecipe;
|
||||
import com.bonus.canteen.core.cook.domain.CookRecipe;
|
||||
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
|
||||
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
|
||||
|
|
@ -59,6 +61,20 @@ public interface CookRecipeMapper {
|
|||
*/
|
||||
public int updateCookRecipe(CookRecipeDTO cookRecipeDTO);
|
||||
|
||||
List<Integer> getDeviceIdByDevivce(@Param("canteenId")String canteenId, @Param("stallId")String stallId);
|
||||
|
||||
List<String> getDeviceSnByIds(@Param("list") List<Integer> deviceInfoList);
|
||||
|
||||
boolean checkIfAlreadyBind(CookAppRecipe appRecipe);
|
||||
|
||||
List<Long> selectRecipeInSameShop(@Param("stallId") Long stallId, @Param("bindType") Integer bindType, @Param("mealLineId") Long mealLineId);
|
||||
|
||||
void deleteBind(CookAppRecipe appRecipe);
|
||||
|
||||
int insertBind(CookAppRecipe appRecipe);
|
||||
|
||||
void updateRecipeByCanteenStallMeal(@Param("recipeId")String recipeId, @Param("canteenId")String canteenId, @Param("stallId")String stallId, @Param("deviceIds")List<Integer> deviceIds);
|
||||
|
||||
/**
|
||||
* 删除菜品计划信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -308,65 +308,65 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
|||
}
|
||||
|
||||
public void bindCookRecipe(CookRecipeBindDTO cookRecipeDTO) {
|
||||
// CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId());
|
||||
// List<Integer> deviceInfoList = new ArrayList<>();
|
||||
// if(cookRecipeDTO.getStallId() !=null){
|
||||
// deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId()));
|
||||
// if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){
|
||||
// throw new ServiceException("该食堂档口下没有设备信息");
|
||||
// }
|
||||
// }
|
||||
// List<String> deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
|
||||
// CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType());
|
||||
// CookAppRecipe mar = new CookAppRecipe();
|
||||
// mar.setRecipeId(cookRecipeDTO.getRecipeId());
|
||||
// mar.setMealLineId(cookRecipeDTO.getMealLineId());
|
||||
// mar.setBindType(cookRecipeDTO.getBindType());
|
||||
// List<Integer> deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId()));
|
||||
// if (ObjectUtil.isEmpty(sortEnum)) {
|
||||
// throw new ServiceException("bingType值异常");
|
||||
// } else {
|
||||
// List<Integer> deviceTypes = sortEnum.getDeviceType();
|
||||
// if (cookRecipeDTO.getHandleType().equals(1)) {
|
||||
// boolean exists;
|
||||
CookRecipe menuRecipe = this.cookRecipeMapper.selectCookRecipeByRecipeId(cookRecipeDTO.getRecipeId());
|
||||
List<Integer> deviceInfoList = new ArrayList<>();
|
||||
if(cookRecipeDTO.getStallId() !=null){
|
||||
deviceInfoList = this.cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(cookRecipeDTO.getStallId()));
|
||||
if(deviceInfoList == null || deviceInfoList.isEmpty() || deviceInfoList.size() == 0){
|
||||
throw new ServiceException("该食堂档口下没有设备信息");
|
||||
}
|
||||
}
|
||||
List<String> deviceSnList = this.cookRecipeMapper.getDeviceSnByIds(deviceInfoList);
|
||||
CookRecipeSortEnum sortEnum = CookRecipeSortEnum.getBindTypeMap().get(cookRecipeDTO.getBindType());
|
||||
CookAppRecipe mar = new CookAppRecipe();
|
||||
mar.setRecipeId(cookRecipeDTO.getRecipeId());
|
||||
mar.setMealLineId(cookRecipeDTO.getMealLineId());
|
||||
mar.setBindType(cookRecipeDTO.getBindType());
|
||||
List<Integer> deviceTypeList = cookRecipeMapper.getDeviceIdByDevivce(null, String.valueOf(menuRecipe.getStallId()));
|
||||
if (ObjectUtil.isEmpty(sortEnum)) {
|
||||
throw new ServiceException("bingType值异常");
|
||||
} else {
|
||||
List<Integer> deviceTypes = sortEnum.getDeviceType();
|
||||
if (cookRecipeDTO.getHandleType().equals(1)) {
|
||||
boolean exists;
|
||||
// if (CookBindTypeEnum.RESERVE.key().equals(cookRecipeDTO.getBindType())) {
|
||||
// exists = this.checkCanteenIfReserve(menuRecipe.getCanteenId(), menuRecipe.getStallId());
|
||||
// if (!exists) {
|
||||
// throw new ServiceException("不支持预订餐");
|
||||
// }
|
||||
// }
|
||||
// exists = this.cookRecipeMapper.exists(mar);
|
||||
// if (exists) {
|
||||
// throw new ServiceException("菜谱已被使用,请勿重复绑定");
|
||||
// }
|
||||
// List<Long> sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), null, cookRecipeDTO.getBindType(), content.getMealLineId());
|
||||
// if (ObjectUtil.isNotEmpty(sourceRecipeList)) {
|
||||
// mar.setRecipeIds(sourceRecipeList);
|
||||
// this.cookRecipeMapper.delete(mar);
|
||||
// }
|
||||
// CookAppRecipe appRecipe = new CookAppRecipe();
|
||||
// appRecipe.setRecipeId(cookRecipeDTO.getRecipeId());
|
||||
// appRecipe.setBindType(cookRecipeDTO.getBindType());
|
||||
// appRecipe.setMealLineId(cookRecipeDTO.getMealLineId());
|
||||
// appRecipe.setBindTime(LocalDateTime.now());
|
||||
// this.cookRecipeMapper.insert(appRecipe);
|
||||
// if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
|
||||
// this.cookRecipeMapper.updateRecipeByCanteeStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList);
|
||||
// }
|
||||
// MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
|
||||
// } else {
|
||||
// mar.setRecipeIds(Collections.singletonList(mar.getRecipeId()));
|
||||
// this.cookRecipeMapper.delete(mar);
|
||||
// if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
|
||||
// this.cookRecipeMapper.updateRecipeByCanteeStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList);
|
||||
// }
|
||||
// }
|
||||
// //发送mq
|
||||
// for (String deviceSn : deviceSnList){
|
||||
// DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,cookRecipeDTO.getHandleType().equals(1) ? "update" : "del");
|
||||
// MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
|
||||
// }
|
||||
// }
|
||||
exists = this.cookRecipeMapper.checkIfAlreadyBind(mar);
|
||||
if (exists) {
|
||||
throw new ServiceException("菜谱已被使用,请勿重复绑定");
|
||||
}
|
||||
List<Long> sourceRecipeList = this.cookRecipeMapper.selectRecipeInSameShop(menuRecipe.getStallId(), cookRecipeDTO.getBindType(), cookRecipeDTO.getMealLineId());
|
||||
if (ObjectUtil.isNotEmpty(sourceRecipeList)) {
|
||||
mar.setRecipeIds(sourceRecipeList);
|
||||
this.cookRecipeMapper.deleteBind(mar);
|
||||
}
|
||||
CookAppRecipe appRecipe = new CookAppRecipe();
|
||||
appRecipe.setRecipeId(cookRecipeDTO.getRecipeId());
|
||||
appRecipe.setBindType(cookRecipeDTO.getBindType());
|
||||
appRecipe.setMealLineId(cookRecipeDTO.getMealLineId());
|
||||
appRecipe.setBindTime(LocalDateTime.now());
|
||||
this.cookRecipeMapper.insertBind(appRecipe);
|
||||
if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
|
||||
this.cookRecipeMapper.updateRecipeByCanteenStallMeal(String.valueOf(cookRecipeDTO.getRecipeId()), String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()),deviceTypeList);
|
||||
}
|
||||
MqUtil.sendDataChange(menuRecipe, LeMqConstant.DataChangeType.ADD, LeMqConstant.Topic.DATA_CHANGE_RECIPE_RELEASE);
|
||||
} else {
|
||||
mar.setRecipeIds(Collections.singletonList(mar.getRecipeId()));
|
||||
this.cookRecipeMapper.deleteBind(mar);
|
||||
if (ObjectUtil.isNotEmpty(deviceTypes) && deviceTypeList!= null && !deviceTypeList.isEmpty()) {
|
||||
this.cookRecipeMapper.updateRecipeByCanteenStallMeal("-1", String.valueOf(menuRecipe.getCanteenId()), String.valueOf(menuRecipe.getStallId()), deviceTypeList);
|
||||
}
|
||||
}
|
||||
//发送mq
|
||||
for (String deviceSn : deviceSnList){
|
||||
DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(0,cookRecipeDTO.getHandleType().equals(1) ? "update" : "del");
|
||||
MqUtil.pushToSingleDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_MENU_CONFIG_V4, deviceSn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -188,6 +188,67 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
where recipe_id = #{recipeId}
|
||||
</update>
|
||||
|
||||
<select id="getDeviceIdByDevivce" parameterType="string" resultType="integer">
|
||||
select a.device_id
|
||||
from device_info a
|
||||
LEFT JOIN cook_recipe_bind_device b on a.device_id = b.device_id
|
||||
where b.stall_id = #{stallId}
|
||||
</select>
|
||||
|
||||
<select id="getDeviceSnByIds" resultType="java.lang.String">
|
||||
select device_sn
|
||||
from device_info
|
||||
where device_id in
|
||||
<foreach collection="list" item="deviceId" separator="," open="(" close=")">
|
||||
#{deviceId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="checkIfAlreadyBind" resultType="boolean">
|
||||
select count(1) > 0 from cook_recipe_bind_app
|
||||
where recipe_id = #{recipeId}
|
||||
<if test="mealLineId !=null">
|
||||
and meal_line_id = #{mealLineId}
|
||||
</if>
|
||||
and bind_type = #{bindType}
|
||||
</select>
|
||||
|
||||
<select id="selectRecipeInSameShop" resultType="java.lang.Long">
|
||||
select mar.recipe_id
|
||||
from cook_recipe_bind_app mar
|
||||
inner join cook_recipe mr on mar.recipe_id = mr.recipe_id
|
||||
where mar.bind_type = #{bindType}
|
||||
and mr.stall_id = #{stallId}
|
||||
<if test="mealLineId !=null">
|
||||
and mar.meal_line_id= #{mealLineId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<delete id="deleteBind" parameterType="com.bonus.canteen.core.cook.domain.CookAppRecipe">
|
||||
delete from cook_recipe_bind_app where recipe_id in
|
||||
<foreach collection="recipeIds" item="recipeId" separator="," open="(" close=")">
|
||||
#{recipeId}
|
||||
</foreach>
|
||||
<if test="mealLineId != null">
|
||||
and meal_line_id = #{mealLineId}
|
||||
</if>
|
||||
and bind_type = #{bindType}
|
||||
</delete>
|
||||
|
||||
<insert id="insertBind" parameterType="com.bonus.canteen.core.cook.domain.CookAppRecipe">
|
||||
insert into cook_recipe_bind_app (recipe_id,bind_type,bind_time,meal_line_id)
|
||||
values (#{recipeId},#{bindType},now(),#{mealLineId})
|
||||
</insert>
|
||||
|
||||
<update id="updateRecipeByCanteenStallMeal">
|
||||
update cook_recipe_bind_device set recipe_id = #{ recipeId}
|
||||
where canteen_id = #{canteenId} and stall_id = #{stallId}
|
||||
and device_id in
|
||||
<foreach collection="deviceIds" separator="," open="(" close=")" item="item">
|
||||
#{item}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<delete id="deleteCookRecipeByRecipeId" parameterType="Long">
|
||||
update cook_recipe set del_flag = '2' where recipe_id = #{recipeId}
|
||||
</delete>
|
||||
|
|
|
|||
Loading…
Reference in New Issue