1.前端页面checkgroup.html
<!DOCTYPE html>
<html>
<head>
<!-- 页面meta -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>传智健康</title>
<meta name="description" content="传智健康">
<meta name="keywords" content="传智健康">
<meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
<!-- 引入样式 -->
<link rel="stylesheet" href="../plugins/elementui/index.css">
<link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="../css/style.css">
<!-- 引入组件库 -->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<style>
.datatable {
position: relative;
box-sizing: border-box;
-webkit-box-flex: 1;
width: 100%;
max-width: 100%;
font-size: 14px;
color: rgb(96, 98, 102);
overflow: hidden;
flex: 1 1 0%;
}
.datatable td, .datatable th {
padding: 12px 0;
min-width: 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
text-overflow: ellipsis;
vertical-align: middle;
position: relative;
text-align: left;
}
</style>
</head>
<body class="hold-transition">
<div id="app">
<div class="content-header">
<h1>预约管理<small>检查组管理</small></h1>
<el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
<el-breadcrumb-item>预约管理</el-breadcrumb-item>
<el-breadcrumb-item>检查组管理</el-breadcrumb-item>
</el-breadcrumb>
</div>
<div class="app-container">
<div class="box">
<div class="filter-container">
<el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
<el-button @click="findPage2()" class="dalfBut">查询</el-button>
<el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
</div>
<el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
<el-table-column type="index" align="center" label="序号"></el-table-column>
<el-table-column prop="code" label="检查组编码" align="center"></el-table-column>
<el-table-column prop="name" label="检查组名称" align="center"></el-table-column>
<el-table-column label="适用性别" align="center">
<template slot-scope="scope">
<span>{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}</span>
</template>
</el-table-column>
<el-table-column prop="helpCode" label="助记码" align="center"></el-table-column>
<el-table-column prop="remark" label="说明" align="center"></el-table-column>
<el-table-column label="操作" align="center">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="pagination-container">
<el-pagination
class="pagiantion"
@current-change="handleCurrentChange"
:current-page="pagination.currentPage"
:page-size="pagination.pageSize"
layout="total, prev, pager, next, jumper"
:total="pagination.total">
</el-pagination>
</div>
<!-- 新增标签弹层 -->
<div class="add-form">
<el-dialog title="新增检查组" :visible.sync="dialogFormVisible">
<template>
<el-tabs v-model="activeName" type="card">
<el-tab-pane label="基本信息" name="first">
<el-form label-position="right" label-width="100px">
<el-row>
<el-col :span="12">
<el-form-item label="编码">
<el-input v-model="formData.code"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="名称">
<el-input v-model="formData.name"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="适用性别">
<el-select v-model="formData.sex">
<el-option label="不限" value="0"></el-option>
<el-option label="男" value="1"></el-option>
<el-option label="女" value="2"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="助记码">
<el-input v-model="formData.helpCode"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="说明">
<el-input v-model="formData.remark" type="textarea"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="注意事项">
<el-input v-model="formData.attention" type="textarea"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-tab-pane>
<el-tab-pane label="检查项信息" name="second">
<div class="checkScrol">
<table class="datatable">
<thead>
<tr>
<th>选择</th>
<th>项目编码</th>
<th>项目名称</th>
<th>项目说明</th>
</tr>
</thead>
<tbody>
<tr v-for="c in tableData">
<td>
<input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
</td>
<td><label :for="c.id">{{c.code}}</label></td>
<td><label :for="c.id">{{c.name}}</label></td>
<td><label :for="c.id">{{c.remark}}</label></td>
</tr>
</tbody>
</table>
</div>
</el-tab-pane>
</el-tabs>
</template>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取消</el-button>
<el-button type="primary" @click="handleAdd()">确定</el-button>
</div>
</el-dialog>
</div>
<!-- 编辑标签弹层 -->
<div class="add-form">
<el-dialog title="编辑检查组" :visible.sync="dialogFormVisible4Edit">
<template>
<el-tabs v-model="activeName" type="card">
<el-tab-pane label="基本信息" name="first">
<el-form label-position="right" label-width="100px">
<el-row>
<el-col :span="12">
<el-form-item label="编码">
<el-input v-model="formData.code"/>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="名称">
<el-input v-model="formData.name"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<el-form-item label="适用性别">
<el-select v-model="formData.sex">
<el-option label="不限" value="0"></el-option>
<el-option label="男" value="1"></el-option>
<el-option label="女" value="2"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="助记码">
<el-input v-model="formData.helpCode"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="说明">
<el-input v-model="formData.remark" type="textarea"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="注意事项">
<el-input v-model="formData.attention" type="textarea"></el-input>
</el-form-item>
</el-col>
</el-row>
</el-form>
</el-tab-pane>
<el-tab-pane label="检查项信息" name="second">
<div class="checkScrol">
<table class="datatable">
<thead>
<tr>
<th>选择</th>
<th>项目编码</th>
<th>项目名称</th>
<th>项目说明</th>
</tr>
</thead>
<tbody>
<tr v-for="c in tableData">
<td>
<input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
</td>
<td><label :for="c.id">{{c.code}}</label></td>
<td><label :for="c.id">{{c.name}}</label></td>
<td><label :for="c.id">{{c.remark}}</label></td>
</tr>
</tbody>
</table>
</div>
</el-tab-pane>
</el-tabs>
</template>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible4Edit = false">取消</el-button>
<el-button type="primary" @click="handleEdit()">确定</el-button>
</div>
</el-dialog>
</div>
</div>
</div>
</div>
</body>
<script>
var vue = new Vue({
el: '#app',
data:{
activeName:'first',//添加/编辑窗口Tab标签名称
pagination: {//分页相关属性
currentPage: 1,
pageSize:10,
total:100,
queryString:null,
},
dataList: [],//列表数据
formData: {},//表单数据
tableData:[],//新增和编辑表单中对应的检查项列表数据
checkitemIds:[],//新增和编辑表单中检查项对应的复选框,基于双向绑定可以进行回显和数据提交
dialogFormVisible: false,//控制添加窗口显示/隐藏
dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
},
created() {
//vue钩子函数 异步请求加载数据 /checkgroup.do
//querypagebean(用户输入的参数、页码、每页记录数) 分页组件:total rows
this.findPage();
},
methods: {
//编辑
handleEdit() {
//1.关闭弹出窗口
this.dialogFormVisible4Edit=false;
//提交表单数据 检查组对象和检查ids
axios.post("/checkgroup/edit.do?checkitemIds="+this.checkitemIds,this.formData).then(res=>{
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
//重新刷新页面
this.findPage();
})
},
//添加
handleAdd () {
//没有做校验 大家可以自己去校验 28,29,30....
axios.post("/checkgroup/add.do?checkitemIds="+this.checkitemIds,this.formData).then(res=>{
//新增检查组窗口关闭
this.dialogFormVisible =false;
//新增检查组成功失败提示
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
//重新刷新页面
this.findPage();
})
},
/*handleAdd () {
//记得加校验
axios.post("/checkgroup/add.do?checkitemIds="+this.checkitemIds,this.formData).then(res=>{
//新增检查组窗口关闭
this.dialogFormVisible=false;
//新增检查组成功是失败提示
this.$message({
message: res.data.message,
type: res.data.flag ? "success" : "error"
});
//分页查询
this.findPage();
})
},*/
//分页查询
findPage() {
var queryPageBean={
currentPage: this.pagination.currentPage,//当前页码
pageSize: this.pagination.pageSize,//当前显示条数
queryString: this.pagination.queryString//查询条件
}
axios.post("/checkgroup/findPage.do",queryPageBean).then((response)=>{
this.pagination.total=response.data.total;
this.dataList=response.data.rows;
})
},
findPage2(){
//查询分页优化提升用户体验
this.pagination.currentPage = 1;
this.findPage();
},
// 重置表单
resetForm() {
//可以观察一下,搜索的时候在第二页的时候就搜索不出来第一页的东西了,所以需要重置一下
//清空表单的方法
//检查组表单
this.formData={};
//勾选
this.checkitemIds=[];
//选项卡选中
this.activeName='first';
},
// 弹出添加窗口 新建按钮
handleCreate() {
this.resetForm();
//弹出新增检查组窗口
this.dialogFormVisible=true;
//查询检查项列表数据
axios.get("/checkitem/findAll.do").then(res=>{
if(res.data.flag){
this.tableData=res.data.data;
//查询所有检查项成功
this.$message({
message:res.data.message,
type:"success"
});
}
})
},
// 弹出编辑窗口
handleUpdate(row) {
//编辑检查组
//1.点确定的时候弹出编辑框,检查项回显
//弹出编辑窗口
this.dialogFormVisible4Edit = true;
//回显数据 根据检查组id查询检查组数据
axios.get("/checkgroup/findById.do?groupId="+row.id).then(res=>{
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
if(res.data.flag) {
//如果查询检查组回显成功再显示
this.formData = res.data.data;
//如果检查组查询成功 再查询检查项列表
axios.post('/checkitem/findAll.do').then(res=>{
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
if(res.data.flag) {
//检查项列表回显
this.tableData = res.data.data;
//查询检查项列表成功后 根据检查组id查询检查项ids [28,29,30]
axios.get('/checkgroup/findCheckItemIdsByCheckGroupId.do?groupId='+row.id).then(res=>{
//List<Integer> == res.data.data [28,29,30]
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
if(res.data.flag) {
this.checkitemIds = res.data.data;
}
})
}
})
}
})
//2.提交数据
// 编辑的时候检查组和关联表(勾选)都要更新
//先删除检查组关联的检查项记录(中间表),再重新建立关联关系(插入中间表)
},
//切换页码
handleCurrentChange(currentPage) {
//重新设置页码,重新查询
this.pagination.currentPage=currentPage;
this.findPage();
},
// 删除检查组
//前端:提示是否确定删除,确定的话发送删除请求
//后端:查询检查组和检查表项关系是否存在,存在则无法删除
//查询检查组和套餐表关系是否存在,存在则无法删除
handleDelete(row) {
this.$confirm('确认要删除检查组吗, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//发送删除请求
axios.get('/checkgroup/deleteById.do?id='+row.id).then(res=>{
this.$message({
message: res.data.message,
type: res.data.flag ? 'success':"error"
});
//重新加载数据
this.findPage();
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
}
})
</script>
</html>
2.CheckGroupController.java
/**
* 检查组的表现层
*/
@RestController
@RequestMapping(value="/checkgroup")
public class CheckGroupController {
@Reference
private CheckGroupService checkGroupService;
/**
* 新增检查组
* @param checkGroup
* @param checkitemIds
* @return
*/
@RequestMapping(value = "/add")
public Result add(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds) {
try {
checkGroupService.add(checkGroup,checkitemIds);
return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.ADD_CHECKGROUP_FAIL);
}
}
/**
* 检查组分页
* @param queryPageBean
* @return
*/
@RequestMapping("/findPage")
public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
try {
PageResult pageResult= checkGroupService.findPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize(),queryPageBean.getQueryString());
return pageResult;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@RequestMapping(value = "/findById")
public Result findById(Integer groupId) {
try {
CheckGroup checkGroup=checkGroupService.findById(groupId);
return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroup);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
}
}
/**
* 根据groupid查询CheckItemIds
* @param groupId
* @return
*/
@RequestMapping(value = "/findCheckItemIdsByCheckGroupId")
public Result findCheckItemIdsByCheckGroupId(Integer groupId) {
try {
List<Integer> integerList=checkGroupService.findCheckItemIdsByCheckGroupId(groupId);
return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,integerList);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
}
}
/**
* 编辑检查组
* @param checkGroup
* @param checkitemIds
* @return
*/
@RequestMapping(value = "/edit")
public Result edit(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds) {
try {
checkGroupService.edit(checkGroup,checkitemIds);
return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
} catch (Exception e) {
e.printStackTrace();
return new Result(false,MessageConstant.EDIT_CHECKGROUP_FAIL);
}
}
/**
* 删除检查组
* @param id
* @return
*/
@RequestMapping(value = "/deleteById")
public Result deleteById(Integer id) {
try {
checkGroupService.deleteById(id);
return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
} catch (RuntimeException e) {
e.printStackTrace();
return new Result(false, e.getMessage());
}catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.DELETE_CHECKGROUP_FAIL);
}
}
/**
* 查询所有检查组
* @return
*/
@RequestMapping(value = "/findAll")
public Result findAll() {
try {
List<CheckGroup> checkGroupList=checkGroupService.findAll();
return new Result(true, MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkGroupList);
} catch (Exception e) {
e.printStackTrace();
return new Result(false, MessageConstant.QUERY_CHECKGROUP_FAIL);
}
}
}
3.CheckGroupService.java
public interface CheckGroupService {
/**
* 新增检查组
* @param checkGroup
* @param checkitemIds
*/
void add(CheckGroup checkGroup, Integer[] checkitemIds);
/**
* 检查组分页
* @param currentPage
* @param pageSize
* @param queryString
* @return
*/
PageResult findPage(Integer currentPage, Integer pageSize, String queryString);
/**
* 根据id回显检查组
* @param groupId
* @return
*/
CheckGroup findById(Integer groupId);
/**
* 根据GroupId查询CheckItemIds
* @param groupId
* @return
*/
List<Integer> findCheckItemIdsByCheckGroupId(Integer groupId);
/**
* 编辑检查组
* @param checkGroup
* @param checkitemIds
*/
void edit(CheckGroup checkGroup, Integer[] checkitemIds);
/**
* 删除检查组
* @param id
*/
void deleteById(Integer id);
/**
* 查询所有检查组
* @return
*/
List<CheckGroup> findAll();
}
4.CheckGroupServiceImpl.java
/**
* 检查组的业务层逻辑
*/
@Service(interfaceClass = CheckGroupService.class)
//事务注解之后,导致类由spring代理对象 接口目录和消费者不一致,导致消费者无法正常使用
@Transactional
//解决方案:事务控制加上之后报错需要配置service:interfaceClass = CheckItemService.class
//1.配置中使用cglib方式来创建代理 proxy-target-class=true
//2.服务提供者@Service指定接口服务类型
public class CheckGroupServiceImpl implements CheckGroupService {
@Autowired
private CheckGroupDao checkGroupDao;
/**
* 新增检查组
* 1.往检查组表新增一条记录
* 2.往中间表新增关联id记录
* @param checkGroup
* @param checkitemIds
*/
@Override
public void add(CheckGroup checkGroup, Integer[] checkitemIds) {
//1.往检查组表新增一条记录
checkGroupDao.add(checkGroup);
//2.往中间表新增关联id记录,在下面的方法中循环遍历
// 抽取代码,别的也可以调用
setCheckGroupAndCheckItem(checkGroup.getId(),checkitemIds);
}
@Override
public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
//设置分页参数
PageHelper.startPage(currentPage,pageSize);
//需要分页的语句
Page<CheckGroup> checkGroupPage= checkGroupDao.selectByCondition(queryString);
return new PageResult(checkGroupPage.getTotal(),checkGroupPage.getResult());
}
/**
* 根据id回显检查组
* @param groupId
* @return
*/
@Override
public CheckGroup findById(Integer groupId) {
return checkGroupDao.findById(groupId);
}
/**
* findCheckItemIdsByCheckGroupId
* @param groupId
* @return
*/
@Override
public List<Integer> findCheckItemIdsByCheckGroupId(Integer groupId) {
return checkGroupDao.findCheckItemIdsByCheckGroupId(groupId);
}
/**
* 编辑检查组
* @param checkGroup
* @param checkitemIds
*/
@Override
public void edit(CheckGroup checkGroup, Integer[] checkitemIds) {
//更新检查组表 update语句
checkGroupDao.edit(checkGroup);
//先删除检查组关联的检查记录(中间表)
checkGroupDao.deleteAssociation(checkGroup.getId());
//重新建立关联关系(插入中间表)
setCheckGroupAndCheckItem(checkGroup.getId(),checkitemIds);
}
/**
* 删除检查组
* @param id
*/
@Override
public void deleteById(Integer id) {
//业务角度考虑
//查询检查组和检查项表关系是否存在,存在则无法删除
int count = checkGroupDao.findCountByCheckGroupIdO(id);
if(count>0){
throw new RuntimeException(MessageConstant.DELETE_CHECKITEM_GROUP_FAIL);//一定要install
}
//查询检查组和套餐表关系是否存在,存在则无法删除
int count2 = checkGroupDao.findCountByCheckGroupIdT(id);
if(count2>0){
throw new RuntimeException(MessageConstant.DELETE_CHECKGROUP_SETMEAL_FAIL);//一定要install
}
//以上两个关系都不存在,则可以删除
checkGroupDao.deleteById(id);
}
/**
* 查询所有检查组
* @return
*/
@Override
public List<CheckGroup> findAll() {
return checkGroupDao.findAll();
}
//2.往中间表新增关联id记录
public void setCheckGroupAndCheckItem(Integer groupId,Integer[] checkitemIds){
if(checkitemIds!=null&&checkitemIds.length>0){
for (Integer checkitemId : checkitemIds) {
Map<String,Integer> map=new HashMap<>();
map.put("grounId",groupId);
map.put("checkitemId",checkitemId);
checkGroupDao.setCheckGroupAndCheckItem(map);
}
}
}
}
5.CheckGroupDao.java
/**
* 检查组dao
*/
public interface CheckGroupDao {
/**
* 新增检查组
* @param checkGroup
*/
void add(CheckGroup checkGroup);
/**
* 往中间表插入记录
* @param map
*/
void setCheckGroupAndCheckItem(Map<String, Integer> map);
/**
* 检查组分页
* @param queryString
* @return
*/
Page<CheckGroup> selectByCondition(String queryString);
/**
* 根据id回显检查组
* @param groupId
* @return
*/
CheckGroup findById(Integer groupId);
/**
* findCheckItemIdsByCheckGroupId
* @param groupId
* @return
*/
List<Integer> findCheckItemIdsByCheckGroupId(Integer groupId);
/**
* 更新检查组
* @param checkGroup
*/
void edit(CheckGroup checkGroup);
/**
* 删除关联表
* @param groupId
*/
void deleteAssociation(Integer groupId);
/**
* //查询检查组和检查项表关系是否存在,存在则无法删除
* @param id
* @return
*/
int findCountByCheckGroupIdO(Integer id);
/**
* //查询检查组和套餐关系是否存在,存在则无法删除
* @param id
* @return
*/
int findCountByCheckGroupIdT(Integer id);
/**
* 删除检查组
* @param id
*/
void deleteById(Integer id);
/**
* 查询所有检查组
*/
List<CheckGroup> findAll();
/**
* findCheckGroupListBySetmealId
* @param id
* @return
*/
List<CheckGroup> findCheckGroupListBySetmealId(Integer id);
List<CheckGroup> findCheckGroupListById(Integer id);
}
6.CheckGroupDao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--
namespace="Dao接口的全限定名"
-->
<mapper namespace="com.itheima.dao.CheckGroupDao">
<!--<!–新增检查组–>
<insert id="add" parameterType="com.itheima.pojo.CheckGroup">
/*获取检查组的id*/
<selectKey resultType="int" order="AFTER" keyProperty="id">
select LAST_INSERT_ID()
</selectKey>
insert into t_checkgroup(code,name,helpCode,,sex,remark)
values (#{code},#{name},#{helpCode},#{},#{sex},#{remark})
</insert>
<insert id="setCheckGroupAndCheckItem" parameterType="map">
insert into t_checkgroup_checkitem(checkgroup_id,checkitem_id)
values (#{grounId},#{checkitemId})
</insert>-->
<!--新增检查组-->
<insert id="add" parameterType="com.itheima.pojo.CheckGroup">
<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>
insert into t_checkgroup(code,name,sex,helpCode,remark,attention)
values
(#{code},#{name},#{sex},#{helpCode},#{remark},#{attention})
</insert>
<!--设置检查组和检查项的关联关系-->
<insert id="setCheckGroupAndCheckItem" parameterType="hashmap">
insert into t_checkgroup_checkitem(checkgroup_id,checkitem_id)
values
(#{grounId},#{checkitemId})
</insert>
<!--检查组分页查询-->
<select id="selectByCondition" parameterType="string" resultType="com.itheima.pojo.CheckGroup">
select * from t_checkgroup
<if test="value !=null and value.length>0">
where name =#{value} or code =#{value} or helpCode =#{helpCode}
</if>
</select>
<!--根据id回显检查项-->
<select id="findById" parameterType="int" resultType="com.itheima.pojo.CheckGroup">
select * from t_checkgroup where id=#{groupId}
</select>
<!--findCheckItemIdsByCheckGroupId-->
<select id="findCheckItemIdsByCheckGroupId" resultType="int" parameterType="int">
SELECT checkitem_id FROM t_checkgroup_checkitem where checkgroup_id=#{groupId}
</select>
<!--编辑-->
<update id="edit" parameterType="com.itheima.pojo.CheckGroup">
update t_checkgroup
<set>
<if test="code!=null and code.length>0">
code=#{code},
</if>
<if test="name!=null and name.length>0">
name=#{name},
</if>
<if test="helpCode!=null and helpCode.length>0">
helpCode=#{helpCode},
</if>
<if test="sex!=null and sex.length>0">
sex=#{sex},
</if>
<if test="remark!=null and remark.length>0">
remark=#{remark},
</if>
<if test="attention!=null and attention.length>0">
attention=#{attention},
</if>
</set>
where id = #{id}
</update>
<!--删除中间关系表-->
<delete id="deleteAssociation" parameterType="int">
delete from t_checkgroup_checkitem where checkgroup_id=#{groupId}
</delete>
<!--查询检查组和检查项表关系是否存在-->
<select id="findCountByCheckGroupIdO" parameterType="int" resultType="int">
select count(*) from t_checkgroup_checkitem where checkgroup_id = #{id}
</select>
<!--查询检查组和套餐表关系是否存在-->
<select id="findCountByCheckGroupIdT" parameterType="int" resultType="int">
select count(*) from t_setmeal_checkgroup where checkgroup_id = #{id}
</select>
<!--删除检查组-->
<delete id="deleteById" parameterType="int">
delete from t_checkgroup where id = #{id}
</delete>
<!--查询所有检查组-->
<select id="findAll" resultType="com.itheima.pojo.CheckGroup">
select * from t_checkgroup
</select>
<!--使用套餐id,查询套餐id具有的检查组的集合-->
<select id="findCheckGroupListBySetmealId" parameterType="int" resultType="com.itheima.pojo.CheckGroup">
SELECT * FROM t_checkgroup WHERE id IN (SELECT checkgroup_id FROM t_setmeal_checkgroup WHERE setmeal_id = #{setmealId})
</select>
<!--检查组关联检查项-->
<resultMap type="com.itheima.pojo.CheckGroup" id="findByIdResultMap">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="code" property="code"/>
<result column="helpCode" property="helpCode"/>
<result column="sex" property="sex"/>
<result column="remark" property="remark"/>
<result column="attention" property="attention"/>
<!--检查组关联检查项 条件是id-->
<collection property="checkItems" column="id"
select="com.itheima.dao.CheckItemDao.findCheckItemListById">
</collection>
</resultMap>
<!--根据套餐id查询检查组信息-->
<select id="findCheckGroupListById" resultMap="findByIdResultMap">
select * from t_checkgroup where id
in (select checkgroup_id from t_setmeal_checkgroup where setmeal_id=#{id})
</select>
</mapper>