完善病患营养配餐“拷贝新增”功能

This commit is contained in:
czx 2021-01-18 16:27:17 +08:00
parent e8c7cecdce
commit 7026d78c34
5 changed files with 136 additions and 124 deletions

View File

@ -1,5 +1,7 @@
package com.ruoyi.system.fantang.controller; package com.ruoyi.system.fantang.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log; import com.ruoyi.common.annotation.Log;
@ -152,18 +154,28 @@ public class FtCateringDaoController extends BaseController {
return AjaxResult.success(iFtCateringDaoService.getOne(wrapper)); return AjaxResult.success(iFtCateringDaoService.getOne(wrapper));
} }
/**
* 根据病人 id 查找营养配餐数据
*/
@GetMapping("/getAllByPatient/{patientId}")
public AjaxResult getAllByPatient(@PathVariable Long patientId) {
QueryWrapper<FtCateringDao> wrapper = new QueryWrapper<>();
wrapper.eq("patient_id", patientId);
return AjaxResult.success(iFtCateringDaoService.list(wrapper));
}
/** /**
* 拷贝并新增 * 拷贝并新增
*/ */
@PostMapping("/copyAndAdd") @PostMapping("/copyAndAdd")
public AjaxResult copyAndAdd(@RequestBody FtCateringDao ftCateringDao) { public AjaxResult copyAndAdd(@RequestBody JSONObject params) {
List<Long> patientIds = params.getJSONArray("patientIds").toJavaList(Long.class);
List<FtCateringDao> data = params.getJSONArray("data").toJavaList(FtCateringDao.class);
for (Long patientId : patientIds) {
Integer ftCateringDaoList = iFtCateringDaoService.copyAndAdd(patientId, data);
}
System.out.println(ftCateringDao);
List<Long> patientIds = iFtCateringDaoService.notInTable(ftCateringDao);
List<FtCateringDao> ftCateringDaoList = iFtCateringDaoService.copyAndAdd(patientIds, ftCateringDao);

View File

@ -25,5 +25,5 @@ public interface IFtCateringDaoService extends IService<FtCateringDao> {
List<Long> notInTable(FtCateringDao ftCateringDao); List<Long> notInTable(FtCateringDao ftCateringDao);
List<FtCateringDao> copyAndAdd(List<Long> patientIds, FtCateringDao ftCateringDao); Integer copyAndAdd(Long patientId, List<FtCateringDao> ftCateringDao);
} }

View File

@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.fantang.domain.FtCateringDao; import com.ruoyi.system.fantang.domain.FtCateringDao;
import com.ruoyi.system.fantang.domain.FtFoodDemandDao;
import com.ruoyi.system.fantang.mapper.FtCateringDaoMapper; import com.ruoyi.system.fantang.mapper.FtCateringDaoMapper;
import com.ruoyi.system.fantang.mapper.FtFoodDemandDaoMapper;
import com.ruoyi.system.fantang.service.IFtCateringDaoService; import com.ruoyi.system.fantang.service.IFtCateringDaoService;
import com.ruoyi.system.fantang.service.IFtFoodDemandDaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +25,9 @@ import java.util.List;
@Service @Service
public class FtCateringDaoServiceImpl extends ServiceImpl<FtCateringDaoMapper, FtCateringDao> implements IFtCateringDaoService { public class FtCateringDaoServiceImpl extends ServiceImpl<FtCateringDaoMapper, FtCateringDao> implements IFtCateringDaoService {
@Autowired
IFtFoodDemandDaoService foodDemandDaoService;
@Override @Override
public List<FtCateringDao> listNewFormatter(FtCateringDao ftCateringDao) { public List<FtCateringDao> listNewFormatter(FtCateringDao ftCateringDao) {
return this.baseMapper.listNewFormatter(ftCateringDao); return this.baseMapper.listNewFormatter(ftCateringDao);
@ -116,37 +123,31 @@ public class FtCateringDaoServiceImpl extends ServiceImpl<FtCateringDaoMapper, F
return patientNotInTable; return patientNotInTable;
} }
/**
* 拷贝粘贴新增指定病患的营养配餐记录并更新该病患默认报餐配置信息
* @author 陈智兴
* @param patientId
* @param ftCateringDao
* @return
*/
@Override @Override
public List<FtCateringDao> copyAndAdd(List<Long> patientIds, FtCateringDao ftCateringDao) { public Integer copyAndAdd(Long patientId, List<FtCateringDao> ftCateringDao) {
List<FtCateringDao> list = new ArrayList<>(); // 为指定病患id批量插入营养配餐配置记录
for (FtCateringDao cateringDao : ftCateringDao) {
cateringDao.setId(null);
cateringDao.setPatientId(patientId);
this.baseMapper.insert(cateringDao);
List<Integer> types = ftCateringDao.getTypes(); // 更新该病患默认配餐信息
FtFoodDemandDao foodDemandDao = new FtFoodDemandDao();
for (Long patientId : patientIds) { foodDemandDao.setNutritionFoodId(cateringDao.getNumber());
for (int i = 1; i < 5; i++) { foodDemandDao.setNutritionFoodFlag(true);
FtCateringDao cateringDao = new FtCateringDao(); QueryWrapper<FtFoodDemandDao> wrapper = new QueryWrapper<>();
cateringDao.setPatientId(patientId); wrapper.eq("patient_id",patientId);
cateringDao.setNumber(ftCateringDao.getNumber()); wrapper.eq("type",cateringDao.getType());
cateringDao.setFrequency(ftCateringDao.getFrequency()); foodDemandDaoService.update(foodDemandDao, wrapper);
cateringDao.setCateringUsage(ftCateringDao.getCateringUsage());
cateringDao.setCreateAt(new Date());
cateringDao.setType(i);
for (Integer type : types) {
if (i == type) {
cateringDao.setFlag(true);
break;
} else {
cateringDao.setFlag(false);
}
}
this.baseMapper.insert(cateringDao);
list.add(cateringDao);
}
} }
return 1;
return list;
} }
} }

View File

@ -76,3 +76,11 @@ export function getByPatient(id) {
method: 'get' method: 'get'
}) })
} }
// 根据病人 id 查找全部四条营养配餐记录
export function getAllByPatient(id) {
return request({
url: '/fantang/catering/getAllByPatient/' + id,
method: 'get'
})
}

View File

@ -411,11 +411,12 @@
</el-dialog> </el-dialog>
<!-- 拷贝并新增对话框 --> <!-- 拷贝并新增对话框 -->
<el-dialog :title="title" :visible.sync="copyItem" width="600px" append-to-body> <el-dialog :title="title" :visible.sync="copyItem" width="800px" append-to-body>
<el-form ref="copyItemForm" :model="copyItemForm" :rules="copyItemFormRules" label-width="80px"> <el-form ref="copyItemForm" :model="copyItemForm" :rules="copyItemFormRules" label-width="80px">
<el-form-item label="科室" prop="departId"> <el-form-item label="科室" prop="departId">
<el-select v-model="copyItemForm.departId" <el-select v-model="copyItemForm.departId"
placeholder="请选择科室" placeholder="请选择科室"
style="width:450px"
@change="changeDepart"> @change="changeDepart">
<el-option <el-option
v-for="item in departOptions" v-for="item in departOptions"
@ -425,8 +426,8 @@
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="病人" prop="patientIds"> <el-form-item label="病人" prop="patientIds" >
<el-select v-model="copyItemForm.patientIds" placeholder="请选择病人" multiple> <el-select v-model="copyItemForm.patientIds" placeholder="请选择病人" multiple style="width:450px">
<el-option <el-option
v-for="item in patientOptions" v-for="item in patientOptions"
:key="item.name" :key="item.name"
@ -438,54 +439,13 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<!-- <el-form-item label="床号" prop="bedId">-->
<!-- <el-input v-model="form.bedId" placeholder="床号" :disabled="true"/>--> <el-table :data="copyItemForm.data"
<!-- </el-form-item>--> border
<el-row :gutter="10"> :span-method="objectSpanMethodForCopyAndCreate">
<el-col :span="12"> <el-table-column label="配餐频次" align="center" prop="frequency" width="100px">
<el-form-item label="配餐号" prop="number"> <template slot-scope="scope">
<el-select v-model="copyItemForm.number" placeholder="请选择配餐号"> <el-select v-model="scope.row.frequency">
<el-option
v-for="item in numberOptions"
:key="item.name"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="用法" prop="cateringUsage">
<el-select v-model="copyItemForm.cateringUsage" placeholder="请选择用法">
<el-option
v-for="item in cateringUsageOptions"
:key="item.label"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row :gutter="10">
<el-col :span="12">
<el-form-item label="正餐类型" prop="types">
<el-select v-model="copyItemForm.types"
multiple
@change="changeDinnerType"
placeholder="请选择正餐类型">
<el-option
v-for="dict in typeOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="parseInt(dict.dictValue)"
></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="配餐频次" prop="frequency">
<el-select v-model="copyItemForm.frequency" placeholder="请选择频次">
<el-option <el-option
v-for="item in frequencyOptions" v-for="item in frequencyOptions"
:key="item.value" :key="item.value"
@ -493,12 +453,48 @@
:value="item.value"> :value="item.value">
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </template>
</el-col> </el-table-column>
</el-row> <el-table-column label="正餐类型" align="center" prop="type" :formatter="typeFormat" width="120px"/>
<el-table-column label="营养配餐" align="center" prop="foodName" width="200px">
<template slot-scope="scope">
<el-select v-model="scope.row.number">
<el-option
v-for="item in numberOptions"
:key="item.id"
:label="item.name"
:value="item.id">
</el-option>
</el-select>
</template>
</el-table-column>
<el-table-column label="用法" align="center" prop="cateringUsage" :formatter="cateringUsageFormat" width="120px">
<template slot-scope="scope">
<el-select v-model="scope.row.cateringUsage" placeholder="请选择用法">
<el-option
v-for="item in cateringUsageOptions"
:key="item.label"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</template>
</el-table-column>
<el-table-column label="启用标志" align="center" prop="flag" :formatter="formatFlag">
<template slot-scope="scope">
<el-switch
v-model="scope.row.flag"
active-color="#13ce66"
inactive-color="#ff4949"
active-text="启用"
inactive-text="关闭">
</el-switch>
</template>
</el-table-column>
</el-table>
</el-form> </el-form>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitCopyForm"> </el-button> <el-button type="primary" @click="submitCopyForm">拷贝新增</el-button>
<el-button @click="cancel"> </el-button> <el-button @click="cancel"> </el-button>
</div> </div>
</el-dialog> </el-dialog>
@ -517,7 +513,7 @@ import {
import {listDepart} from "../../../api/fantang/depart"; import {listDepart} from "../../../api/fantang/depart";
import {getBedIdById, selectNoCateringByDepartId} from "../../../api/fantang/patient"; import {getBedIdById, selectNoCateringByDepartId} from "../../../api/fantang/patient";
import {listNutritionFood} from "../../../api/fantang/nutritionFood"; import {listNutritionFood} from "../../../api/fantang/nutritionFood";
import {cancelCatering, copyAndAdd, getByPatient} from "../../../api/fantang/catering"; import {cancelCatering, copyAndAdd, getByPatient, getAllByPatient} from "../../../api/fantang/catering";
export default { export default {
name: "Catering", name: "Catering",
@ -600,24 +596,9 @@ export default {
copyItemForm: {}, copyItemForm: {},
// //
copyItemFormRules: { copyItemFormRules: {
departId: [
{required: true, message: "部门不能为空", trigger: "blur"}
],
patientIds: [ patientIds: [
{required: true, message: "病人不能为空", trigger: "blur"} {required: true, message: "病人不能为空", trigger: "blur"}
], ],
types: [
{required: true, message: "正餐类型不能为空", trigger: "blur"}
],
cateringUsage: [
{required: true, message: "用法不能为空", trigger: "blur"}
],
frequency: [
{required: true, message: "频次不能为空", trigger: "blur"}
],
number: [
{required: true, message: "配餐号不能为空", trigger: "blur"}
],
}, },
// //
rules: { rules: {
@ -678,7 +659,7 @@ export default {
return "禁用"; return "禁用";
} }
}, },
// //
objectSpanMethod({rowIndex, columnIndex}) { objectSpanMethod({rowIndex, columnIndex}) {
if (columnIndex === 1) { if (columnIndex === 1) {
if (rowIndex % 4 === 0) { if (rowIndex % 4 === 0) {
@ -744,6 +725,25 @@ export default {
} }
}, },
//
objectSpanMethodForCopyAndCreate({rowIndex, columnIndex}) {
if (columnIndex === 0) {
if (rowIndex % 4 === 0) {
return {
rowspan: 4,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
},
// //
changeDinnerType(value) { changeDinnerType(value) {
if (value.length === 1) { if (value.length === 1) {
@ -824,17 +824,8 @@ export default {
this.copyItemForm = { this.copyItemForm = {
id: null, id: null,
data: null,
patientId: null, patientId: null,
type: null,
number: null,
frequency: null,
cateringUsage: null,
isReplace: null,
flag: null,
updateAt: null,
updateBy: null,
createAt: null,
createBy: null,
cateringDescribe: null cateringDescribe: null
}; };
this.resetForm("copyItemForm"); this.resetForm("copyItemForm");
@ -880,12 +871,12 @@ export default {
if (this.ids.length > 1) { if (this.ids.length > 1) {
this.msgError("只能选择一条记录进行拷贝并新增") this.msgError("只能选择一条记录进行拷贝并新增")
} else { } else {
getByPatient(id).then(response => { this.copyItem = true;
console.log(response.data) getAllByPatient(id).then(response => {
this.copyItemForm.cateringUsage = response.data.cateringUsage; this.copyItemForm.data = response.data;
this.copyItemForm.frequency = response.data.frequency; this.copyItemForm.departId =null;
this.copyItemForm.number = response.data.number; this.copyItemForm.patientIds = [];
this.copyItem = true; console.log('cateringList-->', this.copyItemForm);
}) })
} }
}, },