This commit is contained in:
20932067@zju.edu.cn 2021-01-22 23:35:32 +08:00
parent 8473e7a4e4
commit 4db542232c
11 changed files with 462 additions and 237 deletions

View File

@ -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
@ -117,7 +122,7 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination <pagination
v-show="total>0" v-show="total>0"
:total="total" :total="total"
@ -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,150 +171,143 @@
</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: {
},
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
stuList: [],
//
title: "",
//
open: false,
//
daterangeCreateTime: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
tel: null,
email: null,
createTime: null,
},
//
form: {},
//
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"},
],
}
};
},
created() {
this.getList();
},
methods: {
/** 查询学生列表 */
getList() {
this.loading = true;
listStu(this.addCreateDateRange(this.queryParams,this.daterangeCreateTime)).then(response =>{
this.stuList = response.rows;
this.total = response.total;
this.loading = false;
});
}, },
// data() {
cancel() { return {
this.open = false; //
this.reset(); loading: true,
}, //
// ids: [],
reset() { //
this.form = { checkedResults: [],
id: null, //
name: null, single: true,
tel: null, //
email: null, multiple: true,
createTime: null, //
createBy: null, showSearch: true,
updateTime: null, //
updateBy: null total: 0,
//
stuList: [],
//
resultsList: [],
//
title: "",
//
open: false,
//
daterangeCreateTime: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
name: null,
tel: null,
email: null,
},
//
form: {},
//
rules: {
}
}; };
this.resetForm("form");
}, },
/** 搜索按钮操作 */ created() {
handleQuery() {
this.queryParams.pageNum = 1;
this.getList(); this.getList();
}, },
/** 重置按钮操作 */ methods: {
resetQuery() { /** 查询学生列表 */
this.daterangeCreateTime = []; getList() {
this.resetForm("queryForm"); this.loading = true;
this.handleQuery(); listStu(this.addCreateDateRange(this.queryParams,this.daterangeCreateTime)).then(response =>{
}, this.stuList = response.rows;
// this.total = response.total;
handleSelectionChange(selection) { this.loading = false;
this.ids = selection.map(item => item.id) });
this.single = selection.length!==1 },
this.multiple = !selection.length //
}, cancel() {
/** 新增按钮操作 */ this.open = false;
handleAdd() { this.reset();
this.reset(); },
this.open = true; //
this.title = "添加学生"; reset() {
}, this.form = {
/** 修改按钮操作 */ id: null,
handleUpdate(row) { name: null,
this.reset(); tel: null,
const id = row.id || this.ids email: null,
getStu(id).then(response => { createBy: null,
this.form = response.data; updateBy: null
};
this.resultsList = [];
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.daterangeCreateTime = [];
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true; this.open = true;
this.title = "修改学生"; this.title = "添加学生";
}); },
}, /** 修改按钮操作 */
/** 提交按钮 */ handleUpdate(row) {
submitForm() { this.reset();
this.$refs["form"].validate(valid => { const id = row.id || this.ids
if (valid) { getStu(id).then(response => {
if (this.form.id != null) { this.form = response.data;
updateStu(this.form).then(response => { this.resultsList = response.data.resultsList;
this.msgSuccess("修改成功"); this.open = true;
this.open = false; this.title = "修改学生";
this.getList(); });
}); },
} else { /** 提交按钮 */
addStu(this.form).then(response => { submitForm() {
this.msgSuccess("新增成功"); this.$refs["form"].validate(valid => {
this.open = false; if (valid) {
this.getList(); this.form.resultsList = this.resultsList;
}); if (this.form.id != null) {
updateStu(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addStu(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
} }
} });
}); },
}, /** 删除按钮操作 */
/** 删除按钮操作 */ handleDelete(row) {
handleDelete(row) { const ids = row.id || this.ids;
const ids = row.id || this.ids; this.$confirm('是否确认删除学生编号为"' + ids + '"的数据项?', "警告", {
this.$confirm('是否确认删除学生编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
@ -301,11 +317,38 @@ export default {
this.getList(); this.getList();
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}) })
}, },
/** 导出按钮操作 */ /** 成绩序号 */
handleExport() { rowResultsIndex({ row, rowIndex }) {
const queryParams = this.queryParams; row.index = rowIndex + 1;
this.$confirm('是否确认导出所有学生数据项?', "警告", { },
/** 成绩添加按钮操作 */
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() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有学生数据项?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
@ -314,7 +357,7 @@ export default {
}).then(response => { }).then(response => {
this.download(response.msg); this.download(response.msg);
}) })
}
} }
} };
};
</script> </script>

