This commit is contained in:
parent
8473e7a4e4
commit
4db542232c
|
|
@ -98,6 +98,11 @@
|
||||||
<el-table-column label="学生姓名" align="center" prop="name" />
|
<el-table-column label="学生姓名" align="center" prop="name" />
|
||||||
<el-table-column label="电话" align="center" prop="tel" />
|
<el-table-column label="电话" align="center" prop="tel" />
|
||||||
<el-table-column label="电子邮件" align="center" prop="email" />
|
<el-table-column label="电子邮件" align="center" prop="email" />
|
||||||
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button
|
<el-button
|
||||||
|
|
@ -138,6 +143,24 @@
|
||||||
<el-form-item label="电子邮件" prop="email">
|
<el-form-item label="电子邮件" prop="email">
|
||||||
<el-input v-model="form.email" placeholder="请输入电子邮件" />
|
<el-input v-model="form.email" placeholder="请输入电子邮件" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-divider content-position="center">成绩信息</el-divider>
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddResults">添加</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteResults">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
<el-table :data="resultsList" :row-class-name="rowResultsIndex" @selection-change="handleResultsSelectionChange" ref="results">
|
||||||
|
<el-table-column type="selection" width="50" align="center" />
|
||||||
|
<el-table-column label="序号" align="center" prop="index" width="50"/>
|
||||||
|
<el-table-column label="java成绩" prop="java">
|
||||||
|
<template slot-scope="scope">
|
||||||
|
<el-input v-model="scope.row.java" placeholder="请输入java成绩" />
|
||||||
|
</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="submitForm">确 定</el-button>
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
|
@ -148,9 +171,9 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { listStu, getStu, delStu, addStu, updateStu, exportStu } from "@/api/test/stu";
|
import { listStu, getStu, delStu, addStu, updateStu, exportStu } from "@/api/test/stu";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Stu",
|
name: "Stu",
|
||||||
components: {
|
components: {
|
||||||
},
|
},
|
||||||
|
|
@ -160,6 +183,8 @@ export default {
|
||||||
loading: true,
|
loading: true,
|
||||||
// 选中数组
|
// 选中数组
|
||||||
ids: [],
|
ids: [],
|
||||||
|
// 子表选中数据
|
||||||
|
checkedResults: [],
|
||||||
// 非单个禁用
|
// 非单个禁用
|
||||||
single: true,
|
single: true,
|
||||||
// 非多个禁用
|
// 非多个禁用
|
||||||
|
|
@ -170,6 +195,8 @@ export default {
|
||||||
total: 0,
|
total: 0,
|
||||||
// 学生表格数据
|
// 学生表格数据
|
||||||
stuList: [],
|
stuList: [],
|
||||||
|
// 成绩表格数据
|
||||||
|
resultsList: [],
|
||||||
// 弹出层标题
|
// 弹出层标题
|
||||||
title: "",
|
title: "",
|
||||||
// 是否显示弹出层
|
// 是否显示弹出层
|
||||||
|
|
@ -183,23 +210,11 @@ export default {
|
||||||
name: null,
|
name: null,
|
||||||
tel: null,
|
tel: null,
|
||||||
email: null,
|
email: null,
|
||||||
createTime: null,
|
|
||||||
},
|
},
|
||||||
// 表单参数
|
// 表单参数
|
||||||
form: {},
|
form: {},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rules: {
|
rules: {
|
||||||
name: [
|
|
||||||
{ required: true, message: "学生姓名不能为空}", trigger: "blur" },
|
|
||||||
],
|
|
||||||
tel: [
|
|
||||||
{ required: true, message: "电话不能为空}", trigger: "blur" },
|
|
||||||
{ pattern: /^1[0-9]{10}$/, message: '电话格式有误', trigger:"blur"},
|
|
||||||
],
|
|
||||||
email: [
|
|
||||||
{ required: true, message: "电子邮件不能为空}", trigger: "blur" },
|
|
||||||
{ pattern: /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, message: '电子邮件格式有误', trigger:"blur"},
|
|
||||||
],
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -228,11 +243,10 @@ export default {
|
||||||
name: null,
|
name: null,
|
||||||
tel: null,
|
tel: null,
|
||||||
email: null,
|
email: null,
|
||||||
createTime: null,
|
|
||||||
createBy: null,
|
createBy: null,
|
||||||
updateTime: null,
|
|
||||||
updateBy: null
|
updateBy: null
|
||||||
};
|
};
|
||||||
|
this.resultsList = [];
|
||||||
this.resetForm("form");
|
this.resetForm("form");
|
||||||
},
|
},
|
||||||
/** 搜索按钮操作 */
|
/** 搜索按钮操作 */
|
||||||
|
|
@ -264,6 +278,7 @@ export default {
|
||||||
const id = row.id || this.ids
|
const id = row.id || this.ids
|
||||||
getStu(id).then(response => {
|
getStu(id).then(response => {
|
||||||
this.form = response.data;
|
this.form = response.data;
|
||||||
|
this.resultsList = response.data.resultsList;
|
||||||
this.open = true;
|
this.open = true;
|
||||||
this.title = "修改学生";
|
this.title = "修改学生";
|
||||||
});
|
});
|
||||||
|
|
@ -272,6 +287,7 @@ export default {
|
||||||
submitForm() {
|
submitForm() {
|
||||||
this.$refs["form"].validate(valid => {
|
this.$refs["form"].validate(valid => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
|
this.form.resultsList = this.resultsList;
|
||||||
if (this.form.id != null) {
|
if (this.form.id != null) {
|
||||||
updateStu(this.form).then(response => {
|
updateStu(this.form).then(response => {
|
||||||
this.msgSuccess("修改成功");
|
this.msgSuccess("修改成功");
|
||||||
|
|
@ -302,6 +318,33 @@ export default {
|
||||||
this.msgSuccess("删除成功");
|
this.msgSuccess("删除成功");
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
/** 成绩序号 */
|
||||||
|
rowResultsIndex({ row, rowIndex }) {
|
||||||
|
row.index = rowIndex + 1;
|
||||||
|
},
|
||||||
|
/** 成绩添加按钮操作 */
|
||||||
|
handleAddResults() {
|
||||||
|
let obj = {};
|
||||||
|
obj.java = "";
|
||||||
|
this.resultsList.push(obj);
|
||||||
|
},
|
||||||
|
/** 成绩删除按钮操作 */
|
||||||
|
handleDeleteResults() {
|
||||||
|
if (this.checkedResults.length == 0) {
|
||||||
|
this.$alert("请先选择要删除的成绩数据", "提示", { confirmButtonText: "确定", });
|
||||||
|
} else {
|
||||||
|
this.resultsList.splice(this.checkedResults[0].index - 1, 1);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** 单选框选中数据 */
|
||||||
|
handleResultsSelectionChange(selection) {
|
||||||
|
if (selection.length > 1) {
|
||||||
|
this.$refs.results.clearSelection();
|
||||||
|
this.$refs.results.toggleRowSelection(selection.pop());
|
||||||
|
} else {
|
||||||
|
this.checkedResults = selection;
|
||||||
|
}
|
||||||
|
},
|
||||||
/** 导出按钮操作 */
|
/** 导出按钮操作 */
|
||||||
handleExport() {
|
handleExport() {
|
||||||
const queryParams = this.queryParams;
|
const queryParams = this.queryParams;
|
||||||
|
|
@ -316,5 +359,5 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -304,10 +304,10 @@ public class GenTableServiceImpl implements IGenTableService {
|
||||||
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
ZipOutputStream zip = new ZipOutputStream(outputStream);
|
||||||
for (String tableName : tableNames) {
|
for (String tableName : tableNames) {
|
||||||
zip = generatorCode(tableName, zip);
|
zip = generatorCode(tableName, zip);
|
||||||
generatorCode(tableName, zip);
|
// generatorCode(tableName, zip);
|
||||||
// if (zip==null){
|
if (zip==null){
|
||||||
// return null;
|
return null;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
IOUtils.closeQuietly(zip);
|
IOUtils.closeQuietly(zip);
|
||||||
return outputStream.toByteArray();
|
return outputStream.toByteArray();
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,13 @@ package ${packageName}.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
import com.hchyun.common.constant.ReturnConstants;
|
import com.hchyun.common.constant.ReturnConstants;
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
#if($column.javaField == 'createTime' || $column.javaField == 'updateTime')
|
||||||
import com.hchyun.common.utils.DateUtils;
|
import com.hchyun.common.utils.DateUtils;
|
||||||
#break
|
|
||||||
#end
|
#end
|
||||||
#if($column.javaField == 'updateBy' || $column.javaField == 'createBy')
|
#if($column.javaField == 'updateBy' || $column.javaField == 'createBy')
|
||||||
import com.hchyun.common.utils.SecurityUtils;
|
import com.hchyun.common.utils.SecurityUtils;
|
||||||
#break
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
import com.hchyun.common.utils.ServerResult;
|
import com.hchyun.common.utils.ServerResult;
|
||||||
|
|
@ -105,17 +102,18 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
int rows = ${className}Dao.insert${ClassName}(${className});
|
int renewal = ${className}Dao.insert${ClassName}(${className});
|
||||||
insert${subClassName}(${className});
|
if (insert${subClassName}(${className})){
|
||||||
return rows;
|
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
Integer renewal = ${className}Dao.insert${ClassName}(${className});
|
Integer renewal = ${className}Dao.insert${ClassName}(${className});
|
||||||
|
#end
|
||||||
if (renewal >0){
|
if (renewal >0){
|
||||||
return new ServerResult<Integer>(true,renewal);
|
return new ServerResult<Integer>(true,renewal);
|
||||||
}else {
|
}else {
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
||||||
}
|
}
|
||||||
#end
|
|
||||||
}catch (RuntimeException e){
|
}catch (RuntimeException e){
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
||||||
|
|
@ -144,7 +142,9 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
#end
|
#end
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
${className}Dao.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
|
${className}Dao.delete${subClassName}By${subTableFkClassName}(${className}.get${pkColumn.capJavaField}());
|
||||||
insert${subClassName}(${className});
|
if (insert${subClassName}(${className})){
|
||||||
|
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
Integer renewal = ${className}Dao.update${ClassName}(${className});
|
Integer renewal = ${className}Dao.update${ClassName}(${className});
|
||||||
if (renewal >0){
|
if (renewal >0){
|
||||||
|
|
@ -171,6 +171,7 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
public ServerResult<Integer> delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
|
public ServerResult<Integer> delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) {
|
||||||
try {
|
try {
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
|
//批量删除子表数据
|
||||||
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
${className}Dao.delete${subClassName}By${subTableFkClassName}s(${pkColumn.javaField}s);
|
||||||
#end
|
#end
|
||||||
Integer renewal = ${className}Dao.delete${ClassName}ByIds(${pkColumn.javaField}s);
|
Integer renewal = ${className}Dao.delete${ClassName}ByIds(${pkColumn.javaField}s);
|
||||||
|
|
@ -195,6 +196,7 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
public ServerResult<Integer> delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
public ServerResult<Integer> delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) {
|
||||||
try {
|
try {
|
||||||
#if($table.sub)
|
#if($table.sub)
|
||||||
|
//删除子表数据
|
||||||
${className}Dao.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
${className}Dao.delete${subClassName}By${subTableFkClassName}(${pkColumn.javaField});
|
||||||
#end
|
#end
|
||||||
Integer renewal = ${className}Dao.delete${ClassName}ById(${pkColumn.javaField});
|
Integer renewal = ${className}Dao.delete${ClassName}ById(${pkColumn.javaField});
|
||||||
|
|
@ -215,23 +217,23 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
|
||||||
*
|
*
|
||||||
* @param ${className} ${functionName}对象
|
* @param ${className} ${functionName}对象
|
||||||
*/
|
*/
|
||||||
public void insert${subClassName}(${ClassName} ${className})
|
public boolean insert${subClassName}(${ClassName} ${className}) {
|
||||||
{
|
|
||||||
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
|
List<${subClassName}> ${subclassName}List = ${className}.get${subClassName}List();
|
||||||
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
|
Long ${pkColumn.javaField} = ${className}.get${pkColumn.capJavaField}();
|
||||||
if (StringUtils.isNotNull(${subclassName}List))
|
if (StringUtils.isNotNull(${subclassName}List)) {
|
||||||
{
|
|
||||||
List<${subClassName}> list = new ArrayList<${subClassName}>();
|
List<${subClassName}> list = new ArrayList<${subClassName}>();
|
||||||
for (${subClassName} ${subclassName} : ${subclassName}List)
|
for (${subClassName} ${subclassName} : ${subclassName}List){
|
||||||
{
|
|
||||||
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
|
${subclassName}.set${subTableFkClassName}(${pkColumn.javaField});
|
||||||
list.add(${subclassName});
|
list.add(${subclassName});
|
||||||
}
|
}
|
||||||
if (list.size() > 0)
|
if (list.size() > 0) {
|
||||||
{
|
Integer renewal = ${className}Dao.batch${subClassName}(list);
|
||||||
${className}Dao.batch${subClassName}(list);
|
if (renewal>0){
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,9 @@ package ${packageName}.entity;
|
||||||
import ${import};
|
import ${import};
|
||||||
#end
|
#end
|
||||||
import com.hchyun.common.annotation.Excel;
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ${subTable.functionName}对象 ${subTableName}
|
* ${subTable.functionName}对象 ${subTableName}
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,7 @@ export default {
|
||||||
reset() {
|
reset() {
|
||||||
this.form = {
|
this.form = {
|
||||||
#foreach ($column in $columns)
|
#foreach ($column in $columns)
|
||||||
#if($column.htmlType != "datetime" && $column.queryType != "BETWEEN")
|
#if($column.htmlType != "datetime" && $column.queryType != "BETWEEN" && $column.javaField != 'createBy' && $column.javaField != 'updateBy')
|
||||||
#if($column.htmlType == "radio")
|
#if($column.htmlType == "radio")
|
||||||
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
|
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,9 +126,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="batch${subClassName}">
|
<insert id="batch${subClassName}">
|
||||||
insert into ${subTableName}(#foreach($column in $subTable.columns) $column.columnName#if($velocityCount != $subTable.columns.size()),#end#end) values
|
insert into ${subTableName}(#set($index = 0)#foreach($column in $subTable.columns)#if($column.isPk.equals("1"))#set($insex = 1)#else$column.columnName#if($velocityCount != ($subTable.columns.size()-$index)),#end#end#end) values
|
||||||
<foreach item="item" index="index" collection="list" separator=",">
|
<foreach item="item" index="index" collection="list" separator=",">
|
||||||
(#foreach($column in $subTable.columns) #{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end)
|
(#foreach($column in $subTable.columns)#if($column.isPk.equals("1"))#set($index = 1)#else#{item.$column.javaField}#if($velocityCount != $subTable.columns.size()),#end#end#end)
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
#end
|
#end
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.hchyun.test.dao;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.hchyun.test.entity.Stu;
|
import com.hchyun.test.entity.Stu;
|
||||||
|
import com.hchyun.test.entity.Results;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 学生Mapper接口
|
* 学生Mapper接口
|
||||||
|
|
@ -58,4 +59,29 @@ public interface StuDao
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteStuByIds(Long[] ids);
|
public int deleteStuByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除成绩
|
||||||
|
*
|
||||||
|
* @param customerIds 需要删除的数据ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int deleteResultsByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增成绩
|
||||||
|
*
|
||||||
|
* @param resultsList 成绩列表
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int batchResults(List<Results> resultsList);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过学生ID删除成绩信息
|
||||||
|
*
|
||||||
|
* @param roleId 角色ID
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
int deleteResultsBySId(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
package com.hchyun.test.entity;
|
||||||
|
|
||||||
|
import com.hchyun.common.annotation.Excel;
|
||||||
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成绩对象 sys_results
|
||||||
|
*
|
||||||
|
* @author hchyun
|
||||||
|
* @date 2021-01-22
|
||||||
|
*/
|
||||||
|
public class Results extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** id */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 学生id */
|
||||||
|
@Excel(name = "学生id")
|
||||||
|
private Long sId;
|
||||||
|
|
||||||
|
/** java成绩 */
|
||||||
|
@Excel(name = "java成绩")
|
||||||
|
private Long java;
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setSId(Long sId)
|
||||||
|
{
|
||||||
|
this.sId = sId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getSId()
|
||||||
|
{
|
||||||
|
return sId;
|
||||||
|
}
|
||||||
|
public void setJava(Long java)
|
||||||
|
{
|
||||||
|
this.java = java;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getJava()
|
||||||
|
{
|
||||||
|
return java;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("id", getId())
|
||||||
|
.append("sId", getSId())
|
||||||
|
.append("java", getJava())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.hchyun.test.entity;
|
package com.hchyun.test.entity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import com.hchyun.common.annotation.Excel;
|
import com.hchyun.common.annotation.Excel;
|
||||||
import com.hchyun.common.core.entity.BaseEntity;
|
import com.hchyun.common.core.entity.BaseEntity;
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
|
@ -30,6 +31,9 @@ public class Stu extends BaseEntity
|
||||||
@Excel(name = "电子邮件")
|
@Excel(name = "电子邮件")
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
|
/** 成绩信息 */
|
||||||
|
private List<Results> resultsList;
|
||||||
|
|
||||||
public void setId(Long id)
|
public void setId(Long id)
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -67,6 +71,16 @@ public class Stu extends BaseEntity
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Results> getResultsList()
|
||||||
|
{
|
||||||
|
return resultsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResultsList(List<Results> resultsList)
|
||||||
|
{
|
||||||
|
this.resultsList = resultsList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
|
@ -78,6 +92,7 @@ public class Stu extends BaseEntity
|
||||||
.append("createBy", getCreateBy())
|
.append("createBy", getCreateBy())
|
||||||
.append("updateTime", getUpdateTime())
|
.append("updateTime", getUpdateTime())
|
||||||
.append("updateBy", getUpdateBy())
|
.append("updateBy", getUpdateBy())
|
||||||
|
.append("resultsList", getResultsList())
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.hchyun.test.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
import com.hchyun.common.constant.ReturnConstants;
|
import com.hchyun.common.constant.ReturnConstants;
|
||||||
import com.hchyun.common.utils.DateUtils;
|
import com.hchyun.common.utils.DateUtils;
|
||||||
import com.hchyun.common.utils.SecurityUtils;
|
import com.hchyun.common.utils.SecurityUtils;
|
||||||
|
|
@ -11,6 +10,11 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import com.hchyun.common.utils.StringUtils;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import com.hchyun.test.entity.Results;
|
||||||
import com.hchyun.test.dao.StuDao;
|
import com.hchyun.test.dao.StuDao;
|
||||||
import com.hchyun.test.entity.Stu;
|
import com.hchyun.test.entity.Stu;
|
||||||
import com.hchyun.test.service.StuService;
|
import com.hchyun.test.service.StuService;
|
||||||
|
|
@ -38,14 +42,14 @@ public class StuServiceImpl implements StuService {
|
||||||
public ServerResult<Stu> selectStuById(Long id) {
|
public ServerResult<Stu> selectStuById(Long id) {
|
||||||
try {
|
try {
|
||||||
Stu stu = stuDao.selectStuById(id);
|
Stu stu = stuDao.selectStuById(id);
|
||||||
if (stu != null){
|
if (stu != null) {
|
||||||
return new ServerResult<Stu>(true,stu);
|
return new ServerResult<Stu>(true, stu);
|
||||||
}else {
|
} else {
|
||||||
return new ServerResult<Stu>(false, ReturnConstants.RESULT_EMPTY);
|
return new ServerResult<Stu>(false, ReturnConstants.RESULT_EMPTY);
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Stu>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Stu>(false, ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,14 +63,14 @@ public class StuServiceImpl implements StuService {
|
||||||
public ServerResult<List<Stu>> selectStuList(Stu stu) {
|
public ServerResult<List<Stu>> selectStuList(Stu stu) {
|
||||||
try {
|
try {
|
||||||
List<Stu> stuList = stuDao.selectStuList(stu);
|
List<Stu> stuList = stuDao.selectStuList(stu);
|
||||||
if (stuList.size()>0){
|
if (stuList.size() > 0) {
|
||||||
return new ServerResult<List<Stu>>(true,stuList);
|
return new ServerResult<List<Stu>>(true, stuList);
|
||||||
}else {
|
} else {
|
||||||
return new ServerResult<List<Stu>>(false,ReturnConstants.RESULT_EMPTY);
|
return new ServerResult<List<Stu>>(false, ReturnConstants.RESULT_EMPTY);
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<List<Stu>>(false,ReturnConstants.DB_EX);
|
return new ServerResult<List<Stu>>(false, ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,20 +80,22 @@ public class StuServiceImpl implements StuService {
|
||||||
* @param stu 学生
|
* @param stu 学生
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<Integer> insertStu(Stu stu) {
|
public ServerResult<Integer> insertStu(Stu stu) {
|
||||||
try {
|
try {
|
||||||
stu.setCreateTime(DateUtils.getNowDate());
|
stu.setCreateTime(DateUtils.getNowDate());
|
||||||
stu.setCreateBy(SecurityUtils.getUserId());
|
stu.setCreateBy(SecurityUtils.getUserId());
|
||||||
Integer renewal = stuDao.insertStu(stu);
|
int rows = stuDao.insertStu(stu);
|
||||||
if (renewal >0){
|
insertResults(stu);
|
||||||
return new ServerResult<Integer>(true,renewal);
|
if (rows > 0) {
|
||||||
}else {
|
return new ServerResult<Integer>(true, rows);
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
} else {
|
||||||
|
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -99,21 +105,26 @@ public class StuServiceImpl implements StuService {
|
||||||
* @param stu 学生
|
* @param stu 学生
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<Integer> updateStu(Stu stu) {
|
public ServerResult<Integer> updateStu(Stu stu) {
|
||||||
try {
|
try {
|
||||||
stu.setUpdateTime(DateUtils.getNowDate());
|
stu.setUpdateTime(DateUtils.getNowDate());
|
||||||
stu.setUpdateBy(SecurityUtils.getUserId());
|
stu.setUpdateBy(SecurityUtils.getUserId());
|
||||||
Integer renewal = stuDao.updateStu(stu);
|
stuDao.deleteResultsBySId(stu.getId());
|
||||||
if (renewal >0){
|
if (insertResults(stu)){
|
||||||
return new ServerResult<Integer>(true,renewal);
|
|
||||||
}else {
|
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
|
||||||
}
|
|
||||||
}catch (RuntimeException e){
|
|
||||||
logger.error(e.getMessage());
|
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
|
Integer renewal = stuDao.updateStu(stu);
|
||||||
|
if (renewal > 0) {
|
||||||
|
return new ServerResult<Integer>(true, renewal);
|
||||||
|
} else {
|
||||||
|
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
logger.error(e.getMessage());
|
||||||
|
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -122,18 +133,21 @@ public class StuServiceImpl implements StuService {
|
||||||
* @param ids 需要删除的学生ID
|
* @param ids 需要删除的学生ID
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<Integer> deleteStuByIds(Long[] ids) {
|
public ServerResult<Integer> deleteStuByIds(Long[] ids) {
|
||||||
try {
|
try {
|
||||||
|
//todo 批量删除子表数据
|
||||||
|
stuDao.deleteResultsByIds(ids);
|
||||||
Integer renewal = stuDao.deleteStuByIds(ids);
|
Integer renewal = stuDao.deleteStuByIds(ids);
|
||||||
if (renewal >0){
|
if (renewal > 0) {
|
||||||
return new ServerResult<Integer>(true,renewal);
|
return new ServerResult<Integer>(true, renewal);
|
||||||
}else {
|
} else {
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,15 +160,41 @@ public class StuServiceImpl implements StuService {
|
||||||
@Override
|
@Override
|
||||||
public ServerResult<Integer> deleteStuById(Long id) {
|
public ServerResult<Integer> deleteStuById(Long id) {
|
||||||
try {
|
try {
|
||||||
|
//todo 删除子表数据
|
||||||
|
stuDao.deleteResultsBySId(id);
|
||||||
Integer renewal = stuDao.deleteStuById(id);
|
Integer renewal = stuDao.deleteStuById(id);
|
||||||
if (renewal >0){
|
if (renewal > 0) {
|
||||||
return new ServerResult<Integer>(true,renewal);
|
return new ServerResult<Integer>(true, renewal);
|
||||||
}else {
|
} else {
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
|
return new ServerResult<Integer>(false, ReturnConstants.SYS_FAILL);
|
||||||
}
|
}
|
||||||
}catch (RuntimeException e){
|
} catch (RuntimeException e) {
|
||||||
logger.error(e.getMessage());
|
logger.error(e.getMessage());
|
||||||
return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
|
return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增成绩信息
|
||||||
|
*
|
||||||
|
* @param stu 学生对象
|
||||||
|
*/
|
||||||
|
public boolean insertResults(Stu stu) {
|
||||||
|
List<Results> resultsList = stu.getResultsList();
|
||||||
|
Long id = stu.getId();
|
||||||
|
if (StringUtils.isNotNull(resultsList)) {
|
||||||
|
List<Results> list = new ArrayList<Results>();
|
||||||
|
for (Results results : resultsList) {
|
||||||
|
results.setSId(id);
|
||||||
|
list.add(results);
|
||||||
|
}
|
||||||
|
if (list.size() > 0) {
|
||||||
|
Integer renewal = stuDao.batchResults(list);
|
||||||
|
if (renewal>0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper
|
<!DOCTYPE mapper
|
||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.hchyun.test.dao.StuDao">
|
<mapper namespace="com.hchyun.test.dao.StuDao">
|
||||||
|
|
||||||
<resultMap type="Stu" id="StuResult">
|
<resultMap type="Stu" id="StuResult">
|
||||||
|
|
@ -15,6 +15,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<result property="updateBy" column="update_by" />
|
<result property="updateBy" column="update_by" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
|
<resultMap id="StuResultsResult" type="Stu" extends="StuResult">
|
||||||
|
<collection property="resultsList" notNullColumn="id" javaType="java.util.List" resultMap="ResultsResult" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<resultMap type="Results" id="ResultsResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="sId" column="s_id" />
|
||||||
|
<result property="java" column="java" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectStuVo">
|
<sql id="selectStuVo">
|
||||||
select id, name, tel, email, create_time, create_by, update_time, update_by from sys_stu
|
select id, name, tel, email, create_time, create_by, update_time, update_by from sys_stu
|
||||||
</sql>
|
</sql>
|
||||||
|
|
@ -29,26 +39,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectStuById" parameterType="Long" resultMap="StuResult">
|
<select id="selectStuById" parameterType="Long" resultMap="StuResultsResult">
|
||||||
<include refid="selectStuVo"/>
|
select a.id, a.name, a.tel, a.email, a.create_time, a.create_by, a.update_time, a.update_by,
|
||||||
where id = #{id}
|
b.id, b.s_id, b.java
|
||||||
|
from sys_stu a
|
||||||
|
left join sys_results b on b.s_id = a.id
|
||||||
|
where a.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertStu" parameterType="Stu" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insertStu" parameterType="Stu" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into sys_stu
|
insert into sys_stu
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="name != null and name != ''">name,</if>
|
<if test="name != null">name,</if>
|
||||||
<if test="tel != null">tel,</if>
|
<if test="tel != null">tel,</if>
|
||||||
<if test="email != null and email != ''">email,</if>
|
<if test="email != null">email,</if>
|
||||||
<if test="createTime != null">create_time,</if>
|
<if test="createTime != null">create_time,</if>
|
||||||
<if test="createBy != null">create_by,</if>
|
<if test="createBy != null">create_by,</if>
|
||||||
<if test="updateTime != null">update_time,</if>
|
<if test="updateTime != null">update_time,</if>
|
||||||
<if test="updateBy != null">update_by,</if>
|
<if test="updateBy != null">update_by,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="name != null and name != ''">#{name},</if>
|
<if test="name != null">#{name},</if>
|
||||||
<if test="tel != null">#{tel},</if>
|
<if test="tel != null">#{tel},</if>
|
||||||
<if test="email != null and email != ''">#{email},</if>
|
<if test="email != null">#{email},</if>
|
||||||
<if test="createTime != null">#{createTime},</if>
|
<if test="createTime != null">#{createTime},</if>
|
||||||
<if test="createBy != null">#{createBy},</if>
|
<if test="createBy != null">#{createBy},</if>
|
||||||
<if test="updateTime != null">#{updateTime},</if>
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
|
@ -59,9 +72,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<update id="updateStu" parameterType="Stu">
|
<update id="updateStu" parameterType="Stu">
|
||||||
update sys_stu
|
update sys_stu
|
||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="name != null and name != ''">name = #{name},</if>
|
<if test="name != null">name = #{name},</if>
|
||||||
<if test="tel != null">tel = #{tel},</if>
|
<if test="tel != null">tel = #{tel},</if>
|
||||||
<if test="email != null and email != ''">email = #{email},</if>
|
<if test="email != null">email = #{email},</if>
|
||||||
<if test="createTime != null">create_time = #{createTime},</if>
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
<if test="createBy != null">create_by = #{createBy},</if>
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
|
@ -80,4 +93,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteResultsBySIds" parameterType="String">
|
||||||
|
delete from sys_results where s_id in
|
||||||
|
<foreach item="sId" collection="array" open="(" separator="," close=")">
|
||||||
|
#{sId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteResultsBySId" parameterType="Long">
|
||||||
|
delete from sys_results where s_id = #{sId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<insert id="batchResults">
|
||||||
|
insert into sys_results( s_id, java) values
|
||||||
|
<foreach item="item" index="index" collection="list" separator=",">
|
||||||
|
( #{item.sId}, #{item.java})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue