菜品增删查改对接

This commit is contained in:
huangdeliang
2021-02-20 19:46:13 +08:00
parent 854171897d
commit a7ca979d06
14 changed files with 251 additions and 26 deletions

View File

@ -148,6 +148,7 @@ mybatis:
mapperLocations: classpath*:mapper/**/*Mapper.xml mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件 # 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml configLocation: classpath:mybatis/mybatis-config.xml
typeHandlersPackage: com.stdiet.**.typehandler
# PageHelper分页插件 # PageHelper分页插件
pagehelper: pagehelper:

View File

@ -148,6 +148,7 @@ mybatis:
mapperLocations: classpath*:mapper/**/*Mapper.xml mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件 # 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml configLocation: classpath:mybatis/mybatis-config.xml
typeHandlersPackage: com.stdiet.**.typehandler
# PageHelper分页插件 # PageHelper分页插件
pagehelper: pagehelper:

View File

@ -148,6 +148,7 @@ mybatis:
mapperLocations: classpath*:mapper/**/*Mapper.xml mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件 # 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml configLocation: classpath:mybatis/mybatis-config.xml
typeHandlersPackage: com.stdiet.**.typehandler
# PageHelper分页插件 # PageHelper分页插件
pagehelper: pagehelper:

View File

@ -1,16 +1,16 @@
package com.stdiet.web.controller.custom; package com.stdiet.web.controller.custom;
import com.stdiet.common.annotation.Log;
import com.stdiet.common.core.controller.BaseController; import com.stdiet.common.core.controller.BaseController;
import com.stdiet.common.core.domain.AjaxResult; import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.common.enums.BusinessType;
import com.stdiet.custom.domain.SysDishes;
import com.stdiet.custom.service.ISysRecipesService; import com.stdiet.custom.service.ISysRecipesService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/recipes") @RequestMapping("/custom/recipes")
public class SysRecipesController extends BaseController { public class SysRecipesController extends BaseController {
@Autowired @Autowired
@ -20,4 +20,32 @@ public class SysRecipesController extends BaseController {
public AjaxResult getInfo(@PathVariable("resipesId") Long resipesId) { public AjaxResult getInfo(@PathVariable("resipesId") Long resipesId) {
return AjaxResult.success(sysRecipesService.selectSysRecipesByRecipesId(resipesId)); return AjaxResult.success(sysRecipesService.selectSysRecipesByRecipesId(resipesId));
} }
/**
* 修改食谱菜品
*
* @return
*/
@Log(title = "食谱", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysDishes sysDishes) {
return toAjax(sysRecipesService.updateDishesDetail(sysDishes));
}
@Log(title = "食谱", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysDishes sysDishes) {
int rows = sysRecipesService.insertDishes(sysDishes);
if (rows > 0) {
return AjaxResult.success(sysDishes.getId());
} else {
return AjaxResult.error();
}
}
@Log(title = "销售订单", businessType = BusinessType.DELETE)
@DeleteMapping("/dishes/{cId}")
public AjaxResult delete(@PathVariable Long cId) {
return toAjax(sysRecipesService.deleteDishes(cId));
}
} }

View File

@ -1,5 +1,6 @@
package com.stdiet.custom.domain; package com.stdiet.custom.domain;
import com.alibaba.fastjson.JSONArray;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.stdiet.common.annotation.Excel; import com.stdiet.common.annotation.Excel;
import lombok.Data; import lombok.Data;
@ -22,6 +23,10 @@ public class SysDishes {
*/ */
private Long id; private Long id;
private Long cId;
private Long menuId;
/** /**
* 菜品名称 * 菜品名称
*/ */
@ -74,6 +79,6 @@ public class SysDishes {
private List<SysDishesIngredient> igdList; private List<SysDishesIngredient> igdList;
private List<SysDishesIngredient> detail; private JSONArray detail;
} }

View File

@ -1,8 +1,6 @@
package com.stdiet.custom.domain; package com.stdiet.custom.domain;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -27,4 +25,11 @@ public class SysDishesIngredient extends SysIngredient {
private String remark; private String remark;
private Long id;
private String cus_unit;
private String cus_weight;
} }

View File

@ -1,5 +1,6 @@
package com.stdiet.custom.mapper; package com.stdiet.custom.mapper;
import com.stdiet.custom.domain.SysDishes;
import com.stdiet.custom.domain.SysRecipes; import com.stdiet.custom.domain.SysRecipes;
import java.util.List; import java.util.List;
@ -7,4 +8,10 @@ import java.util.List;
public interface SysRecipesMapper { public interface SysRecipesMapper {
public List<SysRecipes> selectSysRecipesByRecipesId(Long id); public List<SysRecipes> selectSysRecipesByRecipesId(Long id);
public int updateDishesDetail(SysDishes sysDishes);
public int insertDishes(SysDishes sysDishes);
public int deleteDishes(Long cId);
} }