View File

@ -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();

View File

@ -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);
@ -136,15 +134,17 @@ public class ${ClassName}ServiceImpl implements ${ClassName}Service {
try { try {
#foreach ($column in $columns) #foreach ($column in $columns)
#if($column.javaField == 'updateTime') #if($column.javaField == 'updateTime')
${className}.setUpdateTime(DateUtils.getNowDate()); ${className}.setUpdateTime(DateUtils.getNowDate());
#end #end
#if($column.javaField == 'updateBy') #if($column.javaField == 'updateBy')
${className}.setUpdateBy(SecurityUtils.getUserId()); ${className}.setUpdateBy(SecurityUtils.getUserId());
#end #end
#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,7 +171,8 @@ 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);
if (renewal >0){ if (renewal >0){
@ -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
} }

View File

@ -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}

View File

@ -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

View File

@ -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

View File

@ -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);
} }

View File

@ -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();
}
}

View File

@ -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();
} }
} }

View File

@ -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,13 +10,18 @@ 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;
/** /**
* 学生Service业务层处理 * 学生Service业务层处理
* *
* @author hchyun * @author hchyun
* @date 2021-01-22 * @date 2021-01-22
*/ */
@ -30,7 +34,7 @@ public class StuServiceImpl implements StuService {
/** /**
* 查询学生 * 查询学生
* *
* @param id 学生ID * @param id 学生ID
* @return 学生 * @return 学生
*/ */
@ -38,20 +42,20 @@ 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);
} }
} }
/** /**
* 查询学生列表 * 查询学生列表
* *
* @param stu 学生 * @param stu 学生
* @return 学生 * @return 学生
*/ */
@ -59,102 +63,138 @@ 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);
} }
} }
/** /**
* 新增学生 * 新增学生
* *
* @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);
} }
} }
/** /**
* 修改学生 * 修改学生
* *
* @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); return new ServerResult<Integer>(false,ReturnConstants.DB_EX);
}else {
return new ServerResult<Integer>(false,ReturnConstants.SYS_FAILL);
} }
}catch (RuntimeException e){ 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()); logger.error(e.getMessage());
return new ServerResult<Integer>(false,ReturnConstants.DB_EX); return new ServerResult<Integer>(false, ReturnConstants.DB_EX);
} }
} }
/** /**
* 批量删除学生 * 批量删除学生
* *
* @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);
} }
} }
/** /**
* 删除学生信息 * 删除学生信息
* *
* @param id 学生ID * @param id 学生ID
* @return 结果 * @return 结果
*/ */
@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;
}
} }

View File

@ -1,9 +1,9 @@
<?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">
<result property="id" column="id" /> <result property="id" column="id" />
<result property="name" column="name" /> <result property="name" column="name" />
@ -15,53 +15,66 @@ 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>
<select id="selectStuList" parameterType="Stu" resultMap="StuResult"> <select id="selectStuList" parameterType="Stu" resultMap="StuResult">
<include refid="selectStuVo"/> <include refid="selectStuVo"/>
<where> <where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if> <if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="tel != null "> and tel like concat('%', #{tel}, '%')</if> <if test="tel != null "> and tel like concat('%', #{tel}, '%')</if>
<if test="email != null and email != ''"> and email like concat('%', #{email}, '%')</if> <if test="email != null and email != ''"> and email like concat('%', #{email}, '%')</if>
<if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if> <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
</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>
<if test="updateBy != null">#{updateBy},</if> <if test="updateBy != null">#{updateBy},</if>
</trim> </trim>
</insert> </insert>
<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>
@ -75,9 +88,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<delete id="deleteStuByIds" parameterType="String"> <delete id="deleteStuByIds" parameterType="String">
delete from sys_stu where id in delete from sys_stu where id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">
#{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>