View File

@ -1,9 +1,16 @@
package com.stdiet.custom.service; package com.stdiet.custom.service;
import com.stdiet.custom.domain.SysDishes;
import com.stdiet.custom.domain.SysRecipes; import com.stdiet.custom.domain.SysRecipes;
import java.util.List; import java.util.List;
public interface ISysRecipesService { public interface ISysRecipesService {
public List<SysRecipes> selectSysRecipesByRecipesId(Long id); public List<SysRecipes> selectSysRecipesByRecipesId(Long id);
public int updateDishesDetail(SysDishes sysDishes);
public int insertDishes(SysDishes sysDishes);
public int deleteDishes(Long cId);
} }

View File

@ -1,5 +1,6 @@
package com.stdiet.custom.service.impl; package com.stdiet.custom.service.impl;
import com.stdiet.custom.domain.SysDishes;
import com.stdiet.custom.domain.SysRecipes; import com.stdiet.custom.domain.SysRecipes;
import com.stdiet.custom.mapper.SysRecipesMapper; import com.stdiet.custom.mapper.SysRecipesMapper;
import com.stdiet.custom.service.ISysRecipesService; import com.stdiet.custom.service.ISysRecipesService;
@ -20,4 +21,19 @@ public class SysRecipesServiceImpl implements ISysRecipesService {
public List<SysRecipes> selectSysRecipesByRecipesId(Long id) { public List<SysRecipes> selectSysRecipesByRecipesId(Long id) {
return sysRecipesMapper.selectSysRecipesByRecipesId(id); return sysRecipesMapper.selectSysRecipesByRecipesId(id);
} }
@Override
public int updateDishesDetail(SysDishes sysDishes) {
return sysRecipesMapper.updateDishesDetail(sysDishes);
}
@Override
public int insertDishes(SysDishes sysDishes) {
return sysRecipesMapper.insertDishes(sysDishes);
}
@Override
public int deleteDishes(Long cId) {
return sysRecipesMapper.deleteDishes(cId);
}
} }

View File

@ -17,12 +17,13 @@
<resultMap id="SysDishesResult" type="SysDishes"> <resultMap id="SysDishesResult" type="SysDishes">
<result property="id" column="dishes_id"/> <result property="id" column="dishes_id"/>
<result property="cId" column="id" />
<result property="name" column="name"/> <result property="name" column="name"/>
<result property="type" column="type"/> <result property="type" column="type"/>
<result property="methods" column="methods"/> <result property="methods" column="methods"/>
<result property="isMain" column="is_main"/> <result property="isMain" column="is_main"/>
<result property="detail" column="detail" typeHandler="com.stdiet.custom.typehandler.ArrayJsonHandler" <result property="detail" column="detail" typeHandler="com.stdiet.custom.typehandler.ArrayJsonHandler"
javaType="com.stdiet.custom.domain.SysDishesIngredientInfo"/> javaType="com.stdiet.custom.domain.SysDishesIngredient"/>
<association property="igdList" column="dishes_id" select="selectIngredientsByDishesId"/> <association property="igdList" column="dishes_id" select="selectIngredientsByDishesId"/>
</resultMap> </resultMap>
@ -76,4 +77,35 @@
) ing USING(id) ) ing USING(id)
</select> </select>
<!-- 更新菜品-->
<update id="updateDishesDetail" parameterType="SysDishes">
update sys_customer_menu_dishes
<trim prefix="SET" suffixOverrides=",">
<if test="detail != null">detail = #{detail, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler},</if>
</trim>
where id = #{cId}
</update>
<!-- 插入菜品-->
<insert id="insertDishes" parameterType="SysDishes" useGeneratedKeys="true" keyProperty="id">
insert into sys_customer_menu_dishes
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="menuId != null">menu_id,</if>
<if test="id != null">dishes_id,</if>
<if test="type != null">type,</if>
<if test="detail != null">detail,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="menuId != null">#{menuId},</if>
<if test="id != null">#{id},</if>
<if test="type != null">#{type},</if>
<if test="detail != null">#{detail, jdbcType=OTHER, typeHandler=com.stdiet.custom.typehandler.ArrayJsonHandler},</if>
</trim>
</insert>
<!-- 删除菜品-->
<delete id="deleteDishes" parameterType="Long">
delete from sys_customer_menu_dishes where id = #{cId}
</delete>
</mapper> </mapper>

View File

@ -1,8 +1,31 @@
import request from "@/utils/request"; import request from "@/utils/request";
export function getRecipes(id) { export function getRecipesApi(id) {
return request({ return request({
url: "/recipes/" + id, url: "/custom/recipes/" + id,
method: "get" method: "get"
}); });
} }
export function updateDishesDetailApi(data) {
return request({
url: "/custom/recipes",
method: "put",
data
});
}
export function addDishesApi(data) {
return request({
url: "/custom/recipes",
method: "post",
data
});
}
export function deleteDishesApi(cid) {
return request({
url: "/custom/recipes/dishes/" + cid,
method: "delete"
});
}

View File

@ -2,11 +2,18 @@ import { getOrder } from "@/api/custom/order";
import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer"; import { getCustomerPhysicalSignsByCusId } from "@/api/custom/customer";
import { dealHealthy } from "@/utils/healthyData"; import { dealHealthy } from "@/utils/healthyData";
import { getRecipesPlan } from "@/api/custom/recipesPlan"; import { getRecipesPlan } from "@/api/custom/recipesPlan";
import { getRecipes } from "@/api/custom/recipes"; import {
getRecipesApi,
updateDishesDetailApi,
addDishesApi,
deleteDishesApi
} from "@/api/custom/recipes";
import { getDicts } from "@/api/system/dict/data"; import { getDicts } from "@/api/system/dict/data";
import produce from "immer"; import produce from "immer";
import { updateDishes } from "@/api/custom/dishes";
const oriState = { const oriState = {
recipesId: undefined,
healthyData: {}, healthyData: {},
healthyDataType: 0, healthyDataType: 0,
recipesData: [], recipesData: [],
@ -18,6 +25,9 @@ const oriState = {
}; };
const mutations = { const mutations = {
setRecipiesId(state, payload) {
state.recipesId = payload.recipesId;
},
setHealtyData(state, payload) { setHealtyData(state, payload) {
state.healthyDataType = payload.healthyDataType; state.healthyDataType = payload.healthyDataType;
state.healthyData = payload.healthyData; state.healthyData = payload.healthyData;
@ -40,7 +50,6 @@ const mutations = {
} }
}, },
addRecipesDishes(state, payload) { addRecipesDishes(state, payload) {
state.recipesData[payload.num].dishes.push(payload.data); state.recipesData[payload.num].dishes.push(payload.data);
}, },
updateOptions(state, payload) { updateOptions(state, payload) {
@ -104,7 +113,7 @@ const actions = {
// 食谱数据 // 食谱数据
if (payload.recipesId) { if (payload.recipesId) {
const recipesDataResult = await getRecipes(payload.recipesId); const recipesDataResult = await getRecipesApi(payload.recipesId);
if (recipesDataResult.code === 200) { if (recipesDataResult.code === 200) {
commit("setRecipesData", { commit("setRecipesData", {
recipesData: recipesDataResult.data.map(dayData => { recipesData: recipesDataResult.data.map(dayData => {
@ -120,6 +129,7 @@ const actions = {
) { ) {
arr.push({ arr.push({
id: cur.id, id: cur.id,
cid: cur.cid,
name: cur.name, name: cur.name,
methods: cur.methods, methods: cur.methods,
type: cur.type, type: cur.type,
@ -162,7 +172,89 @@ const actions = {
throw new Error(recipesDataResult.msg); throw new Error(recipesDataResult.msg);
} }
} }
} },
async saveRecipes({ commit, state }, payload) {
const { recipesData } = state;
const params = recipesData.map(menu => {
return menu.dishes.map(dObj => {
return {
dishesId: dObj.id,
type: dObj.type,
detail: dObj.igdList.map(igd => ({
id: igd.id,
weight: igd.weight,
cus_unit: igd.cusUnit,
cus_weight: igd.cusWeight
}))
};
});
});
console.log(params);
},
async addDishes({ commit, state }, payload) {
const tarRecipesObj = state.recipesData[payload.num];
if (tarRecipesObj && payload.data) {
const { id, type, igdList } = payload.data;
const params = {
menuId: tarRecipesObj.id,
id: id,
type: type,
detail: igdList.map(igd => ({
id: igd.id,
weight: igd.weight,
cus_unit: igd.cusUnit,
cus_weight: igd.cusWeight
}))
};
const result = await addDishesApi(params);
if (result.code === 200) {
payload.data.cid = result.data;
commit("addRecipesDishes", payload);
}
console.log(result);
}
},
async updateDishes({ commit, state }, payload) {
const tarDishes = state.recipesData[payload.num].dishes.find(
obj => obj.id === payload.dishesId
);
if (tarDishes) {
const mTarDishes = JSON.parse(JSON.stringify(tarDishes));
const tarIgd = mTarDishes.igdList.find(obj => obj.id === payload.igdId);
if (tarIgd) {
payload.weight && (tarIgd.weight = payload.weight);
payload.cusWeight && (tarIgd.cusWeight = payload.cusWeight);
payload.cusUnit && (tarIgd.cusUnit = payload.cusUnit);
const params = {
cid: mTarDishes.cid,
detail: mTarDishes.igdList.map(igd => ({
id: igd.id,
weight: igd.weight,
cus_unit: igd.cusUnit,
cus_weight: igd.cusWeight
}))
};
const result = await updateDishesDetailApi(params);
if (result.code === 200) {
commit("updateRecipesDishesDetail", payload);
}
}
}
},
async deleteDishes({ commit, state }, payload) {
const tarDishes = state.recipesData[payload.num].dishes.find(
obj => obj.id === payload.dishesId
);
if (tarDishes) {
const result = await deleteDishesApi(tarDishes.cid);
if (result.code === 200) {
commit("deleteSomeDayDishes", payload);
}
// console.log(params);
}
},
async deleteMenu({ commit }, payload) {}
}; };
const getters = { const getters = {

View File

@ -4,6 +4,9 @@
:style="`height: ${collapse ? 30 : 200}px`" :style="`height: ${collapse ? 30 : 200}px`"
> >
<div class="header"> <div class="header">
<el-button size="mini" type="primary" @click="handleOnSave"
>保存</el-button
>
<el-button size="mini" type="text" @click="handleCollapseClick">{{ <el-button size="mini" type="text" @click="handleCollapseClick">{{
`${collapse ? "展开分析" : "收起分析"}` `${collapse ? "展开分析" : "收起分析"}`
}}</el-button> }}</el-button>
@ -25,6 +28,8 @@
<script> <script>
import BarChart from "./BarChart"; import BarChart from "./BarChart";
import PieChart from "./PieChart"; import PieChart from "./PieChart";
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("recipes");
export default { export default {
name: "RecipesAspectCom", name: "RecipesAspectCom",
components: { components: {
@ -43,6 +48,10 @@ export default {
handleCollapseClick() { handleCollapseClick() {
this.$emit("update:collapse", !this.collapse); this.$emit("update:collapse", !this.collapse);
}, },
handleOnSave() {
this.saveRecipes();
},
...mapActions(["saveRecipes"]),
}, },
}; };
</script> </script>

View File

@ -18,7 +18,9 @@
}}</span> }}</span>
</template> </template>
<template slot-scope="scope"> <template slot-scope="scope">
<span style="font-weight: bold; font-size: 14px">{{ typeFormatter(scope.row) }}</span> <span style="font-weight: bold; font-size: 14px">{{
typeFormatter(scope.row)
}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="菜品" prop="name" align="center"> <el-table-column label="菜品" prop="name" align="center">
@ -270,11 +272,11 @@ export default {
}, },
handleOnDelete(data) { handleOnDelete(data) {
// console.log(data); // console.log(data);
this.deleteSomeDayDishes({ num: this.num - 1, dishesId: data.id }); this.deleteDishes({ num: this.num - 1, dishesId: data.id });
}, },
handleOnWeightChange(data, weight) { handleOnWeightChange(data, weight) {
// console.log({ data, weight }); // console.log({ data, weight });
this.updateRecipesDishesDetail({ this.updateDishes({
num: this.num - 1, num: this.num - 1,
dishesId: data.id, dishesId: data.id,
igdId: data.igdId, igdId: data.igdId,
@ -282,7 +284,7 @@ export default {
}); });
}, },
handleOnCustomUnitChange(data, { cusWeight, cusUnit }) { handleOnCustomUnitChange(data, { cusWeight, cusUnit }) {
this.updateRecipesDishesDetail({ this.updateDishes({
num: this.num - 1, num: this.num - 1,
dishesId: data.id, dishesId: data.id,
igdId: data.igdId, igdId: data.igdId,
@ -291,17 +293,13 @@ export default {
}); });
}, },
handleOnDishesConfirm(data) { handleOnDishesConfirm(data) {
this.addRecipesDishes({ this.addDishes({
num: this.num - 1, num: this.num - 1,
data, data,
}); });
}, },
...mapMutations([ ...mapActions(["updateDishes", "addDishes", "deleteDishes"]),
"setCurrentDay", ...mapMutations(["setCurrentDay",]),
"deleteSomeDayDishes",
"updateRecipesDishesDetail",
"addRecipesDishes",
]),
}, },
}; };
</script> </script>