Commit d261d9b5 by 胡懿

删除test包

parent c27381c3
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.entity;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.ActEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 请假申请Entity
* @author 刘高峰
* @version 2018-06-16
*/
public class OALeave extends ActEntity<OALeave> {
private static final long serialVersionUID = 1L;
private String procInsId; // 流程实例编号
private String leaveType; // 请假类型
private Date startTime; // 请假开始时间
private Date endTime; // 请假结束时间
private String reason; // 请假理由
public OALeave() {
super();
}
public OALeave(String id){
super(id);
}
@ExcelField(title="流程实例编号", align=2, sort=1)
public String getProcInsId() {
return procInsId;
}
public void setProcInsId(String procInsId) {
this.procInsId = procInsId;
}
@ExcelField(title="请假类型", dictType="oa_leave_type", align=2, sort=2)
public String getLeaveType() {
return leaveType;
}
public void setLeaveType(String leaveType) {
this.leaveType = leaveType;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假开始时间不能为空")
@ExcelField(title="请假开始时间", align=2, sort=3)
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假结束时间不能为空")
@ExcelField(title="请假结束时间", align=2, sort=4)
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
@ExcelField(title="请假理由", align=2, sort=5)
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.entity;
import com.jeeplus.modules.sys.entity.User;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.Office;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.ActEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 薪酬调整申请Entity
* @author 刘高峰
* @version 2018-06-16
*/
public class TestAudit extends ActEntity<TestAudit> {
private static final long serialVersionUID = 1L;
private String procInsId; // 流程实例ID
private User user; // 变动用户
private Office office; // 归属部门
private String post; // 岗位
private String sex; // 性别
private String edu; // 学历
private String content; // 调整原因
private String olda; // 现行标准 薪酬档级
private String oldb; // 现行标准 月工资额
private String oldc; // 现行标准 年薪总额
private String newa; // 调整后标准 薪酬档级
private String newb; // 调整后标准 月工资额
private String newc; // 调整后标准 年薪总额
private String addNum; // 月增资
private Date exeDate; // 执行时间
public TestAudit() {
super();
}
public TestAudit(String id){
super(id);
}
@ExcelField(title="流程实例ID", align=2, sort=1)
public String getProcInsId() {
return procInsId;
}
public void setProcInsId(String procInsId) {
this.procInsId = procInsId;
}
@NotNull(message="变动用户不能为空")
@ExcelField(title="变动用户", fieldType=User.class, value="user.name", align=2, sort=2)
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@NotNull(message="归属部门不能为空")
@ExcelField(title="归属部门", fieldType=Office.class, value="office.name", align=2, sort=3)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@ExcelField(title="岗位", align=2, sort=4)
public String getPost() {
return post;
}
public void setPost(String post) {
this.post = post;
}
@ExcelField(title="性别", dictType="sex", align=2, sort=5)
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@ExcelField(title="学历", align=2, sort=6)
public String getEdu() {
return edu;
}
public void setEdu(String edu) {
this.edu = edu;
}
@ExcelField(title="调整原因", align=2, sort=7)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@ExcelField(title="现行标准 薪酬档级", align=2, sort=8)
public String getOlda() {
return olda;
}
public void setOlda(String olda) {
this.olda = olda;
}
@ExcelField(title="现行标准 月工资额", align=2, sort=9)
public String getOldb() {
return oldb;
}
public void setOldb(String oldb) {
this.oldb = oldb;
}
@ExcelField(title="现行标准 年薪总额", align=2, sort=10)
public String getOldc() {
return oldc;
}
public void setOldc(String oldc) {
this.oldc = oldc;
}
@ExcelField(title="调整后标准 薪酬档级", align=2, sort=11)
public String getNewa() {
return newa;
}
public void setNewa(String newa) {
this.newa = newa;
}
@ExcelField(title="调整后标准 月工资额", align=2, sort=12)
public String getNewb() {
return newb;
}
public void setNewb(String newb) {
this.newb = newb;
}
@ExcelField(title="调整后标准 年薪总额", align=2, sort=13)
public String getNewc() {
return newc;
}
public void setNewc(String newc) {
this.newc = newc;
}
@ExcelField(title="月增资", align=2, sort=14)
public String getAddNum() {
return addNum;
}
public void setAddNum(String addNum) {
this.addNum = addNum;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ExcelField(title="执行时间", align=2, sort=15)
public Date getExeDate() {
return exeDate;
}
public void setExeDate(Date exeDate) {
this.exeDate = exeDate;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.entity;
import com.jeeplus.modules.sys.entity.User;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.core.persistence.ActEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 报销申请Entity
* @author 刘高峰
* @version 2018-06-16
*/
public class TestExpense extends ActEntity<TestExpense> {
private static final long serialVersionUID = 1L;
private User tuser; // 员工姓名
private Office office; // 所属部门
private String cost; // 报销费用
private String reason; // 报销事由
private String procInsId; // 流程实例id
public TestExpense() {
super();
}
public TestExpense(String id){
super(id);
}
@NotNull(message="员工姓名不能为空")
@ExcelField(title="员工姓名", fieldType=User.class, value="tuser.name", align=2, sort=1)
public User getTuser() {
return tuser;
}
public void setTuser(User tuser) {
this.tuser = tuser;
}
@NotNull(message="所属部门不能为空")
@ExcelField(title="所属部门", fieldType=Office.class, value="office.name", align=2, sort=2)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@ExcelField(title="报销费用", align=2, sort=3)
public String getCost() {
return cost;
}
public void setCost(String cost) {
this.cost = cost;
}
@ExcelField(title="报销事由", align=2, sort=4)
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
@ExcelField(title="流程实例id", align=2, sort=11)
public String getProcInsId() {
return procInsId;
}
public void setProcInsId(String procInsId) {
this.procInsId = procInsId;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.activiti.entity.OALeave;
/**
* 请假申请MAPPER接口
* @author 刘高峰
* @version 2018-06-16
*/
@MyBatisMapper
public interface OALeaveMapper extends BaseMapper<OALeave> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.activiti.entity.TestAudit;
/**
* 薪酬调整申请MAPPER接口
* @author 刘高峰
* @version 2018-06-16
*/
@MyBatisMapper
public interface TestAuditMapper extends BaseMapper<TestAudit> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.activiti.entity.TestExpense;
/**
* 报销申请MAPPER接口
* @author 刘高峰
* @version 2018-06-16
*/
@MyBatisMapper
public interface TestExpenseMapper extends BaseMapper<TestExpense> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.activiti.mapper.OALeaveMapper">
<sql id="oALeaveColumns">
a.id AS "id",
a.proc_ins_id AS "procInsId",
a.leave_type AS "leaveType",
a.start_time AS "startTime",
a.end_time AS "endTime",
a.reason AS "reason",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="oALeaveJoins">
LEFT JOIN sys_user updateBy ON updateBy.id = a.update_by
</sql>
<resultMap type="OALeave" id="OALeaveResult" autoMapping="true">
<result column="reason" property="reason" typeHandler="com.jeeplus.core.mapper.ConvertBlobTypeHandler"/>
</resultMap>
<select id="get" resultMap="OALeaveResult" >
SELECT
<include refid="oALeaveColumns"/>
FROM test_activiti_leave a
<include refid="oALeaveJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultMap="OALeaveResult" >
SELECT
<include refid="oALeaveColumns"/>
FROM test_activiti_leave a
<include refid="oALeaveJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultMap="OALeaveResult" >
SELECT
<include refid="oALeaveColumns"/>
FROM test_activiti_leave a
<include refid="oALeaveJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_activiti_leave(
id,
proc_ins_id,
leave_type,
start_time,
end_time,
reason,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{procInsId},
#{leaveType},
#{startTime},
#{endTime},
#{reason},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_activiti_leave SET
proc_ins_id = #{procInsId},
leave_type = #{leaveType},
start_time = #{startTime},
end_time = #{endTime},
reason = #{reason},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_activiti_leave
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_activiti_leave SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="OALeave" statementType="STATEMENT">
select * FROM test_activiti_leave where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.activiti.mapper.TestAuditMapper">
<sql id="testAuditColumns">
a.id AS "id",
a.proc_ins_id AS "procInsId",
a.user_id AS "user.id",
a.office_id AS "office.id",
a.post AS "post",
a.sex AS "sex",
a.edu AS "edu",
a.content AS "content",
a.olda AS "olda",
a.oldb AS "oldb",
a.oldc AS "oldc",
a.newa AS "newa",
a.newb AS "newb",
a.newc AS "newc",
a.add_num AS "addNum",
a.exe_date AS "exeDate",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
user.name AS "user.name",
office.name AS "office.name"
</sql>
<sql id="testAuditJoins">
LEFT JOIN sys_user user ON user.id = a.user_id
LEFT JOIN sys_office office ON office.id = a.office_id
</sql>
<select id="get" resultType="TestAudit" >
SELECT
<include refid="testAuditColumns"/>
FROM test_activiti_audit a
<include refid="testAuditJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestAudit" >
SELECT
<include refid="testAuditColumns"/>
FROM test_activiti_audit a
<include refid="testAuditJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestAudit" >
SELECT
<include refid="testAuditColumns"/>
FROM test_activiti_audit a
<include refid="testAuditJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_activiti_audit(
id,
proc_ins_id,
user_id,
office_id,
post,
sex,
edu,
content,
olda,
oldb,
oldc,
newa,
newb,
newc,
add_num,
exe_date,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{procInsId},
#{user.id},
#{office.id},
#{post},
#{sex},
#{edu},
#{content},
#{olda},
#{oldb},
#{oldc},
#{newa},
#{newb},
#{newc},
#{addNum},
#{exeDate},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_activiti_audit SET
proc_ins_id = #{procInsId},
user_id = #{user.id},
office_id = #{office.id},
post = #{post},
sex = #{sex},
edu = #{edu},
content = #{content},
olda = #{olda},
oldb = #{oldb},
oldc = #{oldc},
newa = #{newa},
newb = #{newb},
newc = #{newc},
add_num = #{addNum},
exe_date = #{exeDate},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_activiti_audit
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_activiti_audit SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestAudit" statementType="STATEMENT">
select * FROM test_activiti_audit where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.activiti.mapper.TestExpenseMapper">
<sql id="testExpenseColumns">
a.id AS "id",
a.name AS "tuser.id",
a.office_id AS "office.id",
a.cost AS "cost",
a.reason AS "reason",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
a.proc_ins_id AS "procInsId",
tuser.name AS "tuser.name",
office.name AS "office.name"
</sql>
<sql id="testExpenseJoins">
LEFT JOIN sys_user tuser ON tuser.id = a.name
LEFT JOIN sys_office office ON office.id = a.office_id
</sql>
<select id="get" resultType="TestExpense" >
SELECT
<include refid="testExpenseColumns"/>
FROM test_activiti_expense a
<include refid="testExpenseJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestExpense" >
SELECT
<include refid="testExpenseColumns"/>
FROM test_activiti_expense a
<include refid="testExpenseJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestExpense" >
SELECT
<include refid="testExpenseColumns"/>
FROM test_activiti_expense a
<include refid="testExpenseJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_activiti_expense(
id,
name,
office_id,
cost,
reason,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag,
proc_ins_id
) VALUES (
#{id},
#{tuser.id},
#{office.id},
#{cost},
#{reason},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag},
#{procInsId}
)
</insert>
<update id="update">
UPDATE test_activiti_expense SET
name = #{tuser.id},
office_id = #{office.id},
cost = #{cost},
reason = #{reason},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
proc_ins_id = #{procInsId}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_activiti_expense
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_activiti_expense SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestExpense" statementType="STATEMENT">
select * FROM test_activiti_expense where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.activiti.entity.OALeave;
import com.jeeplus.modules.test.activiti.mapper.OALeaveMapper;
/**
* 请假申请Service
* @author 刘高峰
* @version 2018-06-16
*/
@Service
@Transactional(readOnly = true)
public class OALeaveService extends CrudService<OALeaveMapper, OALeave> {
public OALeave get(String id) {
return super.get(id);
}
public List<OALeave> findList(OALeave oALeave) {
return super.findList(oALeave);
}
public Page<OALeave> findPage(Page<OALeave> page, OALeave oALeave) {
return super.findPage(page, oALeave);
}
@Transactional(readOnly = false)
public void save(OALeave oALeave) {
super.save(oALeave);
}
@Transactional(readOnly = false)
public void delete(OALeave oALeave) {
super.delete(oALeave);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.activiti.entity.TestAudit;
import com.jeeplus.modules.test.activiti.mapper.TestAuditMapper;
/**
* 薪酬调整申请Service
* @author 刘高峰
* @version 2018-06-16
*/
@Service
@Transactional(readOnly = true)
public class TestAuditService extends CrudService<TestAuditMapper, TestAudit> {
public TestAudit get(String id) {
return super.get(id);
}
public List<TestAudit> findList(TestAudit testAudit) {
return super.findList(testAudit);
}
public Page<TestAudit> findPage(Page<TestAudit> page, TestAudit testAudit) {
return super.findPage(page, testAudit);
}
@Transactional(readOnly = false)
public void save(TestAudit testAudit) {
super.save(testAudit);
}
@Transactional(readOnly = false)
public void delete(TestAudit testAudit) {
super.delete(testAudit);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.activiti.entity.TestExpense;
import com.jeeplus.modules.test.activiti.mapper.TestExpenseMapper;
/**
* 报销申请Service
* @author 刘高峰
* @version 2018-06-16
*/
@Service
@Transactional(readOnly = true)
public class TestExpenseService extends CrudService<TestExpenseMapper, TestExpense> {
public TestExpense get(String id) {
return super.get(id);
}
public List<TestExpense> findList(TestExpense testExpense) {
return super.findList(testExpense);
}
public Page<TestExpense> findPage(Page<TestExpense> page, TestExpense testExpense) {
return super.findPage(page, testExpense);
}
@Transactional(readOnly = false)
public void save(TestExpense testExpense) {
super.save(testExpense);
}
@Transactional(readOnly = false)
public void delete(TestExpense testExpense) {
super.delete(testExpense);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.web;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.act.service.ActProcessService;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.test.activiti.entity.OALeave;
import com.jeeplus.modules.test.activiti.service.OALeaveService;
/**
* 请假申请Controller
* @author 刘高峰
* @version 2018-06-16
*/
@Controller
@RequestMapping(value = "${adminPath}/test/activiti/oALeave")
public class OALeaveController extends BaseController {
@Autowired
private OALeaveService oALeaveService;
@Autowired
private ActProcessService actProcessService;
@Autowired
private ActTaskService actTaskService;
@ModelAttribute
public OALeave get(@RequestParam(required=false) String id) {
OALeave entity = null;
if (StringUtils.isNotBlank(id)){
entity = oALeaveService.get(id);
}
if (entity == null){
entity = new OALeave();
}
return entity;
}
/**
* 查看,增加,编辑请假申请表单页面
*/
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, OALeave oALeave, Model model) {
model.addAttribute("oALeave", oALeave);
if("add".equals(mode) || "edit".equals(mode)){
return "modules/test/activiti/oALeaveForm";
}else{//audit
return "modules/test/activiti/oALeaveAudit";
}
}
/**
* 保存请假申请
*/
@ResponseBody
@RequestMapping(value = "save")
public AjaxJson save(OALeave oALeave, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(oALeave);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
/**
* 流程审批
*/
if (StringUtils.isBlank(oALeave.getId())){
//新增或编辑表单保存
oALeaveService.save(oALeave);//保存
// 启动流程
ProcessDefinition p = actProcessService.getProcessDefinition(oALeave.getAct().getProcDefId());
String title = oALeave.getCurrentUser().getName()+"在"+ DateUtils.getDateTime()+"发起"+p.getName();
actTaskService.startProcess(p.getKey(), "test_activiti_leave", oALeave.getId(), title);
j.setMsg("发起流程审批成功!");
j.getBody().put("targetUrl", "/act/task/process/");
}else{
//新增或编辑表单保存
oALeaveService.save(oALeave);//保存
oALeave.getAct().setComment(("yes".equals(oALeave.getAct().getFlag())?"[重新申请] ":"[销毁申请] "));
// 完成流程任务
Map<String, Object> vars = Maps.newHashMap();
vars.put("reapply", "yes".equals(oALeave.getAct().getFlag())? true : false);
actTaskService.complete(oALeave.getAct().getTaskId(), oALeave.getAct().getProcInsId(), oALeave.getAct().getComment(), oALeave.getContent(), vars);
j.setMsg("提交成功!");
j.getBody().put("targetUrl", "/act/task/todo/");
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.web;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.act.service.ActProcessService;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.test.activiti.entity.TestAudit;
import com.jeeplus.modules.test.activiti.service.TestAuditService;
/**
* 薪酬调整申请Controller
* @author 刘高峰
* @version 2018-06-16
*/
@Controller
@RequestMapping(value = "${adminPath}/test/activiti/testAudit")
public class TestAuditController extends BaseController {
@Autowired
private TestAuditService testAuditService;
@Autowired
private ActProcessService actProcessService;
@Autowired
private ActTaskService actTaskService;
@ModelAttribute
public TestAudit get(@RequestParam(required=false) String id) {
TestAudit entity = null;
if (StringUtils.isNotBlank(id)){
entity = testAuditService.get(id);
}
if (entity == null){
entity = new TestAudit();
}
return entity;
}
/**
* 查看,增加,编辑薪酬调整申请表单页面
*/
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestAudit testAudit, Model model) {
model.addAttribute("testAudit", testAudit);
if("add".equals(mode) || "edit".equals(mode)){
return "modules/test/activiti/testAuditForm";
}else{//audit
return "modules/test/activiti/testAuditAudit";
}
}
/**
* 保存薪酬调整申请
*/
@ResponseBody
@RequestMapping(value = "save")
public AjaxJson save(TestAudit testAudit, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testAudit);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
/**
* 流程审批
*/
if (StringUtils.isBlank(testAudit.getId())){
//新增或编辑表单保存
testAuditService.save(testAudit);//保存
// 启动流程
ProcessDefinition p = actProcessService.getProcessDefinition(testAudit.getAct().getProcDefId());
String title = testAudit.getCurrentUser().getName()+"在"+ DateUtils.getDateTime()+"发起"+p.getName();
actTaskService.startProcess(p.getKey(), "test_activiti_audit", testAudit.getId(), title);
j.setMsg("发起流程审批成功!");
j.getBody().put("targetUrl", "/act/task/process/");
}else{
//新增或编辑表单保存
testAuditService.save(testAudit);//保存
testAudit.getAct().setComment(("yes".equals(testAudit.getAct().getFlag())?"[重新申请] ":"[销毁申请] "));
// 完成流程任务
Map<String, Object> vars = Maps.newHashMap();
vars.put("reapply", "yes".equals(testAudit.getAct().getFlag())? true : false);
actTaskService.complete(testAudit.getAct().getTaskId(), testAudit.getAct().getProcInsId(), testAudit.getAct().getComment(), testAudit.getContent(), vars);
j.setMsg("提交成功!");
j.getBody().put("targetUrl", "/act/task/todo/");
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.activiti.web;
import java.util.List;
import java.util.Map;
import com.google.common.collect.Maps;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.act.service.ActProcessService;
import com.jeeplus.modules.act.service.ActTaskService;
import com.jeeplus.modules.test.activiti.entity.TestExpense;
import com.jeeplus.modules.test.activiti.service.TestExpenseService;
/**
* 报销申请Controller
* @author 刘高峰
* @version 2018-06-16
*/
@Controller
@RequestMapping(value = "${adminPath}/test/activiti/testExpense")
public class TestExpenseController extends BaseController {
@Autowired
private TestExpenseService testExpenseService;
@Autowired
private ActProcessService actProcessService;
@Autowired
private ActTaskService actTaskService;
@ModelAttribute
public TestExpense get(@RequestParam(required=false) String id) {
TestExpense entity = null;
if (StringUtils.isNotBlank(id)){
entity = testExpenseService.get(id);
}
if (entity == null){
entity = new TestExpense();
}
return entity;
}
/**
* 查看,增加,编辑报销申请表单页面
*/
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestExpense testExpense, Model model) {
model.addAttribute("testExpense", testExpense);
if("add".equals(mode) || "edit".equals(mode)){
return "modules/test/activiti/testExpenseForm";
}else{//audit
return "modules/test/activiti/testExpenseAudit";
}
}
/**
* 保存报销申请
*/
@ResponseBody
@RequestMapping(value = "save")
public AjaxJson save(TestExpense testExpense, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testExpense);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
/**
* 流程审批
*/
if (StringUtils.isBlank(testExpense.getId())){
//新增或编辑表单保存
testExpenseService.save(testExpense);//保存
// 启动流程
ProcessDefinition p = actProcessService.getProcessDefinition(testExpense.getAct().getProcDefId());
String title = testExpense.getCurrentUser().getName()+"在"+ DateUtils.getDateTime()+"发起"+p.getName();
actTaskService.startProcess(p.getKey(), "test_activiti_expense", testExpense.getId(), title);
j.setMsg("发起流程审批成功!");
j.getBody().put("targetUrl", "/act/task/process/");
}else{
//新增或编辑表单保存
testExpenseService.save(testExpense);//保存
testExpense.getAct().setComment(("yes".equals(testExpense.getAct().getFlag())?"[重新申请] ":"[销毁申请] "));
// 完成流程任务
Map<String, Object> vars = Maps.newHashMap();
vars.put("reapply", "yes".equals(testExpense.getAct().getFlag())? true : false);
actTaskService.complete(testExpense.getAct().getTaskId(), testExpense.getAct().getProcInsId(), testExpense.getAct().getComment(), testExpense.getContent(), vars);
j.setMsg("提交成功!");
j.getBody().put("targetUrl", "/act/task/todo/");
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 洲Entity
* @author lgf
* @version 2018-06-12
*/
public class TestContinent extends DataEntity<TestContinent> {
private static final long serialVersionUID = 1L;
private String name; // 洲名
public TestContinent() {
super();
}
public TestContinent(String id){
super(id);
}
@ExcelField(title="洲名", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.entity;
import com.jeeplus.modules.test.grid.entity.TestContinent;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 国家Entity
* @author lgf
* @version 2018-04-10
*/
public class TestCountry extends DataEntity<TestCountry> {
private static final long serialVersionUID = 1L;
private String name; // 国名
private String sum; // 人口
private TestContinent continent; // 所属洲
public TestCountry() {
super();
}
public TestCountry(String id){
super(id);
}
@ExcelField(title="国名", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ExcelField(title="人口", align=2, sort=2)
public String getSum() {
return sum;
}
public void setSum(String sum) {
this.sum = sum;
}
@ExcelField(title="所属洲", fieldType=TestContinent.class, value="continent.name", align=2, sort=3)
public TestContinent getContinent() {
return continent;
}
public void setContinent(TestContinent continent) {
this.continent = continent;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.grid.entity.TestContinent;
/**
* 洲MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestContinentMapper extends BaseMapper<TestContinent> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.grid.mapper.TestContinentMapper">
<sql id="testContinentColumns">
a.id AS "id",
a.name AS "name",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="testContinentJoins">
</sql>
<select id="get" resultType="TestContinent" >
SELECT
<include refid="testContinentColumns"/>
FROM test_continent a
<include refid="testContinentJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestContinent" >
SELECT
<include refid="testContinentColumns"/>
FROM test_continent a
<include refid="testContinentJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestContinent" >
SELECT
<include refid="testContinentColumns"/>
FROM test_continent a
<include refid="testContinentJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_continent(
id,
name,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_continent SET
name = #{name},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_continent
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_continent SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestContinent" statementType="STATEMENT">
select * FROM test_continent where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.grid.mapper.TestCountryMapper">
<sql id="testCountryColumns">
a.id AS "id",
a.name AS "name",
a.sum AS "sum",
a.continent_id AS "continent.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
continent.name AS "continent.name"
</sql>
<sql id="testCountryJoins">
LEFT JOIN test_continent continent ON continent.id = a.continent_id
</sql>
<select id="get" resultType="TestCountry" >
SELECT
<include refid="testCountryColumns"/>
FROM test_country a
<include refid="testCountryJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestCountry" >
SELECT
<include refid="testCountryColumns"/>
FROM test_country a
<include refid="testCountryJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="continent != null and continent.id != null and continent.id != ''">
AND a.continent_id = #{continent.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestCountry" >
SELECT
<include refid="testCountryColumns"/>
FROM test_country a
<include refid="testCountryJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_country(
id,
name,
sum,
continent_id,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{sum},
#{continent.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_country SET
name = #{name},
sum = #{sum},
continent_id = #{continent.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_country
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_country SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestCountry" statementType="STATEMENT">
select * FROM test_country where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.grid.entity.TestContinent;
import com.jeeplus.modules.test.grid.mapper.TestContinentMapper;
/**
* 洲Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestContinentService extends CrudService<TestContinentMapper, TestContinent> {
public TestContinent get(String id) {
return super.get(id);
}
public List<TestContinent> findList(TestContinent testContinent) {
return super.findList(testContinent);
}
public Page<TestContinent> findPage(Page<TestContinent> page, TestContinent testContinent) {
return super.findPage(page, testContinent);
}
@Transactional(readOnly = false)
public void save(TestContinent testContinent) {
super.save(testContinent);
}
@Transactional(readOnly = false)
public void delete(TestContinent testContinent) {
super.delete(testContinent);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.grid.entity.TestCountry;
import com.jeeplus.modules.test.grid.mapper.TestCountryMapper;
/**
* 国家Service
* @author lgf
* @version 2018-04-10
*/
@Service
@Transactional(readOnly = true)
public class TestCountryService extends CrudService<TestCountryMapper, TestCountry> {
public TestCountry get(String id) {
return super.get(id);
}
public List<TestCountry> findList(TestCountry testCountry) {
return super.findList(testCountry);
}
public Page<TestCountry> findPage(Page<TestCountry> page, TestCountry testCountry) {
return super.findPage(page, testCountry);
}
@Transactional(readOnly = false)
public void save(TestCountry testCountry) {
super.save(testCountry);
}
@Transactional(readOnly = false)
public void delete(TestCountry testCountry) {
super.delete(testCountry);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.grid.entity.TestContinent;
import com.jeeplus.modules.test.grid.service.TestContinentService;
/**
* 洲Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/grid/testContinent")
public class TestContinentController extends BaseController {
@Autowired
private TestContinentService testContinentService;
@ModelAttribute
public TestContinent get(@RequestParam(required=false) String id) {
TestContinent entity = null;
if (StringUtils.isNotBlank(id)){
entity = testContinentService.get(id);
}
if (entity == null){
entity = new TestContinent();
}
return entity;
}
/**
* 洲列表页面
*/
@RequiresPermissions("test:grid:testContinent:list")
@RequestMapping(value = {"list", ""})
public String list(TestContinent testContinent, Model model) {
model.addAttribute("testContinent", testContinent);
return "modules/test/grid/testContinentList";
}
/**
* 洲列表数据
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestContinent testContinent, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestContinent> page = testContinentService.findPage(new Page<TestContinent>(request, response), testContinent);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑洲表单页面
*/
@RequiresPermissions(value={"test:grid:testContinent:view","test:grid:testContinent:add","test:grid:testContinent:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(TestContinent testContinent, Model model) {
model.addAttribute("testContinent", testContinent);
return "modules/test/grid/testContinentForm";
}
/**
* 保存洲
*/
@ResponseBody
@RequiresPermissions(value={"test:grid:testContinent:add","test:grid:testContinent:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestContinent testContinent, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testContinent);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testContinentService.save(testContinent);//保存
j.setSuccess(true);
j.setMsg("保存洲成功");
return j;
}
/**
* 删除洲
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestContinent testContinent) {
AjaxJson j = new AjaxJson();
testContinentService.delete(testContinent);
j.setMsg("删除洲成功");
return j;
}
/**
* 批量删除洲
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testContinentService.delete(testContinentService.get(id));
}
j.setMsg("删除洲成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestContinent testContinent, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "洲"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestContinent> page = testContinentService.findPage(new Page<TestContinent>(request, response, -1), testContinent);
new ExportExcel("洲", TestContinent.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出洲记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestContinent> list = ei.getDataList(TestContinent.class);
for (TestContinent testContinent : list){
try{
testContinentService.save(testContinent);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条洲记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条洲记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入洲失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入洲数据模板
*/
@ResponseBody
@RequiresPermissions("test:grid:testContinent:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "洲数据导入模板.xlsx";
List<TestContinent> list = Lists.newArrayList();
new ExportExcel("洲数据", TestContinent.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.grid.web;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.grid.entity.TestCountry;
import com.jeeplus.modules.test.grid.service.TestCountryService;
/**
* 国家Controller
* @author lgf
* @version 2018-04-10
*/
@Controller
@RequestMapping(value = "${adminPath}/test/grid/testCountry")
public class TestCountryController extends BaseController {
@Autowired
private TestCountryService testCountryService;
@ModelAttribute
public TestCountry get(@RequestParam(required=false) String id) {
TestCountry entity = null;
if (StringUtils.isNotBlank(id)){
entity = testCountryService.get(id);
}
if (entity == null){
entity = new TestCountry();
}
return entity;
}
/**
* 国家列表页面
*/
@RequiresPermissions("test:grid:testCountry:list")
@RequestMapping(value = {"list", ""})
public String list(TestCountry testCountry, Model model) {
model.addAttribute("testCountry", testCountry);
return "modules/test/grid/testCountryList";
}
/**
* 国家列表数据
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestCountry testCountry, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestCountry> page = testCountryService.findPage(new Page<TestCountry>(request, response), testCountry);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑国家表单页面
*/
@RequiresPermissions(value={"test:grid:testCountry:view","test:grid:testCountry:add","test:grid:testCountry:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(TestCountry testCountry, Model model) {
model.addAttribute("testCountry", testCountry);
return "modules/test/grid/testCountryForm";
}
/**
* 保存国家
*/
@ResponseBody
@RequiresPermissions(value={"test:grid:testCountry:add","test:grid:testCountry:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestCountry testCountry, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testCountry);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testCountryService.save(testCountry);//保存
j.setSuccess(true);
j.setMsg("保存国家成功");
return j;
}
/**
* 删除国家
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestCountry testCountry) {
AjaxJson j = new AjaxJson();
testCountryService.delete(testCountry);
j.setMsg("删除国家成功");
return j;
}
/**
* 批量删除国家
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testCountryService.delete(testCountryService.get(id));
}
j.setMsg("删除国家成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestCountry testCountry, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "国家"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestCountry> page = testCountryService.findPage(new Page<TestCountry>(request, response, -1), testCountry);
new ExportExcel("国家", TestCountry.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出国家记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestCountry> list = ei.getDataList(TestCountry.class);
for (TestCountry testCountry : list){
try{
testCountryService.save(testCountry);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条国家记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条国家记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入国家失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入国家数据模板
*/
@ResponseBody
@RequiresPermissions("test:grid:testCountry:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "国家数据导入模板.xlsx";
List<TestCountry> list = Lists.newArrayList();
new ExportExcel("国家数据", TestCountry.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 课程Entity
* @author lgf
* @version 2018-06-12
*/
public class Course extends DataEntity<Course> {
private static final long serialVersionUID = 1L;
private String name; // 课程名
public Course() {
super();
}
public Course(String id){
super(id);
}
@ExcelField(title="课程名", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 学生Entity
* @author lgf
* @version 2018-06-12
*/
public class Student extends DataEntity<Student> {
private static final long serialVersionUID = 1L;
private String name; // 姓名
public Student() {
super();
}
public Student(String id){
super(id);
}
@ExcelField(title="姓名", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.entity;
import com.jeeplus.modules.test.manytomany.entity.Student;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.test.manytomany.entity.Course;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 学生课程记录Entity
* @author lgf
* @version 2018-06-12
*/
public class StudentCourse extends DataEntity<StudentCourse> {
private static final long serialVersionUID = 1L;
private Student student; // 学生
private Course course; // 课程
private Double score; // 分数
public StudentCourse() {
super();
}
public StudentCourse(String id){
super(id);
}
@NotNull(message="学生不能为空")
@ExcelField(title="学生", fieldType=Student.class, value="student.name", align=2, sort=1)
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
@NotNull(message="课程不能为空")
@ExcelField(title="课程", fieldType=Course.class, value="course.name", align=2, sort=2)
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
@NotNull(message="分数不能为空")
@ExcelField(title="分数", align=2, sort=3)
public Double getScore() {
return score;
}
public void setScore(Double score) {
this.score = score;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.manytomany.entity.StudentCourse;
/**
* 学生课程记录MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface StudentCourseMapper extends BaseMapper<StudentCourse> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.manytomany.entity.Student;
/**
* 学生MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface StudentMapper extends BaseMapper<Student> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.manytomany.mapper.StudentCourseMapper">
<sql id="studentCourseColumns">
a.id AS "id",
a.student_id AS "student.id",
a.course_id AS "course.id",
a.score AS "score",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
student.name AS "student.name",
course.name AS "course.name"
</sql>
<sql id="studentCourseJoins">
LEFT JOIN test_student student ON student.id = a.student_id
LEFT JOIN test_course course ON course.id = a.course_id
</sql>
<select id="get" resultType="StudentCourse" >
SELECT
<include refid="studentCourseColumns"/>
FROM test_student_course a
<include refid="studentCourseJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="StudentCourse" >
SELECT
<include refid="studentCourseColumns"/>
FROM test_student_course a
<include refid="studentCourseJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="student != null and student.id != null and student.id != ''">
AND a.student_id = #{student.id}
</if>
<if test="course != null and course.id != null and course.id != ''">
AND a.course_id = #{course.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="StudentCourse" >
SELECT
<include refid="studentCourseColumns"/>
FROM test_student_course a
<include refid="studentCourseJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_student_course(
id,
student_id,
course_id,
score,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{student.id},
#{course.id},
#{score},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_student_course SET
student_id = #{student.id},
course_id = #{course.id},
score = #{score},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_student_course
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_student_course SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="StudentCourse" statementType="STATEMENT">
select * FROM test_student_course where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.manytomany.mapper.StudentMapper">
<sql id="studentColumns">
a.id AS "id",
a.name AS "name",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="studentJoins">
</sql>
<select id="get" resultType="Student" >
SELECT
<include refid="studentColumns"/>
FROM test_student a
<include refid="studentJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Student" >
SELECT
<include refid="studentColumns"/>
FROM test_student a
<include refid="studentJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name = #{name}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Student" >
SELECT
<include refid="studentColumns"/>
FROM test_student a
<include refid="studentJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_student(
id,
name,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_student SET
name = #{name},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_student
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_student SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Student" statementType="STATEMENT">
select * FROM test_student where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.manytomany.entity.Course;
import com.jeeplus.modules.test.manytomany.mapper.CourseMapper;
/**
* 课程Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class CourseService extends CrudService<CourseMapper, Course> {
public Course get(String id) {
return super.get(id);
}
public List<Course> findList(Course course) {
return super.findList(course);
}
public Page<Course> findPage(Page<Course> page, Course course) {
return super.findPage(page, course);
}
@Transactional(readOnly = false)
public void save(Course course) {
super.save(course);
}
@Transactional(readOnly = false)
public void delete(Course course) {
super.delete(course);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.manytomany.entity.StudentCourse;
import com.jeeplus.modules.test.manytomany.mapper.StudentCourseMapper;
/**
* 学生课程记录Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class StudentCourseService extends CrudService<StudentCourseMapper, StudentCourse> {
public StudentCourse get(String id) {
return super.get(id);
}
public List<StudentCourse> findList(StudentCourse studentCourse) {
return super.findList(studentCourse);
}
public Page<StudentCourse> findPage(Page<StudentCourse> page, StudentCourse studentCourse) {
return super.findPage(page, studentCourse);
}
@Transactional(readOnly = false)
public void save(StudentCourse studentCourse) {
super.save(studentCourse);
}
@Transactional(readOnly = false)
public void delete(StudentCourse studentCourse) {
super.delete(studentCourse);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.manytomany.entity.Student;
import com.jeeplus.modules.test.manytomany.mapper.StudentMapper;
/**
* 学生Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class StudentService extends CrudService<StudentMapper, Student> {
public Student get(String id) {
return super.get(id);
}
public List<Student> findList(Student student) {
return super.findList(student);
}
public Page<Student> findPage(Page<Student> page, Student student) {
return super.findPage(page, student);
}
@Transactional(readOnly = false)
public void save(Student student) {
super.save(student);
}
@Transactional(readOnly = false)
public void delete(Student student) {
super.delete(student);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.manytomany.entity.Student;
import com.jeeplus.modules.test.manytomany.service.StudentService;
/**
* 学生Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/manytomany/student")
public class StudentController extends BaseController {
@Autowired
private StudentService studentService;
@ModelAttribute
public Student get(@RequestParam(required=false) String id) {
Student entity = null;
if (StringUtils.isNotBlank(id)){
entity = studentService.get(id);
}
if (entity == null){
entity = new Student();
}
return entity;
}
/**
* 学生列表页面
*/
@RequiresPermissions("test:manytomany:student:list")
@RequestMapping(value = {"list", ""})
public String list(Student student, Model model) {
model.addAttribute("student", student);
return "modules/test/manytomany/studentList";
}
/**
* 学生列表数据
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:list")
@RequestMapping(value = "data")
public Map<String, Object> data(Student student, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Student> page = studentService.findPage(new Page<Student>(request, response), student);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑学生表单页面
*/
@RequiresPermissions(value={"test:manytomany:student:view","test:manytomany:student:add","test:manytomany:student:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, Student student, Model model) {
model.addAttribute("student", student);
model.addAttribute("mode", mode);
return "modules/test/manytomany/studentForm";
}
/**
* 保存学生
*/
@ResponseBody
@RequiresPermissions(value={"test:manytomany:student:add","test:manytomany:student:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Student student, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(student);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
studentService.save(student);//保存
j.setSuccess(true);
j.setMsg("保存学生成功");
return j;
}
/**
* 删除学生
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Student student) {
AjaxJson j = new AjaxJson();
studentService.delete(student);
j.setMsg("删除学生成功");
return j;
}
/**
* 批量删除学生
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
studentService.delete(studentService.get(id));
}
j.setMsg("删除学生成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(Student student, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "学生"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<Student> page = studentService.findPage(new Page<Student>(request, response, -1), student);
new ExportExcel("学生", Student.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出学生记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<Student> list = ei.getDataList(Student.class);
for (Student student : list){
try{
studentService.save(student);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条学生记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条学生记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入学生失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入学生数据模板
*/
@ResponseBody
@RequiresPermissions("test:manytomany:student:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "学生数据导入模板.xlsx";
List<Student> list = Lists.newArrayList();
new ExportExcel("学生数据", Student.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytomany.web;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.manytomany.entity.StudentCourse;
import com.jeeplus.modules.test.manytomany.service.StudentCourseService;
/**
* 学生课程记录Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/manytomany/studentCourse")
public class StudentCourseController extends BaseController {
@Autowired
private StudentCourseService studentCourseService;
@ModelAttribute
public StudentCourse get(@RequestParam(required=false) String id) {
StudentCourse entity = null;
if (StringUtils.isNotBlank(id)){
entity = studentCourseService.get(id);
}
if (entity == null){
entity = new StudentCourse();
}
return entity;
}
/**
* 学生课程记录列表页面
*/
@RequiresPermissions("test:manytomany:studentCourse:list")
@RequestMapping(value = {"list", ""})
public String list(StudentCourse studentCourse, Model model) {
model.addAttribute("studentCourse", studentCourse);
return "modules/test/manytomany/studentCourseList";
}
/**
* 学生课程记录列表数据
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:list")
@RequestMapping(value = "data")
public Map<String, Object> data(StudentCourse studentCourse, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<StudentCourse> page = studentCourseService.findPage(new Page<StudentCourse>(request, response), studentCourse);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑学生课程记录表单页面
*/
@RequiresPermissions(value={"test:manytomany:studentCourse:view","test:manytomany:studentCourse:add","test:manytomany:studentCourse:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, StudentCourse studentCourse, Model model) {
model.addAttribute("studentCourse", studentCourse);
model.addAttribute("mode", mode);
return "modules/test/manytomany/studentCourseForm";
}
/**
* 保存学生课程记录
*/
@ResponseBody
@RequiresPermissions(value={"test:manytomany:studentCourse:add","test:manytomany:studentCourse:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(StudentCourse studentCourse, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(studentCourse);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
studentCourseService.save(studentCourse);//保存
j.setSuccess(true);
j.setMsg("保存学生课程记录成功");
return j;
}
/**
* 删除学生课程记录
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:del")
@RequestMapping(value = "delete")
public AjaxJson delete(StudentCourse studentCourse) {
AjaxJson j = new AjaxJson();
studentCourseService.delete(studentCourse);
j.setMsg("删除学生课程记录成功");
return j;
}
/**
* 批量删除学生课程记录
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
studentCourseService.delete(studentCourseService.get(id));
}
j.setMsg("删除学生课程记录成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(StudentCourse studentCourse, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "学生课程记录"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<StudentCourse> page = studentCourseService.findPage(new Page<StudentCourse>(request, response, -1), studentCourse);
new ExportExcel("学生课程记录", StudentCourse.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出学生课程记录记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<StudentCourse> list = ei.getDataList(StudentCourse.class);
for (StudentCourse studentCourse : list){
try{
studentCourseService.save(studentCourse);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条学生课程记录记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条学生课程记录记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入学生课程记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入学生课程记录数据模板
*/
@ResponseBody
@RequiresPermissions("test:manytomany:studentCourse:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "学生课程记录数据导入模板.xlsx";
List<StudentCourse> list = Lists.newArrayList();
new ExportExcel("学生课程记录数据", StudentCourse.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.entity;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.jeeplus.core.persistence.TreeEntity;
/**
* 商品类型Entity
* @author liugf
* @version 2018-06-12
*/
public class Category extends TreeEntity<Category> {
private static final long serialVersionUID = 1L;
public Category() {
super();
}
public Category(String id){
super(id);
}
public Category getParent() {
return parent;
}
@Override
public void setParent(Category parent) {
this.parent = parent;
}
public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.entity;
import com.jeeplus.modules.test.manytoone.entity.Category;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 商品Entity
* @author liugf
* @version 2018-06-12
*/
public class Goods extends DataEntity<Goods> {
private static final long serialVersionUID = 1L;
private String name; // 商品名称
private Category category; // 所属类型
private String price; // 价格
public Goods() {
super();
}
public Goods(String id){
super(id);
}
@ExcelField(title="商品名称", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@NotNull(message="所属类型不能为空")
@ExcelField(title="所属类型", fieldType=Category.class, value="category.name", align=2, sort=2)
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
@ExcelField(title="价格", align=2, sort=3)
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.mapper;
import com.jeeplus.core.persistence.TreeMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.manytoone.entity.Category;
/**
* 商品类型MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface CategoryMapper extends TreeMapper<Category> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.manytoone.mapper.CategoryMapper">
<resultMap id="categoryResult" type="Category">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="sort" column="sort" />
<result property="parentIds" column="parentIds" />
<association property="hasChildren" column="id" select="hasChildren" />
</resultMap>
<sql id="categoryColumns">
a.id AS "id",
a.name AS "name",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
a.parent_id AS "parent.id",
a.parent_ids AS "parentIds",
a.sort AS "sort"
</sql>
<sql id="categoryJoins">
</sql>
<select id="get" resultType="Category">
SELECT
<include refid="categoryColumns"/>
FROM test_category a
<include refid="categoryJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Category">
SELECT
<include refid="categoryColumns"/>
FROM test_category a
<include refid="categoryJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="parent != null and parent.id != null and parent.id != ''">
AND a.parent_id = #{parent.id}
</if>
<if test="parentIds != null and parentIds != ''">
AND a.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{parentIds}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{parentIds}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{parentIds},'%')</if>
</if>
</where>
ORDER BY a.sort ASC
</select>
<select id="findAllList" resultType="Category">
SELECT
<include refid="categoryColumns"/>
FROM test_category a
<include refid="categoryJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
ORDER BY a.sort ASC
</select>
<select id="getChildren" parameterType="String" resultMap="categoryResult">
select * from test_category where parent_id = #{id} ORDER BY sort
</select>
<select id="hasChildren" parameterType="String" resultType="Boolean">
select case when exists(select 1 from test_category where parent_id = #{id}) then 1 else 0 end ${dual}
</select>
<select id="findByParentIdsLike" resultType="Category">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM test_category a
<include refid="categoryJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.parent_ids LIKE #{parentIds}
</where>
ORDER BY a.sort ASC
</select>
<insert id="insert">
INSERT INTO test_category(
id,
name,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag,
parent_id,
parent_ids,
sort
) VALUES (
#{id},
#{name},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag},
#{parent.id},
#{parentIds},
#{sort}
)
</insert>
<update id="update">
UPDATE test_category SET
name = #{name},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
parent_id = #{parent.id},
parent_ids = #{parentIds},
sort = #{sort}
WHERE id = #{id}
</update>
<update id="updateParentIds">
UPDATE test_category SET
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_category
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_category SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.service.TreeService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.manytoone.entity.Category;
import com.jeeplus.modules.test.manytoone.mapper.CategoryMapper;
/**
* 商品类型Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class CategoryService extends TreeService<CategoryMapper, Category> {
public Category get(String id) {
return super.get(id);
}
public List<Category> findList(Category category) {
if (StringUtils.isNotBlank(category.getParentIds())){
category.setParentIds(","+category.getParentIds()+",");
}
return super.findList(category);
}
@Transactional(readOnly = false)
public void save(Category category) {
super.save(category);
}
@Transactional(readOnly = false)
public void delete(Category category) {
super.delete(category);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.manytoone.entity.Goods;
import com.jeeplus.modules.test.manytoone.mapper.GoodsMapper;
/**
* 商品Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class GoodsService extends CrudService<GoodsMapper, Goods> {
public Goods get(String id) {
return super.get(id);
}
public List<Goods> findList(Goods goods) {
return super.findList(goods);
}
public Page<Goods> findPage(Page<Goods> page, Goods goods) {
return super.findPage(page, goods);
}
@Transactional(readOnly = false)
public void save(Goods goods) {
super.save(goods);
}
@Transactional(readOnly = false)
public void delete(Goods goods) {
super.delete(goods);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.manytoone.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.manytoone.entity.Category;
import com.jeeplus.modules.test.manytoone.service.CategoryService;
/**
* 商品类型Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/manytoone/category")
public class CategoryController extends BaseController {
@Autowired
private CategoryService categoryService;
@ModelAttribute
public Category get(@RequestParam(required=false) String id) {
Category entity = null;
if (StringUtils.isNotBlank(id)){
entity = categoryService.get(id);
}
if (entity == null){
entity = new Category();
}
return entity;
}
/**
* 商品类型列表页面
*/
@RequiresPermissions("test:manytoone:category:list")
@RequestMapping(value = {"list", ""})
public String list(Category category, HttpServletRequest request, HttpServletResponse response, Model model) {
model.addAttribute("category", category);
return "modules/test/manytoone/categoryList";
}
/**
* 查看,增加,编辑商品类型表单页面
*/
@RequiresPermissions(value={"test:manytoone:category:view","test:manytoone:category:add","test:manytoone:category:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(Category category, Model model) {
if (category.getParent()!=null && StringUtils.isNotBlank(category.getParent().getId())){
category.setParent(categoryService.get(category.getParent().getId()));
// 获取排序号,最末节点排序号+30
if (StringUtils.isBlank(category.getId())){
Category categoryChild = new Category();
categoryChild.setParent(new Category(category.getParent().getId()));
List<Category> list = categoryService.findList(category);
if (list.size() > 0){
category.setSort(list.get(list.size()-1).getSort());
if (category.getSort() != null){
category.setSort(category.getSort() + 30);
}
}
}
}
if (category.getSort() == null){
category.setSort(30);
}
model.addAttribute("category", category);
return "modules/test/manytoone/categoryForm";
}
/**
* 保存商品类型
*/
@ResponseBody
@RequiresPermissions(value={"test:manytoone:category:add","test:manytoone:category:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Category category, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(category);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
categoryService.save(category);//保存
j.setSuccess(true);
j.put("category", category);
j.setMsg("保存商品类型成功");
return j;
}
@ResponseBody
@RequestMapping(value = "getChildren")
public List<Category> getChildren(String parentId){
if("-1".equals(parentId)){//如果是-1,没指定任何父节点,就从根节点开始查找
parentId = "0";
}
return categoryService.getChildren(parentId);
}
/**
* 删除商品类型
*/
@ResponseBody
@RequiresPermissions("test:manytoone:category:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Category category) {
AjaxJson j = new AjaxJson();
categoryService.delete(category);
j.setSuccess(true);
j.setMsg("删除商品类型成功");
return j;
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
List<Category> list = categoryService.findList(new Category());
for (int i=0; i<list.size(); i++){
Category e = list.get(i);
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("text", e.getName());
if(StringUtils.isBlank(e.getParentId()) || "0".equals(e.getParentId())){
map.put("parent", "#");
Map<String, Object> state = Maps.newHashMap();
state.put("opened", true);
map.put("state", state);
}else{
map.put("parent", e.getParentId());
}
mapList.add(map);
}
}
return mapList;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.note.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 富文本测试Entity
* @author liugf
* @version 2018-06-12
*/
public class TestNote extends DataEntity<TestNote> {
private static final long serialVersionUID = 1L;
private String title; // 标题
private String contents; // 内容
public TestNote() {
super();
}
public TestNote(String id){
super(id);
}
@ExcelField(title="标题", align=2, sort=7)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@ExcelField(title="内容", align=2, sort=8)
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.note.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.note.entity.TestNote;
/**
* 富文本测试MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestNoteMapper extends BaseMapper<TestNote> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.note.mapper.TestNoteMapper">
<sql id="testNoteColumns">
a.id AS "id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
a.title AS "title",
a.contents AS "contents"
</sql>
<sql id="testNoteJoins">
</sql>
<resultMap type="TestNote" id="TestNoteResult" autoMapping="true">
<result column="contents" property="contents" typeHandler="com.jeeplus.core.mapper.ConvertBlobTypeHandler"/>
</resultMap>
<select id="get" resultMap="TestNoteResult" >
SELECT
<include refid="testNoteColumns"/>
FROM test_note a
<include refid="testNoteJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultMap="TestNoteResult" >
SELECT
<include refid="testNoteColumns"/>
FROM test_note a
<include refid="testNoteJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="title != null and title != ''">
AND a.title = #{title}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultMap="TestNoteResult" >
SELECT
<include refid="testNoteColumns"/>
FROM test_note a
<include refid="testNoteJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_note(
id,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag,
title,
contents
) VALUES (
#{id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag},
#{title},
#{contents}
)
</insert>
<update id="update">
UPDATE test_note SET
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks},
title = #{title},
contents = #{contents}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_note
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_note SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestNote" statementType="STATEMENT">
select * FROM test_note where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.note.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.note.entity.TestNote;
import com.jeeplus.modules.test.note.mapper.TestNoteMapper;
/**
* 富文本测试Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestNoteService extends CrudService<TestNoteMapper, TestNote> {
public TestNote get(String id) {
return super.get(id);
}
public List<TestNote> findList(TestNote testNote) {
return super.findList(testNote);
}
public Page<TestNote> findPage(Page<TestNote> page, TestNote testNote) {
return super.findPage(page, testNote);
}
@Transactional(readOnly = false)
public void save(TestNote testNote) {
super.save(testNote);
}
@Transactional(readOnly = false)
public void delete(TestNote testNote) {
super.delete(testNote);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.note.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.note.entity.TestNote;
import com.jeeplus.modules.test.note.service.TestNoteService;
/**
* 富文本测试Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/note/testNote")
public class TestNoteController extends BaseController {
@Autowired
private TestNoteService testNoteService;
@ModelAttribute
public TestNote get(@RequestParam(required=false) String id) {
TestNote entity = null;
if (StringUtils.isNotBlank(id)){
entity = testNoteService.get(id);
}
if (entity == null){
entity = new TestNote();
}
return entity;
}
/**
* 富文本测试列表页面
*/
@RequiresPermissions("test:note:testNote:list")
@RequestMapping(value = {"list", ""})
public String list(TestNote testNote, Model model) {
model.addAttribute("testNote", testNote);
return "modules/test/note/testNoteList";
}
/**
* 富文本测试列表数据
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestNote testNote, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestNote> page = testNoteService.findPage(new Page<TestNote>(request, response), testNote);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑富文本测试表单页面
*/
@RequiresPermissions(value={"test:note:testNote:view","test:note:testNote:add","test:note:testNote:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestNote testNote, Model model) {
model.addAttribute("testNote", testNote);
model.addAttribute("mode", mode);
return "modules/test/note/testNoteForm";
}
/**
* 保存富文本测试
*/
@ResponseBody
@RequiresPermissions(value={"test:note:testNote:add","test:note:testNote:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestNote testNote, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testNote);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testNoteService.save(testNote);//保存
j.setSuccess(true);
j.setMsg("保存富文本测试成功");
return j;
}
/**
* 删除富文本测试
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestNote testNote) {
AjaxJson j = new AjaxJson();
testNoteService.delete(testNote);
j.setMsg("删除富文本测试成功");
return j;
}
/**
* 批量删除富文本测试
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testNoteService.delete(testNoteService.get(id));
}
j.setMsg("删除富文本测试成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestNote testNote, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "富文本测试"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestNote> page = testNoteService.findPage(new Page<TestNote>(request, response, -1), testNote);
new ExportExcel("富文本测试", TestNote.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出富文本测试记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestNote> list = ei.getDataList(TestNote.class);
for (TestNote testNote : list){
try{
testNoteService.save(testNote);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条富文本测试记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条富文本测试记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入富文本测试失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入富文本测试数据模板
*/
@ResponseBody
@RequiresPermissions("test:note:testNote:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "富文本测试数据导入模板.xlsx";
List<TestNote> list = Lists.newArrayList();
new ExportExcel("富文本测试数据", TestNote.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.dialog.entity;
import com.jeeplus.modules.sys.entity.Office;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.User;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 请假表单Entity
* @author lgf
* @version 2018-06-12
*/
public class Leave1 extends DataEntity<Leave1> {
private static final long serialVersionUID = 1L;
private Office office; // 归属部门
private User tuser; // 员工
private String area; // 归属区域
private Date beginDate; // 请假开始日期
private Date endDate; // 请假结束日期
private Date beginBeginDate; // 开始 请假开始日期
private Date endBeginDate; // 结束 请假开始日期
public Leave1() {
super();
}
public Leave1(String id){
super(id);
}
@NotNull(message="归属部门不能为空")
@ExcelField(title="归属部门", fieldType=Office.class, value="office.name", align=2, sort=1)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@NotNull(message="员工不能为空")
@ExcelField(title="员工", fieldType=User.class, value="tuser.name", align=2, sort=2)
public User getTuser() {
return tuser;
}
public void setTuser(User tuser) {
this.tuser = tuser;
}
@ExcelField(title="归属区域", align=2, sort=3)
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假开始日期不能为空")
@ExcelField(title="请假开始日期", align=2, sort=4)
public Date getBeginDate() {
return beginDate;
}
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假结束日期不能为空")
@ExcelField(title="请假结束日期", align=2, sort=5)
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Date getBeginBeginDate() {
return beginBeginDate;
}
public void setBeginBeginDate(Date beginBeginDate) {
this.beginBeginDate = beginBeginDate;
}
public Date getEndBeginDate() {
return endBeginDate;
}
public void setEndBeginDate(Date endBeginDate) {
this.endBeginDate = endBeginDate;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.one.dialog.entity.Leave1;
/**
* 请假表单MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface Leave1Mapper extends BaseMapper<Leave1> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.one.dialog.mapper.Leave1Mapper">
<sql id="leave1Columns">
a.id AS "id",
a.office_id AS "office.id",
a.user_id AS "tuser.id",
a.area_id AS "area",
a.begin_date AS "beginDate",
a.end_date AS "endDate",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
office.name AS "office.name",
tuser.name AS "tuser.name"
</sql>
<sql id="leave1Joins">
LEFT JOIN sys_office office ON office.id = a.office_id
LEFT JOIN sys_user tuser ON tuser.id = a.user_id
</sql>
<select id="get" resultType="Leave1" >
SELECT
<include refid="leave1Columns"/>
FROM test_leave a
<include refid="leave1Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Leave1" >
SELECT
<include refid="leave1Columns"/>
FROM test_leave a
<include refid="leave1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="office != null and office.id != null and office.id != ''">
AND a.office_id = #{office.id}
</if>
<if test="tuser != null and tuser.id != null and tuser.id != ''">
AND a.user_id = #{tuser.id}
</if>
<if test="area != null and area != ''">
AND a.area_id LIKE
<if test="dbName == 'oracle'">'%'||#{area}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{area}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{area},'%')</if>
</if>
<if test="beginBeginDate != null and endBeginDate != null ">
AND a.begin_date BETWEEN #{beginBeginDate} AND #{endBeginDate}
</if>
<if test="endDate != null and endDate != ''">
AND a.end_date = #{endDate}
</if>
<if test="remarks != null and remarks != ''">
AND a.remarks = #{remarks}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Leave1" >
SELECT
<include refid="leave1Columns"/>
FROM test_leave a
<include refid="leave1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_leave(
id,
office_id,
user_id,
area_id,
begin_date,
end_date,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{office.id},
#{tuser.id},
#{area},
#{beginDate},
#{endDate},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_leave SET
office_id = #{office.id},
user_id = #{tuser.id},
area_id = #{area},
begin_date = #{beginDate},
end_date = #{endDate},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_leave
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_leave SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Leave1" statementType="STATEMENT">
select * FROM test_leave where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.dialog.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.one.dialog.entity.Leave1;
import com.jeeplus.modules.test.one.dialog.mapper.Leave1Mapper;
/**
* 请假表单Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class Leave1Service extends CrudService<Leave1Mapper, Leave1> {
public Leave1 get(String id) {
return super.get(id);
}
public List<Leave1> findList(Leave1 leave1) {
return super.findList(leave1);
}
public Page<Leave1> findPage(Page<Leave1> page, Leave1 leave1) {
return super.findPage(page, leave1);
}
@Transactional(readOnly = false)
public void save(Leave1 leave1) {
super.save(leave1);
}
@Transactional(readOnly = false)
public void delete(Leave1 leave1) {
super.delete(leave1);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.dialog.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.one.dialog.entity.Leave1;
import com.jeeplus.modules.test.one.dialog.service.Leave1Service;
/**
* 请假表单Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/one/dialog/leave1")
public class Leave1Controller extends BaseController {
@Autowired
private Leave1Service leave1Service;
@ModelAttribute
public Leave1 get(@RequestParam(required=false) String id) {
Leave1 entity = null;
if (StringUtils.isNotBlank(id)){
entity = leave1Service.get(id);
}
if (entity == null){
entity = new Leave1();
}
return entity;
}
/**
* 请假表单列表页面
*/
@RequiresPermissions("test:one:dialog:leave1:list")
@RequestMapping(value = {"list", ""})
public String list(Leave1 leave1, Model model) {
model.addAttribute("leave1", leave1);
return "modules/test/one/dialog/leave1List";
}
/**
* 请假表单列表数据
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:list")
@RequestMapping(value = "data")
public Map<String, Object> data(Leave1 leave1, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Leave1> page = leave1Service.findPage(new Page<Leave1>(request, response), leave1);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑请假表单表单页面
*/
@RequiresPermissions(value={"test:one:dialog:leave1:view","test:one:dialog:leave1:add","test:one:dialog:leave1:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(Leave1 leave1, Model model) {
model.addAttribute("leave1", leave1);
return "modules/test/one/dialog/leave1Form";
}
/**
* 保存请假表单
*/
@ResponseBody
@RequiresPermissions(value={"test:one:dialog:leave1:add","test:one:dialog:leave1:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Leave1 leave1, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(leave1);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
leave1Service.save(leave1);//保存
j.setSuccess(true);
j.setMsg("保存请假表单成功");
return j;
}
/**
* 删除请假表单
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Leave1 leave1) {
AjaxJson j = new AjaxJson();
leave1Service.delete(leave1);
j.setMsg("删除请假表单成功");
return j;
}
/**
* 批量删除请假表单
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
leave1Service.delete(leave1Service.get(id));
}
j.setMsg("删除请假表单成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(Leave1 leave1, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "请假表单"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<Leave1> page = leave1Service.findPage(new Page<Leave1>(request, response, -1), leave1);
new ExportExcel("请假表单", Leave1.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出请假表单记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<Leave1> list = ei.getDataList(Leave1.class);
for (Leave1 leave1 : list){
try{
leave1Service.save(leave1);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条请假表单记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条请假表单记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入请假表单失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入请假表单数据模板
*/
@ResponseBody
@RequiresPermissions("test:one:dialog:leave1:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "请假表单数据导入模板.xlsx";
List<Leave1> list = Lists.newArrayList();
new ExportExcel("请假表单数据", Leave1.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.form.entity;
import com.jeeplus.modules.sys.entity.Office;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.User;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 请假表单Entity
* @author lgf
* @version 2018-06-12
*/
public class Leave2 extends DataEntity<Leave2> {
private static final long serialVersionUID = 1L;
private Office office; // 归属部门
private User tuser; // 员工
private String area; // 归属区域
private Date beginDate; // 请假开始日期
private Date endDate; // 请假结束日期
private Date beginBeginDate; // 开始 请假开始日期
private Date endBeginDate; // 结束 请假开始日期
public Leave2() {
super();
}
public Leave2(String id){
super(id);
}
@NotNull(message="归属部门不能为空")
@ExcelField(title="归属部门", fieldType=Office.class, value="office.name", align=2, sort=1)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@NotNull(message="员工不能为空")
@ExcelField(title="员工", fieldType=User.class, value="tuser.name", align=2, sort=2)
public User getTuser() {
return tuser;
}
public void setTuser(User tuser) {
this.tuser = tuser;
}
@ExcelField(title="归属区域", align=2, sort=3)
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假开始日期不能为空")
@ExcelField(title="请假开始日期", align=2, sort=4)
public Date getBeginDate() {
return beginDate;
}
public void setBeginDate(Date beginDate) {
this.beginDate = beginDate;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="请假结束日期不能为空")
@ExcelField(title="请假结束日期", align=2, sort=5)
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public Date getBeginBeginDate() {
return beginBeginDate;
}
public void setBeginBeginDate(Date beginBeginDate) {
this.beginBeginDate = beginBeginDate;
}
public Date getEndBeginDate() {
return endBeginDate;
}
public void setEndBeginDate(Date endBeginDate) {
this.endBeginDate = endBeginDate;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.one.form.entity.Leave2;
/**
* 请假表单MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface Leave2Mapper extends BaseMapper<Leave2> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.one.form.mapper.Leave2Mapper">
<sql id="leave2Columns">
a.id AS "id",
a.office_id AS "office.id",
a.user_id AS "tuser.id",
a.area_id AS "area",
a.begin_date AS "beginDate",
a.end_date AS "endDate",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
office.name AS "office.name",
tuser.name AS "tuser.name"
</sql>
<sql id="leave2Joins">
LEFT JOIN sys_office office ON office.id = a.office_id
LEFT JOIN sys_user tuser ON tuser.id = a.user_id
</sql>
<select id="get" resultType="Leave2" >
SELECT
<include refid="leave2Columns"/>
FROM test_leave a
<include refid="leave2Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Leave2" >
SELECT
<include refid="leave2Columns"/>
FROM test_leave a
<include refid="leave2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="office != null and office.id != null and office.id != ''">
AND a.office_id = #{office.id}
</if>
<if test="tuser != null and tuser.id != null and tuser.id != ''">
AND a.user_id = #{tuser.id}
</if>
<if test="area != null and area != ''">
AND a.area_id LIKE
<if test="dbName == 'oracle'">'%'||#{area}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{area}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{area},'%')</if>
</if>
<if test="beginBeginDate != null and endBeginDate != null ">
AND a.begin_date BETWEEN #{beginBeginDate} AND #{endBeginDate}
</if>
<if test="endDate != null and endDate != ''">
AND a.end_date = #{endDate}
</if>
<if test="remarks != null and remarks != ''">
AND a.remarks = #{remarks}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Leave2" >
SELECT
<include refid="leave2Columns"/>
FROM test_leave a
<include refid="leave2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_leave(
id,
office_id,
user_id,
area_id,
begin_date,
end_date,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{office.id},
#{tuser.id},
#{area},
#{beginDate},
#{endDate},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_leave SET
office_id = #{office.id},
user_id = #{tuser.id},
area_id = #{area},
begin_date = #{beginDate},
end_date = #{endDate},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_leave
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_leave SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Leave2" statementType="STATEMENT">
select * FROM test_leave where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.one.form.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.one.form.entity.Leave2;
import com.jeeplus.modules.test.one.form.mapper.Leave2Mapper;
/**
* 请假表单Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class Leave2Service extends CrudService<Leave2Mapper, Leave2> {
public Leave2 get(String id) {
return super.get(id);
}
public List<Leave2> findList(Leave2 leave2) {
return super.findList(leave2);
}
public Page<Leave2> findPage(Page<Leave2> page, Leave2 leave2) {
return super.findPage(page, leave2);
}
@Transactional(readOnly = false)
public void save(Leave2 leave2) {
super.save(leave2);
}
@Transactional(readOnly = false)
public void delete(Leave2 leave2) {
super.delete(leave2);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 火车票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild11 extends DataEntity<TestDataChild11> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private Date starttime; // 出发时间
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain1 testDataMain; // 业务主表ID 父类
public TestDataChild11() {
super();
}
public TestDataChild11(String id){
super(id);
}
public TestDataChild11(TestDataMain1 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="出发时间不能为空")
@ExcelField(title="出发时间", align=2, sort=3)
public Date getStarttime() {
return starttime;
}
public void setStarttime(Date starttime) {
this.starttime = starttime;
}
@NotNull(message="代理价格不能为空")
@ExcelField(title="代理价格", align=2, sort=4)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=5)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain1 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain1 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 飞机票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild12 extends DataEntity<TestDataChild12> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private String startTime; // 出发时间
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain1 testDataMain; // 外键 父类
public TestDataChild12() {
super();
}
public TestDataChild12(String id){
super(id);
}
public TestDataChild12(TestDataMain1 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@ExcelField(title="出发时间", align=2, sort=3)
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
@NotNull(message="代理价格不能为空")
@ExcelField(title="代理价格", align=2, sort=4)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=5)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain1 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain1 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 汽车票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild13 extends DataEntity<TestDataChild13> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain1 testDataMain; // 外键 父类
public TestDataChild13() {
super();
}
public TestDataChild13(String id){
super(id);
}
public TestDataChild13(TestDataMain1 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@ExcelField(title="代理价格", align=2, sort=3)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=4)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain1 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain1 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.entity;
import com.jeeplus.modules.sys.entity.User;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Area;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.List;
import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 票务代理Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataMain1 extends DataEntity<TestDataMain1> {
private static final long serialVersionUID = 1L;
private User tuser; // 归属用户
private Office office; // 归属部门
private Area area; // 归属区域
private String name; // 名称
private String sex; // 性别
private Date inDate; // 加入日期
private Date beginInDate; // 开始 加入日期
private Date endInDate; // 结束 加入日期
private List<TestDataChild11> testDataChild11List = Lists.newArrayList(); // 子表列表
private List<TestDataChild12> testDataChild12List = Lists.newArrayList(); // 子表列表
private List<TestDataChild13> testDataChild13List = Lists.newArrayList(); // 子表列表
public TestDataMain1() {
super();
}
public TestDataMain1(String id){
super(id);
}
@NotNull(message="归属用户不能为空")
@ExcelField(title="归属用户", fieldType=User.class, value="tuser.name", align=2, sort=1)
public User getTuser() {
return tuser;
}
public void setTuser(User tuser) {
this.tuser = tuser;
}
@NotNull(message="归属部门不能为空")
@ExcelField(title="归属部门", fieldType=Office.class, value="office.name", align=2, sort=2)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@NotNull(message="归属区域不能为空")
@ExcelField(title="归属区域", fieldType=Area.class, value="area.name", align=2, sort=3)
public Area getArea() {
return area;
}
public void setArea(Area area) {
this.area = area;
}
@ExcelField(title="名称", align=2, sort=4)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ExcelField(title="性别", dictType="sex", align=2, sort=5)
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="加入日期不能为空")
@ExcelField(title="加入日期", align=2, sort=6)
public Date getInDate() {
return inDate;
}
public void setInDate(Date inDate) {
this.inDate = inDate;
}
public Date getBeginInDate() {
return beginInDate;
}
public void setBeginInDate(Date beginInDate) {
this.beginInDate = beginInDate;
}
public Date getEndInDate() {
return endInDate;
}
public void setEndInDate(Date endInDate) {
this.endInDate = endInDate;
}
public List<TestDataChild11> getTestDataChild11List() {
return testDataChild11List;
}
public void setTestDataChild11List(List<TestDataChild11> testDataChild11List) {
this.testDataChild11List = testDataChild11List;
}
public List<TestDataChild12> getTestDataChild12List() {
return testDataChild12List;
}
public void setTestDataChild12List(List<TestDataChild12> testDataChild12List) {
this.testDataChild12List = testDataChild12List;
}
public List<TestDataChild13> getTestDataChild13List() {
return testDataChild13List;
}
public void setTestDataChild13List(List<TestDataChild13> testDataChild13List) {
this.testDataChild13List = testDataChild13List;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild11;
/**
* 火车票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild11Mapper extends BaseMapper<TestDataChild11> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild12;
/**
* 飞机票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild12Mapper extends BaseMapper<TestDataChild12> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild13;
/**
* 汽车票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild13Mapper extends BaseMapper<TestDataChild13> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataMain1;
/**
* 票务代理MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataMain1Mapper extends BaseMapper<TestDataMain1> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild11Mapper">
<sql id="testDataChild11Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.starttime AS "starttime",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main_id AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild11Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main_id
</sql>
<select id="get" resultType="TestDataChild11" >
SELECT
<include refid="testDataChild11Columns"/>
FROM test_data_child a
<include refid="testDataChild11Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild11" >
SELECT
<include refid="testDataChild11Columns"/>
FROM test_data_child a
<include refid="testDataChild11Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main_id = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild11" >
SELECT
<include refid="testDataChild11Columns"/>
FROM test_data_child a
<include refid="testDataChild11Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child(
id,
startarea,
endarea,
starttime,
price,
yes_no,
test_data_main_id,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{starttime},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child SET
startarea = #{startArea.id},
endarea = #{endArea.id},
starttime = #{starttime},
price = #{price},
yes_no = #{isHave},
test_data_main_id = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main_id = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main_id = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild11" statementType="STATEMENT">
select * FROM test_data_child where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild12Mapper">
<sql id="testDataChild12Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.starttime AS "startTime",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild12Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main
</sql>
<select id="get" resultType="TestDataChild12" >
SELECT
<include refid="testDataChild12Columns"/>
FROM test_data_child2 a
<include refid="testDataChild12Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild12" >
SELECT
<include refid="testDataChild12Columns"/>
FROM test_data_child2 a
<include refid="testDataChild12Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild12" >
SELECT
<include refid="testDataChild12Columns"/>
FROM test_data_child2 a
<include refid="testDataChild12Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child2(
id,
startarea,
endarea,
starttime,
price,
yes_no,
test_data_main,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{startTime},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child2 SET
startarea = #{startArea.id},
endarea = #{endArea.id},
starttime = #{startTime},
price = #{price},
yes_no = #{isHave},
test_data_main = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child2
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child2 SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild12" statementType="STATEMENT">
select * FROM test_data_child2 where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild13Mapper">
<sql id="testDataChild13Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild13Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main
</sql>
<select id="get" resultType="TestDataChild13" >
SELECT
<include refid="testDataChild13Columns"/>
FROM test_data_child3 a
<include refid="testDataChild13Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild13" >
SELECT
<include refid="testDataChild13Columns"/>
FROM test_data_child3 a
<include refid="testDataChild13Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild13" >
SELECT
<include refid="testDataChild13Columns"/>
FROM test_data_child3 a
<include refid="testDataChild13Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child3(
id,
startarea,
endarea,
price,
yes_no,
test_data_main,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child3 SET
startarea = #{startArea.id},
endarea = #{endArea.id},
price = #{price},
yes_no = #{isHave},
test_data_main = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child3
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child3 SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild13" statementType="STATEMENT">
select * FROM test_data_child3 where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataMain1Mapper">
<sql id="testDataMain1Columns">
a.id AS "id",
a.user_id AS "tuser.id",
a.office_id AS "office.id",
a.area_id AS "area.id",
a.name AS "name",
a.sex AS "sex",
a.in_date AS "inDate",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
tuser.name AS "tuser.name",
office.name AS "office.name",
area.name AS "area.name"
</sql>
<sql id="testDataMain1Joins">
LEFT JOIN sys_user tuser ON tuser.id = a.user_id
LEFT JOIN sys_office office ON office.id = a.office_id
LEFT JOIN sys_area area ON area.id = a.area_id
</sql>
<select id="get" resultType="TestDataMain1" >
SELECT
<include refid="testDataMain1Columns"/>
FROM test_data_main a
<include refid="testDataMain1Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataMain1" >
SELECT
<include refid="testDataMain1Columns"/>
FROM test_data_main a
<include refid="testDataMain1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="tuser != null and tuser.id != null and tuser.id != ''">
AND a.user_id = #{tuser.id}
</if>
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="sex != null and sex != ''">
AND a.sex = #{sex}
</if>
<if test="beginInDate != null and endInDate != null ">
AND a.in_date BETWEEN #{beginInDate} AND #{endInDate}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataMain1" >
SELECT
<include refid="testDataMain1Columns"/>
FROM test_data_main a
<include refid="testDataMain1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_main(
id,
user_id,
office_id,
area_id,
name,
sex,
in_date,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{tuser.id},
#{office.id},
#{area.id},
#{name},
#{sex},
#{inDate},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_main SET
user_id = #{tuser.id},
office_id = #{office.id},
area_id = #{area.id},
name = #{name},
sex = #{sex},
in_date = #{inDate},
create_date = #{createDate},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_main
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_main SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataMain1" statementType="STATEMENT">
select * FROM test_data_main where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataMain1;
import com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataMain1Mapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild11;
import com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild11Mapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild12;
import com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild12Mapper;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataChild13;
import com.jeeplus.modules.test.onetomany.dialog.mapper.TestDataChild13Mapper;
/**
* 票务代理Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestDataMain1Service extends CrudService<TestDataMain1Mapper, TestDataMain1> {
@Autowired
private TestDataChild11Mapper testDataChild11Mapper;
@Autowired
private TestDataChild12Mapper testDataChild12Mapper;
@Autowired
private TestDataChild13Mapper testDataChild13Mapper;
public TestDataMain1 get(String id) {
TestDataMain1 testDataMain1 = super.get(id);
testDataMain1.setTestDataChild11List(testDataChild11Mapper.findList(new TestDataChild11(testDataMain1)));
testDataMain1.setTestDataChild12List(testDataChild12Mapper.findList(new TestDataChild12(testDataMain1)));
testDataMain1.setTestDataChild13List(testDataChild13Mapper.findList(new TestDataChild13(testDataMain1)));
return testDataMain1;
}
public List<TestDataMain1> findList(TestDataMain1 testDataMain1) {
return super.findList(testDataMain1);
}
public Page<TestDataMain1> findPage(Page<TestDataMain1> page, TestDataMain1 testDataMain1) {
return super.findPage(page, testDataMain1);
}
@Transactional(readOnly = false)
public void save(TestDataMain1 testDataMain1) {
super.save(testDataMain1);
for (TestDataChild11 testDataChild11 : testDataMain1.getTestDataChild11List()){
if (testDataChild11.getId() == null){
continue;
}
if (TestDataChild11.DEL_FLAG_NORMAL.equals(testDataChild11.getDelFlag())){
if (StringUtils.isBlank(testDataChild11.getId())){
testDataChild11.setTestDataMain(testDataMain1);
testDataChild11.preInsert();
testDataChild11Mapper.insert(testDataChild11);
}else{
testDataChild11.preUpdate();
testDataChild11Mapper.update(testDataChild11);
}
}else{
testDataChild11Mapper.delete(testDataChild11);
}
}
for (TestDataChild12 testDataChild12 : testDataMain1.getTestDataChild12List()){
if (testDataChild12.getId() == null){
continue;
}
if (TestDataChild12.DEL_FLAG_NORMAL.equals(testDataChild12.getDelFlag())){
if (StringUtils.isBlank(testDataChild12.getId())){
testDataChild12.setTestDataMain(testDataMain1);
testDataChild12.preInsert();
testDataChild12Mapper.insert(testDataChild12);
}else{
testDataChild12.preUpdate();
testDataChild12Mapper.update(testDataChild12);
}
}else{
testDataChild12Mapper.delete(testDataChild12);
}
}
for (TestDataChild13 testDataChild13 : testDataMain1.getTestDataChild13List()){
if (testDataChild13.getId() == null){
continue;
}
if (TestDataChild13.DEL_FLAG_NORMAL.equals(testDataChild13.getDelFlag())){
if (StringUtils.isBlank(testDataChild13.getId())){
testDataChild13.setTestDataMain(testDataMain1);
testDataChild13.preInsert();
testDataChild13Mapper.insert(testDataChild13);
}else{
testDataChild13.preUpdate();
testDataChild13Mapper.update(testDataChild13);
}
}else{
testDataChild13Mapper.delete(testDataChild13);
}
}
}
@Transactional(readOnly = false)
public void delete(TestDataMain1 testDataMain1) {
super.delete(testDataMain1);
testDataChild11Mapper.delete(new TestDataChild11(testDataMain1));
testDataChild12Mapper.delete(new TestDataChild12(testDataMain1));
testDataChild13Mapper.delete(new TestDataChild13(testDataMain1));
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.dialog.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.onetomany.dialog.entity.TestDataMain1;
import com.jeeplus.modules.test.onetomany.dialog.service.TestDataMain1Service;
/**
* 票务代理Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/onetomany/dialog/testDataMain1")
public class TestDataMain1Controller extends BaseController {
@Autowired
private TestDataMain1Service testDataMain1Service;
@ModelAttribute
public TestDataMain1 get(@RequestParam(required=false) String id) {
TestDataMain1 entity = null;
if (StringUtils.isNotBlank(id)){
entity = testDataMain1Service.get(id);
}
if (entity == null){
entity = new TestDataMain1();
}
return entity;
}
/**
* 票务代理列表页面
*/
@RequiresPermissions("test:onetomany:dialog:testDataMain1:list")
@RequestMapping(value = {"list", ""})
public String list(TestDataMain1 testDataMain1, Model model) {
model.addAttribute("testDataMain1", testDataMain1);
return "modules/test/onetomany/dialog/testDataMain1List";
}
/**
* 票务代理列表数据
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestDataMain1 testDataMain1, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestDataMain1> page = testDataMain1Service.findPage(new Page<TestDataMain1>(request, response), testDataMain1);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑票务代理表单页面
*/
@RequiresPermissions(value={"test:onetomany:dialog:testDataMain1:view","test:onetomany:dialog:testDataMain1:add","test:onetomany:dialog:testDataMain1:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(TestDataMain1 testDataMain1, Model model) {
model.addAttribute("testDataMain1", testDataMain1);
return "modules/test/onetomany/dialog/testDataMain1Form";
}
/**
* 保存票务代理
*/
@ResponseBody
@RequiresPermissions(value={"test:onetomany:dialog:testDataMain1:add","test:onetomany:dialog:testDataMain1:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestDataMain1 testDataMain1, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testDataMain1);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testDataMain1Service.save(testDataMain1);//保存
j.setSuccess(true);
j.setMsg("保存票务代理成功");
return j;
}
/**
* 删除票务代理
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestDataMain1 testDataMain1) {
AjaxJson j = new AjaxJson();
testDataMain1Service.delete(testDataMain1);
j.setMsg("删除票务代理成功");
return j;
}
/**
* 批量删除票务代理
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testDataMain1Service.delete(testDataMain1Service.get(id));
}
j.setMsg("删除票务代理成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestDataMain1 testDataMain1, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "票务代理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestDataMain1> page = testDataMain1Service.findPage(new Page<TestDataMain1>(request, response, -1), testDataMain1);
new ExportExcel("票务代理", TestDataMain1.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出票务代理记录失败!失败信息:"+e.getMessage());
}
return j;
}
@ResponseBody
@RequestMapping(value = "detail")
public TestDataMain1 detail(String id) {
return testDataMain1Service.get(id);
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestDataMain1> list = ei.getDataList(TestDataMain1.class);
for (TestDataMain1 testDataMain1 : list){
try{
testDataMain1Service.save(testDataMain1);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条票务代理记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条票务代理记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入票务代理失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入票务代理数据模板
*/
@ResponseBody
@RequiresPermissions("test:onetomany:dialog:testDataMain1:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "票务代理数据导入模板.xlsx";
List<TestDataMain1> list = Lists.newArrayList();
new ExportExcel("票务代理数据", TestDataMain1.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 火车票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild21 extends DataEntity<TestDataChild21> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private Date starttime; // 出发时间
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain2 testDataMain; // 业务主表ID 父类
public TestDataChild21() {
super();
}
public TestDataChild21(String id){
super(id);
}
public TestDataChild21(TestDataMain2 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="出发时间不能为空")
@ExcelField(title="出发时间", align=2, sort=3)
public Date getStarttime() {
return starttime;
}
public void setStarttime(Date starttime) {
this.starttime = starttime;
}
@NotNull(message="代理价格不能为空")
@ExcelField(title="代理价格", align=2, sort=4)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=5)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain2 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain2 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 飞机票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild22 extends DataEntity<TestDataChild22> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private String startTime; // 出发时间
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain2 testDataMain; // 外键 父类
public TestDataChild22() {
super();
}
public TestDataChild22(String id){
super(id);
}
public TestDataChild22(TestDataMain2 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@ExcelField(title="出发时间", align=2, sort=3)
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
@NotNull(message="代理价格不能为空")
@ExcelField(title="代理价格", align=2, sort=4)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=5)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain2 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain2 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.entity;
import com.jeeplus.modules.sys.entity.Area;
import javax.validation.constraints.NotNull;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 汽车票Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataChild23 extends DataEntity<TestDataChild23> {
private static final long serialVersionUID = 1L;
private Area startArea; // 出发地
private Area endArea; // 目的地
private Double price; // 代理价格
private String isHave; // 是否有票
private TestDataMain2 testDataMain; // 外键 父类
public TestDataChild23() {
super();
}
public TestDataChild23(String id){
super(id);
}
public TestDataChild23(TestDataMain2 testDataMain){
this.testDataMain = testDataMain;
}
@NotNull(message="出发地不能为空")
@ExcelField(title="出发地", fieldType=Area.class, value="startArea.name", align=2, sort=1)
public Area getStartArea() {
return startArea;
}
public void setStartArea(Area startArea) {
this.startArea = startArea;
}
@NotNull(message="目的地不能为空")
@ExcelField(title="目的地", fieldType=Area.class, value="endArea.name", align=2, sort=2)
public Area getEndArea() {
return endArea;
}
public void setEndArea(Area endArea) {
this.endArea = endArea;
}
@ExcelField(title="代理价格", align=2, sort=3)
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
@ExcelField(title="是否有票", dictType="yes_no", align=2, sort=4)
public String getIsHave() {
return isHave;
}
public void setIsHave(String isHave) {
this.isHave = isHave;
}
public TestDataMain2 getTestDataMain() {
return testDataMain;
}
public void setTestDataMain(TestDataMain2 testDataMain) {
this.testDataMain = testDataMain;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.entity;
import com.jeeplus.modules.sys.entity.User;
import javax.validation.constraints.NotNull;
import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.entity.Area;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.List;
import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 票务代理Entity
* @author liugf
* @version 2018-06-12
*/
public class TestDataMain2 extends DataEntity<TestDataMain2> {
private static final long serialVersionUID = 1L;
private User tuser; // 归属用户
private Office office; // 归属部门
private Area area; // 归属区域
private String name; // 名称
private String sex; // 性别
private Date inDate; // 加入日期
private Date beginInDate; // 开始 加入日期
private Date endInDate; // 结束 加入日期
private List<TestDataChild21> testDataChild21List = Lists.newArrayList(); // 子表列表
private List<TestDataChild22> testDataChild22List = Lists.newArrayList(); // 子表列表
private List<TestDataChild23> testDataChild23List = Lists.newArrayList(); // 子表列表
public TestDataMain2() {
super();
}
public TestDataMain2(String id){
super(id);
}
@NotNull(message="归属用户不能为空")
@ExcelField(title="归属用户", fieldType=User.class, value="tuser.name", align=2, sort=1)
public User getTuser() {
return tuser;
}
public void setTuser(User tuser) {
this.tuser = tuser;
}
@NotNull(message="归属部门不能为空")
@ExcelField(title="归属部门", fieldType=Office.class, value="office.name", align=2, sort=2)
public Office getOffice() {
return office;
}
public void setOffice(Office office) {
this.office = office;
}
@NotNull(message="归属区域不能为空")
@ExcelField(title="归属区域", fieldType=Area.class, value="area.name", align=2, sort=3)
public Area getArea() {
return area;
}
public void setArea(Area area) {
this.area = area;
}
@ExcelField(title="名称", align=2, sort=4)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ExcelField(title="性别", dictType="sex", align=2, sort=5)
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="加入日期不能为空")
@ExcelField(title="加入日期", align=2, sort=6)
public Date getInDate() {
return inDate;
}
public void setInDate(Date inDate) {
this.inDate = inDate;
}
public Date getBeginInDate() {
return beginInDate;
}
public void setBeginInDate(Date beginInDate) {
this.beginInDate = beginInDate;
}
public Date getEndInDate() {
return endInDate;
}
public void setEndInDate(Date endInDate) {
this.endInDate = endInDate;
}
public List<TestDataChild21> getTestDataChild21List() {
return testDataChild21List;
}
public void setTestDataChild21List(List<TestDataChild21> testDataChild21List) {
this.testDataChild21List = testDataChild21List;
}
public List<TestDataChild22> getTestDataChild22List() {
return testDataChild22List;
}
public void setTestDataChild22List(List<TestDataChild22> testDataChild22List) {
this.testDataChild22List = testDataChild22List;
}
public List<TestDataChild23> getTestDataChild23List() {
return testDataChild23List;
}
public void setTestDataChild23List(List<TestDataChild23> testDataChild23List) {
this.testDataChild23List = testDataChild23List;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild21;
/**
* 火车票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild21Mapper extends BaseMapper<TestDataChild21> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild22;
/**
* 飞机票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild22Mapper extends BaseMapper<TestDataChild22> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild23;
/**
* 汽车票MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataChild23Mapper extends BaseMapper<TestDataChild23> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataMain2;
/**
* 票务代理MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestDataMain2Mapper extends BaseMapper<TestDataMain2> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild21Mapper">
<sql id="testDataChild21Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.starttime AS "starttime",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main_id AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild21Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main_id
</sql>
<select id="get" resultType="TestDataChild21" >
SELECT
<include refid="testDataChild21Columns"/>
FROM test_data_child a
<include refid="testDataChild21Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild21" >
SELECT
<include refid="testDataChild21Columns"/>
FROM test_data_child a
<include refid="testDataChild21Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main_id = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild21" >
SELECT
<include refid="testDataChild21Columns"/>
FROM test_data_child a
<include refid="testDataChild21Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child(
id,
startarea,
endarea,
starttime,
price,
yes_no,
test_data_main_id,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{starttime},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child SET
startarea = #{startArea.id},
endarea = #{endArea.id},
starttime = #{starttime},
price = #{price},
yes_no = #{isHave},
test_data_main_id = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main_id = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main_id = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild21" statementType="STATEMENT">
select * FROM test_data_child where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild22Mapper">
<sql id="testDataChild22Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.starttime AS "startTime",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild22Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main
</sql>
<select id="get" resultType="TestDataChild22" >
SELECT
<include refid="testDataChild22Columns"/>
FROM test_data_child2 a
<include refid="testDataChild22Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild22" >
SELECT
<include refid="testDataChild22Columns"/>
FROM test_data_child2 a
<include refid="testDataChild22Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild22" >
SELECT
<include refid="testDataChild22Columns"/>
FROM test_data_child2 a
<include refid="testDataChild22Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child2(
id,
startarea,
endarea,
starttime,
price,
yes_no,
test_data_main,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{startTime},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child2 SET
startarea = #{startArea.id},
endarea = #{endArea.id},
starttime = #{startTime},
price = #{price},
yes_no = #{isHave},
test_data_main = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child2
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child2 SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild22" statementType="STATEMENT">
select * FROM test_data_child2 where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild23Mapper">
<sql id="testDataChild23Columns">
a.id AS "id",
a.startarea AS "startArea.id",
a.endarea AS "endArea.id",
a.price AS "price",
a.yes_no AS "isHave",
a.test_data_main AS "testDataMain.id",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag",
startArea.name AS "startArea.name",
endArea.name AS "endArea.name"
</sql>
<sql id="testDataChild23Joins">
LEFT JOIN sys_area startArea ON startArea.id = a.startarea
LEFT JOIN sys_area endArea ON endArea.id = a.endarea
LEFT JOIN test_data_main b ON b.id = a.test_data_main
</sql>
<select id="get" resultType="TestDataChild23" >
SELECT
<include refid="testDataChild23Columns"/>
FROM test_data_child3 a
<include refid="testDataChild23Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestDataChild23" >
SELECT
<include refid="testDataChild23Columns"/>
FROM test_data_child3 a
<include refid="testDataChild23Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="testDataMain != null and testDataMain.id != null and testDataMain.id != ''">
AND a.test_data_main = #{testDataMain.id}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestDataChild23" >
SELECT
<include refid="testDataChild23Columns"/>
FROM test_data_child3 a
<include refid="testDataChild23Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_data_child3(
id,
startarea,
endarea,
price,
yes_no,
test_data_main,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{startArea.id},
#{endArea.id},
#{price},
#{isHave},
#{testDataMain.id},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_data_child3 SET
startarea = #{startArea.id},
endarea = #{endArea.id},
price = #{price},
yes_no = #{isHave},
test_data_main = #{testDataMain.id},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_data_child3
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_data_child3 SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE test_data_main = #{testDataMain.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestDataChild23" statementType="STATEMENT">
select * FROM test_data_child3 where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataMain2;
import com.jeeplus.modules.test.onetomany.form.mapper.TestDataMain2Mapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild21;
import com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild21Mapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild22;
import com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild22Mapper;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataChild23;
import com.jeeplus.modules.test.onetomany.form.mapper.TestDataChild23Mapper;
/**
* 票务代理Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestDataMain2Service extends CrudService<TestDataMain2Mapper, TestDataMain2> {
@Autowired
private TestDataChild21Mapper testDataChild21Mapper;
@Autowired
private TestDataChild22Mapper testDataChild22Mapper;
@Autowired
private TestDataChild23Mapper testDataChild23Mapper;
public TestDataMain2 get(String id) {
TestDataMain2 testDataMain2 = super.get(id);
testDataMain2.setTestDataChild21List(testDataChild21Mapper.findList(new TestDataChild21(testDataMain2)));
testDataMain2.setTestDataChild22List(testDataChild22Mapper.findList(new TestDataChild22(testDataMain2)));
testDataMain2.setTestDataChild23List(testDataChild23Mapper.findList(new TestDataChild23(testDataMain2)));
return testDataMain2;
}
public List<TestDataMain2> findList(TestDataMain2 testDataMain2) {
return super.findList(testDataMain2);
}
public Page<TestDataMain2> findPage(Page<TestDataMain2> page, TestDataMain2 testDataMain2) {
return super.findPage(page, testDataMain2);
}
@Transactional(readOnly = false)
public void save(TestDataMain2 testDataMain2) {
super.save(testDataMain2);
for (TestDataChild21 testDataChild21 : testDataMain2.getTestDataChild21List()){
if (testDataChild21.getId() == null){
continue;
}
if (TestDataChild21.DEL_FLAG_NORMAL.equals(testDataChild21.getDelFlag())){
if (StringUtils.isBlank(testDataChild21.getId())){
testDataChild21.setTestDataMain(testDataMain2);
testDataChild21.preInsert();
testDataChild21Mapper.insert(testDataChild21);
}else{
testDataChild21.preUpdate();
testDataChild21Mapper.update(testDataChild21);
}
}else{
testDataChild21Mapper.delete(testDataChild21);
}
}
for (TestDataChild22 testDataChild22 : testDataMain2.getTestDataChild22List()){
if (testDataChild22.getId() == null){
continue;
}
if (TestDataChild22.DEL_FLAG_NORMAL.equals(testDataChild22.getDelFlag())){
if (StringUtils.isBlank(testDataChild22.getId())){
testDataChild22.setTestDataMain(testDataMain2);
testDataChild22.preInsert();
testDataChild22Mapper.insert(testDataChild22);
}else{
testDataChild22.preUpdate();
testDataChild22Mapper.update(testDataChild22);
}
}else{
testDataChild22Mapper.delete(testDataChild22);
}
}
for (TestDataChild23 testDataChild23 : testDataMain2.getTestDataChild23List()){
if (testDataChild23.getId() == null){
continue;
}
if (TestDataChild23.DEL_FLAG_NORMAL.equals(testDataChild23.getDelFlag())){
if (StringUtils.isBlank(testDataChild23.getId())){
testDataChild23.setTestDataMain(testDataMain2);
testDataChild23.preInsert();
testDataChild23Mapper.insert(testDataChild23);
}else{
testDataChild23.preUpdate();
testDataChild23Mapper.update(testDataChild23);
}
}else{
testDataChild23Mapper.delete(testDataChild23);
}
}
}
@Transactional(readOnly = false)
public void delete(TestDataMain2 testDataMain2) {
super.delete(testDataMain2);
testDataChild21Mapper.delete(new TestDataChild21(testDataMain2));
testDataChild22Mapper.delete(new TestDataChild22(testDataMain2));
testDataChild23Mapper.delete(new TestDataChild23(testDataMain2));
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.onetomany.form.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.onetomany.form.entity.TestDataMain2;
import com.jeeplus.modules.test.onetomany.form.service.TestDataMain2Service;
/**
* 票务代理Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/onetomany/form/testDataMain2")
public class TestDataMain2Controller extends BaseController {
@Autowired
private TestDataMain2Service testDataMain2Service;
@ModelAttribute
public TestDataMain2 get(@RequestParam(required=false) String id) {
TestDataMain2 entity = null;
if (StringUtils.isNotBlank(id)){
entity = testDataMain2Service.get(id);
}
if (entity == null){
entity = new TestDataMain2();
}
return entity;
}
/**
* 票务代理列表页面
*/
@RequiresPermissions("test:onetomany:form:testDataMain2:list")
@RequestMapping(value = {"list", ""})
public String list(TestDataMain2 testDataMain2, Model model) {
model.addAttribute("testDataMain2", testDataMain2);
return "modules/test/onetomany/form/testDataMain2List";
}
/**
* 票务代理列表数据
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestDataMain2 testDataMain2, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestDataMain2> page = testDataMain2Service.findPage(new Page<TestDataMain2>(request, response), testDataMain2);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑票务代理表单页面
*/
@RequiresPermissions(value={"test:onetomany:form:testDataMain2:view","test:onetomany:form:testDataMain2:add","test:onetomany:form:testDataMain2:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestDataMain2 testDataMain2, Model model) {
model.addAttribute("testDataMain2", testDataMain2);
model.addAttribute("mode", mode);
return "modules/test/onetomany/form/testDataMain2Form";
}
/**
* 保存票务代理
*/
@ResponseBody
@RequiresPermissions(value={"test:onetomany:form:testDataMain2:add","test:onetomany:form:testDataMain2:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestDataMain2 testDataMain2, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testDataMain2);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testDataMain2Service.save(testDataMain2);//保存
j.setSuccess(true);
j.setMsg("保存票务代理成功");
return j;
}
/**
* 删除票务代理
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestDataMain2 testDataMain2) {
AjaxJson j = new AjaxJson();
testDataMain2Service.delete(testDataMain2);
j.setMsg("删除票务代理成功");
return j;
}
/**
* 批量删除票务代理
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testDataMain2Service.delete(testDataMain2Service.get(id));
}
j.setMsg("删除票务代理成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestDataMain2 testDataMain2, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "票务代理"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestDataMain2> page = testDataMain2Service.findPage(new Page<TestDataMain2>(request, response, -1), testDataMain2);
new ExportExcel("票务代理", TestDataMain2.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出票务代理记录失败!失败信息:"+e.getMessage());
}
return j;
}
@ResponseBody
@RequestMapping(value = "detail")
public TestDataMain2 detail(String id) {
return testDataMain2Service.get(id);
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestDataMain2> list = ei.getDataList(TestDataMain2.class);
for (TestDataMain2 testDataMain2 : list){
try{
testDataMain2Service.save(testDataMain2);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条票务代理记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条票务代理记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入票务代理失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入票务代理数据模板
*/
@ResponseBody
@RequiresPermissions("test:onetomany:form:testDataMain2:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "票务代理数据导入模板.xlsx";
List<TestDataMain2> list = Lists.newArrayList();
new ExportExcel("票务代理数据", TestDataMain2.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.pic.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 图片管理Entity
* @author lgf
* @version 2018-06-12
*/
public class TestPic extends DataEntity<TestPic> {
private static final long serialVersionUID = 1L;
private String title; // 标题
private String pic; // 图片路径
public TestPic() {
super();
}
public TestPic(String id){
super(id);
}
@ExcelField(title="标题", align=2, sort=1)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@ExcelField(title="图片路径", align=2, sort=2)
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.pic.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.pic.entity.TestPic;
/**
* 图片管理MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestPicMapper extends BaseMapper<TestPic> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.pic.mapper.TestPicMapper">
<sql id="testPicColumns">
a.id AS "id",
a.title AS "title",
a.pic AS "pic",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="testPicJoins">
</sql>
<select id="get" resultType="TestPic" >
SELECT
<include refid="testPicColumns"/>
FROM test_pic a
<include refid="testPicJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestPic" >
SELECT
<include refid="testPicColumns"/>
FROM test_pic a
<include refid="testPicJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestPic" >
SELECT
<include refid="testPicColumns"/>
FROM test_pic a
<include refid="testPicJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_pic(
id,
title,
pic,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{title},
#{pic},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_pic SET
title = #{title},
pic = #{pic},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_pic
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_pic SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestPic" statementType="STATEMENT">
select * FROM test_pic where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.pic.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.pic.entity.TestPic;
import com.jeeplus.modules.test.pic.mapper.TestPicMapper;
/**
* 图片管理Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestPicService extends CrudService<TestPicMapper, TestPic> {
public TestPic get(String id) {
return super.get(id);
}
public List<TestPic> findList(TestPic testPic) {
return super.findList(testPic);
}
public Page<TestPic> findPage(Page<TestPic> page, TestPic testPic) {
return super.findPage(page, testPic);
}
@Transactional(readOnly = false)
public void save(TestPic testPic) {
super.save(testPic);
}
@Transactional(readOnly = false)
public void delete(TestPic testPic) {
super.delete(testPic);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.dialog.entity;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.jeeplus.core.persistence.TreeEntity;
/**
* 组织机构Entity
* @author liugf
* @version 2018-06-12
*/
public class TestTree1 extends TreeEntity<TestTree1> {
private static final long serialVersionUID = 1L;
public TestTree1() {
super();
}
public TestTree1(String id){
super(id);
}
public TestTree1 getParent() {
return parent;
}
@Override
public void setParent(TestTree1 parent) {
this.parent = parent;
}
public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.dialog.mapper;
import com.jeeplus.core.persistence.TreeMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.tree.dialog.entity.TestTree1;
/**
* 组织机构MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestTree1Mapper extends TreeMapper<TestTree1> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.tree.dialog.mapper.TestTree1Mapper">
<resultMap id="testTree1Result" type="TestTree1">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="sort" column="sort" />
<result property="parentIds" column="parentIds" />
<association property="hasChildren" column="id" select="hasChildren" />
</resultMap>
<sql id="testTree1Columns">
a.id AS "id",
a.name AS "name",
a.sort AS "sort",
a.parent_id AS "parent.id",
a.parent_ids AS "parentIds",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="testTree1Joins">
</sql>
<select id="get" resultType="TestTree1">
SELECT
<include refid="testTree1Columns"/>
FROM test_tree a
<include refid="testTree1Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestTree1">
SELECT
<include refid="testTree1Columns"/>
FROM test_tree a
<include refid="testTree1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="sort != null and sort != ''">
AND a.sort = #{sort}
</if>
<if test="parent != null and parent.id != null and parent.id != ''">
AND a.parent_id = #{parent.id}
</if>
<if test="parentIds != null and parentIds != ''">
AND a.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{parentIds}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{parentIds}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{parentIds},'%')</if>
</if>
<if test="remarks != null and remarks != ''">
AND a.remarks = #{remarks}
</if>
</where>
ORDER BY a.sort ASC
</select>
<select id="findAllList" resultType="TestTree1">
SELECT
<include refid="testTree1Columns"/>
FROM test_tree a
<include refid="testTree1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
ORDER BY a.sort ASC
</select>
<select id="getChildren" parameterType="String" resultMap="testTree1Result">
select * from test_tree where parent_id = #{id} ORDER BY sort
</select>
<select id="hasChildren" parameterType="String" resultType="Boolean">
select case when exists(select 1 from test_tree where parent_id = #{id}) then 1 else 0 end ${dual}
</select>
<select id="findByParentIdsLike" resultType="TestTree1">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM test_tree a
<include refid="testTree1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.parent_ids LIKE #{parentIds}
</where>
ORDER BY a.sort ASC
</select>
<insert id="insert">
INSERT INTO test_tree(
id,
name,
sort,
parent_id,
parent_ids,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{sort},
#{parent.id},
#{parentIds},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_tree SET
name = #{name},
sort = #{sort},
parent_id = #{parent.id},
parent_ids = #{parentIds},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<update id="updateParentIds">
UPDATE test_tree SET
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_tree
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_tree SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.dialog.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.service.TreeService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.tree.dialog.entity.TestTree1;
import com.jeeplus.modules.test.tree.dialog.mapper.TestTree1Mapper;
/**
* 组织机构Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestTree1Service extends TreeService<TestTree1Mapper, TestTree1> {
public TestTree1 get(String id) {
return super.get(id);
}
public List<TestTree1> findList(TestTree1 testTree1) {
if (StringUtils.isNotBlank(testTree1.getParentIds())){
testTree1.setParentIds(","+testTree1.getParentIds()+",");
}
return super.findList(testTree1);
}
@Transactional(readOnly = false)
public void save(TestTree1 testTree1) {
super.save(testTree1);
}
@Transactional(readOnly = false)
public void delete(TestTree1 testTree1) {
super.delete(testTree1);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.dialog.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.tree.dialog.entity.TestTree1;
import com.jeeplus.modules.test.tree.dialog.service.TestTree1Service;
/**
* 组织机构Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/tree/dialog/testTree1")
public class TestTree1Controller extends BaseController {
@Autowired
private TestTree1Service testTree1Service;
@ModelAttribute
public TestTree1 get(@RequestParam(required=false) String id) {
TestTree1 entity = null;
if (StringUtils.isNotBlank(id)){
entity = testTree1Service.get(id);
}
if (entity == null){
entity = new TestTree1();
}
return entity;
}
/**
* 机构列表页面
*/
@RequiresPermissions("test:tree:dialog:testTree1:list")
@RequestMapping(value = {"list", ""})
public String list(TestTree1 testTree1, HttpServletRequest request, HttpServletResponse response, Model model) {
model.addAttribute("testTree1", testTree1);
return "modules/test/tree/dialog/testTree1List";
}
/**
* 查看,增加,编辑机构表单页面
*/
@RequiresPermissions(value={"test:tree:dialog:testTree1:view","test:tree:dialog:testTree1:add","test:tree:dialog:testTree1:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(TestTree1 testTree1, Model model) {
if (testTree1.getParent()!=null && StringUtils.isNotBlank(testTree1.getParent().getId())){
testTree1.setParent(testTree1Service.get(testTree1.getParent().getId()));
// 获取排序号,最末节点排序号+30
if (StringUtils.isBlank(testTree1.getId())){
TestTree1 testTree1Child = new TestTree1();
testTree1Child.setParent(new TestTree1(testTree1.getParent().getId()));
List<TestTree1> list = testTree1Service.findList(testTree1);
if (list.size() > 0){
testTree1.setSort(list.get(list.size()-1).getSort());
if (testTree1.getSort() != null){
testTree1.setSort(testTree1.getSort() + 30);
}
}
}
}
if (testTree1.getSort() == null){
testTree1.setSort(30);
}
model.addAttribute("testTree1", testTree1);
return "modules/test/tree/dialog/testTree1Form";
}
/**
* 保存机构
*/
@ResponseBody
@RequiresPermissions(value={"test:tree:dialog:testTree1:add","test:tree:dialog:testTree1:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestTree1 testTree1, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testTree1);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testTree1Service.save(testTree1);//保存
j.setSuccess(true);
j.put("testTree1", testTree1);
j.setMsg("保存机构成功");
return j;
}
@ResponseBody
@RequestMapping(value = "getChildren")
public List<TestTree1> getChildren(String parentId){
if("-1".equals(parentId)){//如果是-1,没指定任何父节点,就从根节点开始查找
parentId = "0";
}
return testTree1Service.getChildren(parentId);
}
/**
* 删除机构
*/
@ResponseBody
@RequiresPermissions("test:tree:dialog:testTree1:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestTree1 testTree1) {
AjaxJson j = new AjaxJson();
testTree1Service.delete(testTree1);
j.setSuccess(true);
j.setMsg("删除机构成功");
return j;
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
List<TestTree1> list = testTree1Service.findList(new TestTree1());
for (int i=0; i<list.size(); i++){
TestTree1 e = list.get(i);
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("text", e.getName());
if(StringUtils.isBlank(e.getParentId()) || "0".equals(e.getParentId())){
map.put("parent", "#");
Map<String, Object> state = Maps.newHashMap();
state.put("opened", true);
map.put("state", state);
}else{
map.put("parent", e.getParentId());
}
mapList.add(map);
}
}
return mapList;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.form.entity;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.jeeplus.core.persistence.TreeEntity;
/**
* 组织机构Entity
* @author liugf
* @version 2018-06-12
*/
public class TestTree2 extends TreeEntity<TestTree2> {
private static final long serialVersionUID = 1L;
public TestTree2() {
super();
}
public TestTree2(String id){
super(id);
}
public TestTree2 getParent() {
return parent;
}
@Override
public void setParent(TestTree2 parent) {
this.parent = parent;
}
public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.form.mapper;
import com.jeeplus.core.persistence.TreeMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.tree.form.entity.TestTree2;
/**
* 组织机构MAPPER接口
* @author liugf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestTree2Mapper extends TreeMapper<TestTree2> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.tree.form.mapper.TestTree2Mapper">
<resultMap id="testTree2Result" type="TestTree2">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="sort" column="sort" />
<result property="parentIds" column="parentIds" />
<association property="hasChildren" column="id" select="hasChildren" />
</resultMap>
<sql id="testTree2Columns">
a.id AS "id",
a.name AS "name",
a.sort AS "sort",
a.parent_id AS "parent.id",
a.parent_ids AS "parentIds",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="testTree2Joins">
</sql>
<select id="get" resultType="TestTree2">
SELECT
<include refid="testTree2Columns"/>
FROM test_tree a
<include refid="testTree2Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestTree2">
SELECT
<include refid="testTree2Columns"/>
FROM test_tree a
<include refid="testTree2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="sort != null and sort != ''">
AND a.sort = #{sort}
</if>
<if test="parent != null and parent.id != null and parent.id != ''">
AND a.parent_id = #{parent.id}
</if>
<if test="parentIds != null and parentIds != ''">
AND a.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{parentIds}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{parentIds}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{parentIds},'%')</if>
</if>
<if test="remarks != null and remarks != ''">
AND a.remarks = #{remarks}
</if>
</where>
ORDER BY a.sort ASC
</select>
<select id="findAllList" resultType="TestTree2">
SELECT
<include refid="testTree2Columns"/>
FROM test_tree a
<include refid="testTree2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
ORDER BY a.sort ASC
</select>
<select id="getChildren" parameterType="String" resultMap="testTree2Result">
select * from test_tree where parent_id = #{id} ORDER BY sort
</select>
<select id="hasChildren" parameterType="String" resultType="Boolean">
select case when exists(select 1 from test_tree where parent_id = #{id}) then 1 else 0 end ${dual}
</select>
<select id="findByParentIdsLike" resultType="TestTree2">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM test_tree a
<include refid="testTree2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.parent_ids LIKE #{parentIds}
</where>
ORDER BY a.sort ASC
</select>
<insert id="insert">
INSERT INTO test_tree(
id,
name,
sort,
parent_id,
parent_ids,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{name},
#{sort},
#{parent.id},
#{parentIds},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE test_tree SET
name = #{name},
sort = #{sort},
parent_id = #{parent.id},
parent_ids = #{parentIds},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<update id="updateParentIds">
UPDATE test_tree SET
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_tree
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_tree SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.form.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.service.TreeService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.tree.form.entity.TestTree2;
import com.jeeplus.modules.test.tree.form.mapper.TestTree2Mapper;
/**
* 组织机构Service
* @author liugf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestTree2Service extends TreeService<TestTree2Mapper, TestTree2> {
public TestTree2 get(String id) {
return super.get(id);
}
public List<TestTree2> findList(TestTree2 testTree2) {
if (StringUtils.isNotBlank(testTree2.getParentIds())){
testTree2.setParentIds(","+testTree2.getParentIds()+",");
}
return super.findList(testTree2);
}
@Transactional(readOnly = false)
public void save(TestTree2 testTree2) {
super.save(testTree2);
}
@Transactional(readOnly = false)
public void delete(TestTree2 testTree2) {
super.delete(testTree2);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.tree.form.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.tree.form.entity.TestTree2;
import com.jeeplus.modules.test.tree.form.service.TestTree2Service;
/**
* 组织机构Controller
* @author liugf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/tree/form/testTree2")
public class TestTree2Controller extends BaseController {
@Autowired
private TestTree2Service testTree2Service;
@ModelAttribute
public TestTree2 get(@RequestParam(required=false) String id) {
TestTree2 entity = null;
if (StringUtils.isNotBlank(id)){
entity = testTree2Service.get(id);
}
if (entity == null){
entity = new TestTree2();
}
return entity;
}
/**
* 机构列表页面
*/
@RequiresPermissions("test:tree:form:testTree2:list")
@RequestMapping(value = {"list", ""})
public String list(TestTree2 testTree2, @ModelAttribute("parentIds") String parentIds, HttpServletRequest request, HttpServletResponse response, Model model) {
if(StringUtils.isNotBlank(parentIds)){
model.addAttribute("parentIds", parentIds);
}
model.addAttribute("testTree2", testTree2);
return "modules/test/tree/form/testTree2List";
}
/**
* 查看,增加,编辑机构表单页面
* params:
* mode: add, edit, view,addChild 代表四种种模式的页面
*/
@RequiresPermissions(value={"test:tree:form:testTree2:view","test:tree:form:testTree2:add","test:tree:form:testTree2:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestTree2 testTree2, Model model) {
if (testTree2.getParent()!=null && StringUtils.isNotBlank(testTree2.getParent().getId())){
testTree2.setParent(testTree2Service.get(testTree2.getParent().getId()));
// 获取排序号,最末节点排序号+30
if (StringUtils.isBlank(testTree2.getId())){
TestTree2 testTree2Child = new TestTree2();
testTree2Child.setParent(new TestTree2(testTree2.getParent().getId()));
List<TestTree2> list = testTree2Service.findList(testTree2);
if (list.size() > 0){
testTree2.setSort(list.get(list.size()-1).getSort());
if (testTree2.getSort() != null){
testTree2.setSort(testTree2.getSort() + 30);
}
}
}
}
if (testTree2.getSort() == null){
testTree2.setSort(30);
}
model.addAttribute("mode", mode);
model.addAttribute("testTree2", testTree2);
return "modules/test/tree/form/testTree2Form";
}
/**
* 保存机构
*/
@ResponseBody
@RequiresPermissions(value={"test:tree:form:testTree2:add","test:tree:form:testTree2:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestTree2 testTree2, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testTree2);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testTree2Service.save(testTree2);//保存
j.setSuccess(true);
j.put("parentIds", testTree2.getParentIds());
j.setMsg("保存机构成功");
return j;
}
@ResponseBody
@RequestMapping(value = "getChildren")
public List<TestTree2> getChildren(String parentId){
if("-1".equals(parentId)){//如果是-1,没指定任何父节点,就从根节点开始查找
parentId = "0";
}
return testTree2Service.getChildren(parentId);
}
/**
* 删除机构
*/
@ResponseBody
@RequiresPermissions("test:tree:form:testTree2:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestTree2 testTree2) {
AjaxJson j = new AjaxJson();
testTree2Service.delete(testTree2);
j.setSuccess(true);
j.setMsg("删除机构成功");
return j;
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
List<TestTree2> list = testTree2Service.findList(new TestTree2());
for (int i=0; i<list.size(); i++){
TestTree2 e = list.get(i);
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("text", e.getName());
if(StringUtils.isBlank(e.getParentId()) || "0".equals(e.getParentId())){
map.put("parent", "#");
Map<String, Object> state = Maps.newHashMap();
state.put("opened", true);
map.put("state", state);
}else{
map.put("parent", e.getParentId());
}
mapList.add(map);
}
}
return mapList;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 车辆Entity
* @author lgf
* @version 2018-06-12
*/
public class Car1 extends DataEntity<Car1> {
private static final long serialVersionUID = 1L;
private String name; // 品牌
private CarKind1 kind; // 车系 父类
public Car1() {
super();
}
public Car1(String id){
super(id);
}
public Car1(CarKind1 kind){
this.kind = kind;
}
@ExcelField(title="品牌", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CarKind1 getKind() {
return kind;
}
public void setKind(CarKind1 kind) {
this.kind = kind;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.entity;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;
import java.util.List;
import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.TreeEntity;
/**
* 车系Entity
* @author lgf
* @version 2018-06-12
*/
public class CarKind1 extends TreeEntity<CarKind1> {
private static final long serialVersionUID = 1L;
private List<Car1> car1List = Lists.newArrayList(); // 子表列表
public CarKind1() {
super();
}
public CarKind1(String id){
super(id);
}
public CarKind1 getParent() {
return parent;
}
@Override
public void setParent(CarKind1 parent) {
this.parent = parent;
}
public List<Car1> getCar1List() {
return car1List;
}
public void setCar1List(List<Car1> car1List) {
this.car1List = car1List;
}
public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.treetable.dialog.entity.Car1;
/**
* 车辆MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface Car1Mapper extends BaseMapper<Car1> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.mapper;
import com.jeeplus.core.persistence.TreeMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.treetable.dialog.entity.CarKind1;
/**
* 车系MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface CarKind1Mapper extends TreeMapper<CarKind1> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.treetable.dialog.mapper.Car1Mapper">
<sql id="car1Columns">
a.id AS "id",
a.name AS "name",
a.kind_id AS "kind.id",
a.del_flag AS "delFlag",
a.remarks AS "remarks",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
b.name AS "kind.name"
</sql>
<sql id="car1Joins">
LEFT JOIN test_car_kind b ON b.id = a.kind_id
</sql>
<select id="get" resultType="Car1" >
SELECT
<include refid="car1Columns"/>
FROM test_car a
<include refid="car1Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Car1" >
SELECT
<include refid="car1Columns"/>
FROM test_car a
<include refid="car1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="kind != null and kind.id != null and kind.id != ''">
AND (b.id = #{kind.id} OR b.parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{kind.id}||',%')</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{kind.id}, ',%'))</if>
<if test="dbName == 'mssql'">'%'+#{kind.id}+'%')</if>
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Car1" >
SELECT
<include refid="car1Columns"/>
FROM test_car a
<include refid="car1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_car(
id,
name,
kind_id,
del_flag,
remarks,
create_by,
create_date,
update_by,
update_date
) VALUES (
#{id},
#{name},
#{kind.id},
#{delFlag},
#{remarks},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate}
)
</insert>
<update id="update">
UPDATE test_car SET
name = #{name},
kind_id = #{kind.id},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_car
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE kind_id = #{kind.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_car SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE kind_id = #{kind.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Car1" statementType="STATEMENT">
select * FROM test_car where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.treetable.dialog.mapper.CarKind1Mapper">
<resultMap id="carKind1Result" type="CarKind1">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="sort" column="sort" />
<result property="parentIds" column="parentIds" />
<association property="hasChildren" column="id" select="hasChildren" />
</resultMap>
<sql id="carKind1Columns">
a.id AS "id",
a.name AS "name",
a.sort AS "sort",
a.remarks AS "remarks",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.del_flag AS "delFlag",
a.parent_id AS "parent.id",
a.parent_ids AS "parentIds"
</sql>
<sql id="carKind1Joins">
</sql>
<select id="get" resultType="CarKind1">
SELECT
<include refid="carKind1Columns"/>
FROM test_car_kind a
<include refid="carKind1Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="CarKind1">
SELECT
<include refid="carKind1Columns"/>
FROM test_car_kind a
<include refid="carKind1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="parent != null and parent.id != null and parent.id != ''">
AND a.parent_id = #{parent.id}
</if>
<if test="parentIds != null and parentIds != ''">
AND a.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{parentIds}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{parentIds}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{parentIds},'%')</if>
</if>
</where>
ORDER BY a.sort ASC
</select>
<select id="findAllList" resultType="CarKind1">
SELECT
<include refid="carKind1Columns"/>
FROM test_car_kind a
<include refid="carKind1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
ORDER BY a.sort ASC
</select>
<select id="getChildren" parameterType="String" resultMap="carKind1Result">
select * from test_car_kind where parent_id = #{id} ORDER BY sort
</select>
<select id="hasChildren" parameterType="String" resultType="Boolean">
select case when exists(select 1 from test_car_kind where parent_id = #{id}) then 1 else 0 end ${dual}
</select>
<select id="findByParentIdsLike" resultType="CarKind1">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM test_car_kind a
<include refid="carKind1Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.parent_ids LIKE #{parentIds}
</where>
ORDER BY a.sort ASC
</select>
<insert id="insert">
INSERT INTO test_car_kind(
id,
name,
sort,
remarks,
create_by,
create_date,
update_by,
update_date,
del_flag,
parent_id,
parent_ids
) VALUES (
#{id},
#{name},
#{sort},
#{remarks},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{delFlag},
#{parent.id},
#{parentIds}
)
</insert>
<update id="update">
UPDATE test_car_kind SET
name = #{name},
sort = #{sort},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate},
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<update id="updateParentIds">
UPDATE test_car_kind SET
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_car_kind
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_car_kind SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.treetable.dialog.entity.Car1;
import com.jeeplus.modules.test.treetable.dialog.mapper.Car1Mapper;
/**
* 车辆Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class Car1Service extends CrudService<Car1Mapper, Car1> {
public Car1 get(String id) {
return super.get(id);
}
public List<Car1> findList(Car1 car1) {
return super.findList(car1);
}
public Page<Car1> findPage(Page<Car1> page, Car1 car1) {
return super.findPage(page, car1);
}
@Transactional(readOnly = false)
public void save(Car1 car1) {
super.save(car1);
}
@Transactional(readOnly = false)
public void delete(Car1 car1) {
super.delete(car1);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.service.TreeService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.treetable.dialog.entity.CarKind1;
import com.jeeplus.modules.test.treetable.dialog.mapper.CarKind1Mapper;
/**
* 车系Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class CarKind1Service extends TreeService<CarKind1Mapper, CarKind1> {
public CarKind1 get(String id) {
return super.get(id);
}
public List<CarKind1> findList(CarKind1 carKind1) {
if (StringUtils.isNotBlank(carKind1.getParentIds())){
carKind1.setParentIds(","+carKind1.getParentIds()+",");
}
return super.findList(carKind1);
}
@Transactional(readOnly = false)
public void save(CarKind1 carKind1) {
super.save(carKind1);
}
@Transactional(readOnly = false)
public void delete(CarKind1 carKind1) {
super.delete(carKind1);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.treetable.dialog.entity.Car1;
import com.jeeplus.modules.test.treetable.dialog.service.Car1Service;
/**
* 车辆Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/treetable/dialog/car1")
public class Car1Controller extends BaseController {
@Autowired
private Car1Service car1Service;
@ModelAttribute
public Car1 get(@RequestParam(required=false) String id) {
Car1 entity = null;
if (StringUtils.isNotBlank(id)){
entity = car1Service.get(id);
}
if (entity == null){
entity = new Car1();
}
return entity;
}
/**
* 车辆列表页面
*/
@RequiresPermissions("test:treetable:dialog:car1:list")
@RequestMapping(value = {"list", ""})
public String list(Car1 car1, Model model) {
model.addAttribute("car1", car1);
return "modules/test/treetable/dialog/car1List";
}
/**
* 车辆列表数据
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:list")
@RequestMapping(value = "data")
public Map<String, Object> data(Car1 car1, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Car1> page = car1Service.findPage(new Page<Car1>(request, response), car1);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑车辆表单页面
*/
@RequiresPermissions(value={"test:treetable:dialog:car1:view","test:treetable:dialog:car1:add","test:treetable:dialog:car1:edit"},logical=Logical.OR)
@RequestMapping(value = "form")
public String form(Car1 car1, Model model) {
model.addAttribute("car1", car1);
return "modules/test/treetable/dialog/car1Form";
}
/**
* 保存车辆
*/
@ResponseBody
@RequiresPermissions(value={"test:treetable:dialog:car1:add","test:treetable:dialog:car1:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Car1 car1, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(car1);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
car1Service.save(car1);//保存
j.setSuccess(true);
j.setMsg("保存车辆成功");
return j;
}
/**
* 删除车辆
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Car1 car1) {
AjaxJson j = new AjaxJson();
car1Service.delete(car1);
j.setMsg("删除车辆成功");
return j;
}
/**
* 批量删除车辆
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
car1Service.delete(car1Service.get(id));
}
j.setMsg("删除车辆成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(Car1 car1, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "车辆"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<Car1> page = car1Service.findPage(new Page<Car1>(request, response, -1), car1);
new ExportExcel("车辆", Car1.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出车辆记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<Car1> list = ei.getDataList(Car1.class);
for (Car1 car1 : list){
try{
car1Service.save(car1);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条车辆记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条车辆记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入车辆失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入车辆数据模板
*/
@ResponseBody
@RequiresPermissions("test:treetable:dialog:car1:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "车辆数据导入模板.xlsx";
List<Car1> list = Lists.newArrayList();
new ExportExcel("车辆数据", Car1.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.dialog.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.treetable.dialog.entity.CarKind1;
import com.jeeplus.modules.test.treetable.dialog.service.CarKind1Service;
/**
* 车系Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/treetable/dialog/carKind1")
public class CarKind1Controller extends BaseController {
@Autowired
private CarKind1Service carKind1Service;
@ModelAttribute
public CarKind1 get(@RequestParam(required=false) String id) {
CarKind1 entity = null;
if (StringUtils.isNotBlank(id)){
entity = carKind1Service.get(id);
}
if (entity == null){
entity = new CarKind1();
}
return entity;
}
/**
* 车系列表页面
*/
@RequestMapping(value = {"list", ""})
public String list(CarKind1 carKind1, HttpServletRequest request, HttpServletResponse response, Model model) {
return "modules/test/treetable/dialog/carKind1List";
}
/**
* 查看,增加,编辑车系表单页面
*/
@RequestMapping(value = "form")
public String form(CarKind1 carKind1, Model model) {
if (carKind1.getParent()!=null && StringUtils.isNotBlank(carKind1.getParent().getId())){
carKind1.setParent(carKind1Service.get(carKind1.getParent().getId()));
// 获取排序号,最末节点排序号+30
if (StringUtils.isBlank(carKind1.getId())){
CarKind1 carKind1Child = new CarKind1();
carKind1Child.setParent(new CarKind1(carKind1.getParent().getId()));
List<CarKind1> list = carKind1Service.findList(carKind1);
if (list.size() > 0){
carKind1.setSort(list.get(list.size()-1).getSort());
if (carKind1.getSort() != null){
carKind1.setSort(carKind1.getSort() + 30);
}
}
}
}
if (carKind1.getSort() == null){
carKind1.setSort(30);
}
model.addAttribute("carKind1", carKind1);
return "modules/test/treetable/dialog/carKind1Form";
}
/**
* 保存车系
*/
@ResponseBody
@RequestMapping(value = "save")
public AjaxJson save(CarKind1 carKind1, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(carKind1);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
carKind1Service.save(carKind1);//保存
j.setSuccess(true);
j.put("carKind1", carKind1);
j.setMsg("保存车系成功");
return j;
}
@ResponseBody
@RequestMapping(value = "getChildren")
public List<CarKind1> getChildren(String parentId){
if("-1".equals(parentId)){//如果是-1,没指定任何父节点,就从根节点开始查找
parentId = "0";
}
return carKind1Service.getChildren(parentId);
}
/**
* 删除车系
*/
@ResponseBody
@RequestMapping(value = "delete")
public AjaxJson delete(CarKind1 carKind1) {
AjaxJson j = new AjaxJson();
carKind1Service.delete(carKind1);
j.setSuccess(true);
j.setMsg("删除车系成功");
return j;
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
List<CarKind1> list = carKind1Service.findList(new CarKind1());
for (int i=0; i<list.size(); i++){
CarKind1 e = list.get(i);
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("text", e.getName());
if(StringUtils.isBlank(e.getParentId()) || "0".equals(e.getParentId())){
map.put("parent", "#");
Map<String, Object> state = Maps.newHashMap();
state.put("opened", true);
map.put("state", state);
}else{
map.put("parent", e.getParentId());
}
mapList.add(map);
}
}
return mapList;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.entity;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 车辆Entity
* @author lgf
* @version 2018-06-12
*/
public class Car2 extends DataEntity<Car2> {
private static final long serialVersionUID = 1L;
private String name; // 品牌
private CarKind2 kind; // 车系 父类
public Car2() {
super();
}
public Car2(String id){
super(id);
}
public Car2(CarKind2 kind){
this.kind = kind;
}
@ExcelField(title="品牌", align=2, sort=1)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public CarKind2 getKind() {
return kind;
}
public void setKind(CarKind2 kind) {
this.kind = kind;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.entity;
import javax.validation.constraints.NotNull;
import com.fasterxml.jackson.annotation.JsonBackReference;
import java.util.List;
import com.google.common.collect.Lists;
import com.jeeplus.core.persistence.TreeEntity;
/**
* 车系Entity
* @author lgf
* @version 2018-06-12
*/
public class CarKind2 extends TreeEntity<CarKind2> {
private static final long serialVersionUID = 1L;
private List<Car2> car2List = Lists.newArrayList(); // 子表列表
public CarKind2() {
super();
}
public CarKind2(String id){
super(id);
}
public CarKind2 getParent() {
return parent;
}
@Override
public void setParent(CarKind2 parent) {
this.parent = parent;
}
public List<Car2> getCar2List() {
return car2List;
}
public void setCar2List(List<Car2> car2List) {
this.car2List = car2List;
}
public String getParentId() {
return parent != null && parent.getId() != null ? parent.getId() : "0";
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.treetable.form.entity.Car2;
/**
* 车辆MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface Car2Mapper extends BaseMapper<Car2> {
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.mapper;
import com.jeeplus.core.persistence.TreeMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.treetable.form.entity.CarKind2;
/**
* 车系MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface CarKind2Mapper extends TreeMapper<CarKind2> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.treetable.form.mapper.Car2Mapper">
<sql id="car2Columns">
a.id AS "id",
a.name AS "name",
a.kind_id AS "kind.id",
a.del_flag AS "delFlag",
a.remarks AS "remarks",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
b.name AS "kind.name"
</sql>
<sql id="car2Joins">
LEFT JOIN test_car_kind b ON b.id = a.kind_id
</sql>
<select id="get" resultType="Car2" >
SELECT
<include refid="car2Columns"/>
FROM test_car a
<include refid="car2Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Car2" >
SELECT
<include refid="car2Columns"/>
FROM test_car a
<include refid="car2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="kind != null and kind.id != null and kind.id != ''">
AND (b.id = #{kind.id} OR b.parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{kind.id}||',%')</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{kind.id}, ',%'))</if>
<if test="dbName == 'mssql'">'%'+#{kind.id}+'%')</if>
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Car2" >
SELECT
<include refid="car2Columns"/>
FROM test_car a
<include refid="car2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.create_date ASC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_car(
id,
name,
kind_id,
del_flag,
remarks,
create_by,
create_date,
update_by,
update_date
) VALUES (
#{id},
#{name},
#{kind.id},
#{delFlag},
#{remarks},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate}
)
</insert>
<update id="update">
UPDATE test_car SET
name = #{name},
kind_id = #{kind.id},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_car
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE kind_id = #{kind.id}
</otherwise>
</choose>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_car SET
del_flag = #{DEL_FLAG_DELETE}
<choose>
<when test="id !=null and id != ''">
WHERE id = #{id}
</when>
<otherwise>
WHERE kind_id = #{kind.id}
</otherwise>
</choose>
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Car2" statementType="STATEMENT">
select * FROM test_car where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.treetable.form.mapper.CarKind2Mapper">
<resultMap id="carKind2Result" type="CarKind2">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="sort" column="sort" />
<result property="parentIds" column="parentIds" />
<association property="hasChildren" column="id" select="hasChildren" />
</resultMap>
<sql id="carKind2Columns">
a.id AS "id",
a.name AS "name",
a.sort AS "sort",
a.remarks AS "remarks",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.del_flag AS "delFlag",
a.parent_id AS "parent.id",
a.parent_ids AS "parentIds"
</sql>
<sql id="carKind2Joins">
</sql>
<select id="get" resultType="CarKind2">
SELECT
<include refid="carKind2Columns"/>
FROM test_car_kind a
<include refid="carKind2Joins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="CarKind2">
SELECT
<include refid="carKind2Columns"/>
FROM test_car_kind a
<include refid="carKind2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="name != null and name != ''">
AND a.name LIKE
<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
</if>
<if test="parent != null and parent.id != null and parent.id != ''">
AND a.parent_id = #{parent.id}
</if>
<if test="parentIds != null and parentIds != ''">
AND a.parent_ids LIKE
<if test="dbName == 'oracle'">'%'||#{parentIds}||'%'</if>
<if test="dbName == 'mssql'">'%'+#{parentIds}+'%'</if>
<if test="dbName == 'mysql'">concat('%',#{parentIds},'%')</if>
</if>
</where>
ORDER BY a.sort ASC
</select>
<select id="findAllList" resultType="CarKind2">
SELECT
<include refid="carKind2Columns"/>
FROM test_car_kind a
<include refid="carKind2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
ORDER BY a.sort ASC
</select>
<select id="getChildren" parameterType="String" resultMap="carKind2Result">
select * from test_car_kind where parent_id = #{id} ORDER BY sort
</select>
<select id="hasChildren" parameterType="String" resultType="Boolean">
select case when exists(select 1 from test_car_kind where parent_id = #{id}) then 1 else 0 end ${dual}
</select>
<select id="findByParentIdsLike" resultType="CarKind2">
SELECT
a.id,
a.parent_id AS "parent.id",
a.parent_ids
FROM test_car_kind a
<include refid="carKind2Joins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
AND a.parent_ids LIKE #{parentIds}
</where>
ORDER BY a.sort ASC
</select>
<insert id="insert">
INSERT INTO test_car_kind(
id,
name,
sort,
remarks,
create_by,
create_date,
update_by,
update_date,
del_flag,
parent_id,
parent_ids
) VALUES (
#{id},
#{name},
#{sort},
#{remarks},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{delFlag},
#{parent.id},
#{parentIds}
)
</insert>
<update id="update">
UPDATE test_car_kind SET
name = #{name},
sort = #{sort},
remarks = #{remarks},
update_by = #{updateBy.id},
update_date = #{updateDate},
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<update id="updateParentIds">
UPDATE test_car_kind SET
parent_id = #{parent.id},
parent_ids = #{parentIds}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_car_kind
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_car_kind SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id} OR parent_ids LIKE
<if test="dbName == 'oracle'">'%,'||#{id}||',%'</if>
<if test="dbName == 'mssql'">'%,'+#{id}+',%'</if>
<if test="dbName == 'mysql'">CONCAT('%,', #{id}, ',%')</if>
</update>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.treetable.form.entity.Car2;
import com.jeeplus.modules.test.treetable.form.mapper.Car2Mapper;
/**
* 车辆Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class Car2Service extends CrudService<Car2Mapper, Car2> {
public Car2 get(String id) {
return super.get(id);
}
public List<Car2> findList(Car2 car2) {
return super.findList(car2);
}
public Page<Car2> findPage(Page<Car2> page, Car2 car2) {
return super.findPage(page, car2);
}
@Transactional(readOnly = false)
public void save(Car2 car2) {
super.save(car2);
}
@Transactional(readOnly = false)
public void delete(Car2 car2) {
super.delete(car2);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.service.TreeService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.treetable.form.entity.CarKind2;
import com.jeeplus.modules.test.treetable.form.mapper.CarKind2Mapper;
/**
* 车系Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class CarKind2Service extends TreeService<CarKind2Mapper, CarKind2> {
public CarKind2 get(String id) {
return super.get(id);
}
public List<CarKind2> findList(CarKind2 carKind2) {
if (StringUtils.isNotBlank(carKind2.getParentIds())){
carKind2.setParentIds(","+carKind2.getParentIds()+",");
}
return super.findList(carKind2);
}
@Transactional(readOnly = false)
public void save(CarKind2 carKind2) {
super.save(carKind2);
}
@Transactional(readOnly = false)
public void delete(CarKind2 carKind2) {
super.delete(carKind2);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.treetable.form.entity.Car2;
import com.jeeplus.modules.test.treetable.form.service.Car2Service;
/**
* 车辆Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/treetable/form/car2")
public class Car2Controller extends BaseController {
@Autowired
private Car2Service car2Service;
@ModelAttribute
public Car2 get(@RequestParam(required=false) String id) {
Car2 entity = null;
if (StringUtils.isNotBlank(id)){
entity = car2Service.get(id);
}
if (entity == null){
entity = new Car2();
}
return entity;
}
/**
* 车辆列表页面
*/
@RequiresPermissions("test:treetable:form:car2:list")
@RequestMapping(value = {"list", ""})
public String list(Car2 car2, Model model) {
model.addAttribute("car2", car2);
return "modules/test/treetable/form/car2List";
}
/**
* 车辆列表数据
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:list")
@RequestMapping(value = "data")
public Map<String, Object> data(Car2 car2, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Car2> page = car2Service.findPage(new Page<Car2>(request, response), car2);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑车辆表单页面
*/
@RequiresPermissions(value={"test:treetable:form:car2:view","test:treetable:form:car2:add","test:treetable:form:car2:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, Car2 car2, Model model) {
model.addAttribute("car2", car2);
model.addAttribute("mode", mode);
return "modules/test/treetable/form/car2Form";
}
/**
* 保存车辆
*/
@ResponseBody
@RequiresPermissions(value={"test:treetable:form:car2:add","test:treetable:form:car2:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Car2 car2, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(car2);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
car2Service.save(car2);//保存
j.setSuccess(true);
j.setMsg("保存车辆成功");
return j;
}
/**
* 删除车辆
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Car2 car2) {
AjaxJson j = new AjaxJson();
car2Service.delete(car2);
j.setMsg("删除车辆成功");
return j;
}
/**
* 批量删除车辆
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
car2Service.delete(car2Service.get(id));
}
j.setMsg("删除车辆成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(Car2 car2, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "车辆"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<Car2> page = car2Service.findPage(new Page<Car2>(request, response, -1), car2);
new ExportExcel("车辆", Car2.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出车辆记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<Car2> list = ei.getDataList(Car2.class);
for (Car2 car2 : list){
try{
car2Service.save(car2);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条车辆记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条车辆记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入车辆失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入车辆数据模板
*/
@ResponseBody
@RequiresPermissions("test:treetable:form:car2:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "车辆数据导入模板.xlsx";
List<Car2> list = Lists.newArrayList();
new ExportExcel("车辆数据", Car2.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.treetable.form.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.config.Global;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.treetable.form.entity.CarKind2;
import com.jeeplus.modules.test.treetable.form.service.CarKind2Service;
/**
* 车系Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/treetable/form/carKind2")
public class CarKind2Controller extends BaseController {
@Autowired
private CarKind2Service carKind2Service;
@ModelAttribute
public CarKind2 get(@RequestParam(required=false) String id) {
CarKind2 entity = null;
if (StringUtils.isNotBlank(id)){
entity = carKind2Service.get(id);
}
if (entity == null){
entity = new CarKind2();
}
return entity;
}
/**
* 车系列表页面
*/
@RequestMapping(value = {"list", ""})
public String list(CarKind2 carKind2, HttpServletRequest request, HttpServletResponse response, Model model) {
return "modules/test/treetable/form/carKind2List";
}
/**
* 查看,增加,编辑车系表单页面
*/
@RequestMapping(value = "form")
public String form(CarKind2 carKind2, Model model) {
if (carKind2.getParent()!=null && StringUtils.isNotBlank(carKind2.getParent().getId())){
carKind2.setParent(carKind2Service.get(carKind2.getParent().getId()));
// 获取排序号,最末节点排序号+30
if (StringUtils.isBlank(carKind2.getId())){
CarKind2 carKind2Child = new CarKind2();
carKind2Child.setParent(new CarKind2(carKind2.getParent().getId()));
List<CarKind2> list = carKind2Service.findList(carKind2);
if (list.size() > 0){
carKind2.setSort(list.get(list.size()-1).getSort());
if (carKind2.getSort() != null){
carKind2.setSort(carKind2.getSort() + 30);
}
}
}
}
if (carKind2.getSort() == null){
carKind2.setSort(30);
}
model.addAttribute("carKind2", carKind2);
return "modules/test/treetable/form/carKind2Form";
}
/**
* 保存车系
*/
@ResponseBody
@RequestMapping(value = "save")
public AjaxJson save(CarKind2 carKind2, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(carKind2);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
carKind2Service.save(carKind2);//保存
j.setSuccess(true);
j.put("carKind2", carKind2);
j.setMsg("保存车系成功");
return j;
}
@ResponseBody
@RequestMapping(value = "getChildren")
public List<CarKind2> getChildren(String parentId){
if("-1".equals(parentId)){//如果是-1,没指定任何父节点,就从根节点开始查找
parentId = "0";
}
return carKind2Service.getChildren(parentId);
}
/**
* 删除车系
*/
@ResponseBody
@RequestMapping(value = "delete")
public AjaxJson delete(CarKind2 carKind2) {
AjaxJson j = new AjaxJson();
carKind2Service.delete(carKind2);
j.setSuccess(true);
j.setMsg("删除车系成功");
return j;
}
@RequiresPermissions("user")
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
List<Map<String, Object>> mapList = Lists.newArrayList();
List<CarKind2> list = carKind2Service.findList(new CarKind2());
for (int i=0; i<list.size(); i++){
CarKind2 e = list.get(i);
if (StringUtils.isBlank(extId) || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("text", e.getName());
if(StringUtils.isBlank(e.getParentId()) || "0".equals(e.getParentId())){
map.put("parent", "#");
Map<String, Object> state = Maps.newHashMap();
state.put("opened", true);
map.put("state", state);
}else{
map.put("parent", e.getParentId());
}
mapList.add(map);
}
}
return mapList;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.validation.entity;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Min;
import javax.validation.constraints.Max;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.URL;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
/**
* 测试校验功能Entity
* @author lgf
* @version 2018-06-12
*/
public class TestValidation extends DataEntity<TestValidation> {
private static final long serialVersionUID = 1L;
private Double num; // 浮点数字
private Integer num2; // 整数
private String str; // 字符串
private String email; // 邮件
private String url; // 网址
private Date newDate; // 日期
private String c1; // 浮点数小于等于0
private String c2; // 身份证号码
private String c3; // QQ号码
private String c4; // 手机号码
private String c5; // 中英文数字下划线
private String c6; // 合法字符(a-z A-Z 0-9)
private String en; // 英语
private String zn; // 汉子
private String enzn; // 汉英字符
public TestValidation() {
super();
}
public TestValidation(String id){
super(id);
}
@NotNull(message="浮点数字不能为空")
@Min(value=(long)20.1,message="浮点数字的最小值不能小于20.1")
@Max(value=(long)69.3,message="浮点数字的最大值不能超过69.3")
@ExcelField(title="浮点数字", align=2, sort=1)
public Double getNum() {
return num;
}
public void setNum(Double num) {
this.num = num;
}
@NotNull(message="整数不能为空")
@Min(value=10,message="整数的最小值不能小于10")
@Max(value=30,message="整数的最大值不能超过30")
@ExcelField(title="整数", align=2, sort=2)
public Integer getNum2() {
return num2;
}
public void setNum2(Integer num2) {
this.num2 = num2;
}
@Length(min=5, max=65, message="字符串长度必须介于 5 和 65 之间")
@ExcelField(title="字符串", align=2, sort=3)
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
@Length(min=10, max=60, message="邮件长度必须介于 10 和 60 之间")
@Email(message="邮件必须为合法邮箱")
@ExcelField(title="邮件", align=2, sort=4)
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Length(min=10, max=30, message="网址长度必须介于 10 和 30 之间")
@URL(message="网址必须为合法网址")
@ExcelField(title="网址", align=2, sort=5)
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@NotNull(message="日期不能为空")
@ExcelField(title="日期", align=2, sort=6)
public Date getNewDate() {
return newDate;
}
public void setNewDate(Date newDate) {
this.newDate = newDate;
}
@ExcelField(title="浮点数小于等于0", align=2, sort=8)
public String getC1() {
return c1;
}
public void setC1(String c1) {
this.c1 = c1;
}
@ExcelField(title="身份证号码", align=2, sort=9)
public String getC2() {
return c2;
}
public void setC2(String c2) {
this.c2 = c2;
}
@ExcelField(title="QQ号码", align=2, sort=10)
public String getC3() {
return c3;
}
public void setC3(String c3) {
this.c3 = c3;
}
@ExcelField(title="手机号码", align=2, sort=11)
public String getC4() {
return c4;
}
public void setC4(String c4) {
this.c4 = c4;
}
@ExcelField(title="中英文数字下划线", align=2, sort=12)
public String getC5() {
return c5;
}
public void setC5(String c5) {
this.c5 = c5;
}
@ExcelField(title="合法字符(a-z A-Z 0-9)", align=2, sort=13)
public String getC6() {
return c6;
}
public void setC6(String c6) {
this.c6 = c6;
}
@ExcelField(title="英语", align=2, sort=14)
public String getEn() {
return en;
}
public void setEn(String en) {
this.en = en;
}
@ExcelField(title="汉子", align=2, sort=15)
public String getZn() {
return zn;
}
public void setZn(String zn) {
this.zn = zn;
}
@ExcelField(title="汉英字符", align=2, sort=16)
public String getEnzn() {
return enzn;
}
public void setEnzn(String enzn) {
this.enzn = enzn;
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.validation.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.test.validation.entity.TestValidation;
/**
* 测试校验功能MAPPER接口
* @author lgf
* @version 2018-06-12
*/
@MyBatisMapper
public interface TestValidationMapper extends BaseMapper<TestValidation> {
}
\ No newline at end of file
<?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">
<mapper namespace="com.jeeplus.modules.test.validation.mapper.TestValidationMapper">
<sql id="testValidationColumns">
a.id AS "id",
a.num AS "num",
a.num2 AS "num2",
a.str AS "str",
a.email AS "email",
a.url AS "url",
a.new_date AS "newDate",
a.remarks AS "remarks",
a.c1 AS "c1",
a.c2 AS "c2",
a.c3 AS "c3",
a.c4 AS "c4",
a.c5 AS "c5",
a.c6 AS "c6",
a.en AS "en",
a.zn AS "zn",
a.enzn AS "enzn"
</sql>
<sql id="testValidationJoins">
</sql>
<select id="get" resultType="TestValidation" >
SELECT
<include refid="testValidationColumns"/>
FROM test_validation a
<include refid="testValidationJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="TestValidation" >
SELECT
<include refid="testValidationColumns"/>
FROM test_validation a
<include refid="testValidationJoins"/>
<where>
${dataScope}
<if test="num != null and num != ''">
AND a.num = #{num}
</if>
<if test="num2 != null and num2 != ''">
AND a.num2 = #{num2}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="TestValidation" >
SELECT
<include refid="testValidationColumns"/>
FROM test_validation a
<include refid="testValidationJoins"/>
<where>
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO test_validation(
id,
num,
num2,
str,
email,
url,
new_date,
remarks,
c1,
c2,
c3,
c4,
c5,
c6,
en,
zn,
enzn
) VALUES (
#{id},
#{num},
#{num2},
#{str},
#{email},
#{url},
#{newDate},
#{remarks},
#{c1},
#{c2},
#{c3},
#{c4},
#{c5},
#{c6},
#{en},
#{zn},
#{enzn}
)
</insert>
<update id="update">
UPDATE test_validation SET
num = #{num},
num2 = #{num2},
str = #{str},
email = #{email},
url = #{url},
new_date = #{newDate},
remarks = #{remarks},
c1 = #{c1},
c2 = #{c2},
c3 = #{c3},
c4 = #{c4},
c5 = #{c5},
c6 = #{c6},
en = #{en},
zn = #{zn},
enzn = #{enzn}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM test_validation
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE test_validation SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="TestValidation" statementType="STATEMENT">
select * FROM test_validation where ${propertyName} = '${value}'
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.validation.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.test.validation.entity.TestValidation;
import com.jeeplus.modules.test.validation.mapper.TestValidationMapper;
/**
* 测试校验功能Service
* @author lgf
* @version 2018-06-12
*/
@Service
@Transactional(readOnly = true)
public class TestValidationService extends CrudService<TestValidationMapper, TestValidation> {
public TestValidation get(String id) {
return super.get(id);
}
public List<TestValidation> findList(TestValidation testValidation) {
return super.findList(testValidation);
}
public Page<TestValidation> findPage(Page<TestValidation> page, TestValidation testValidation) {
return super.findPage(page, testValidation);
}
@Transactional(readOnly = false)
public void save(TestValidation testValidation) {
super.save(testValidation);
}
@Transactional(readOnly = false)
public void delete(TestValidation testValidation) {
super.delete(testValidation);
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.test.validation.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.test.validation.entity.TestValidation;
import com.jeeplus.modules.test.validation.service.TestValidationService;
/**
* 测试校验功能Controller
* @author lgf
* @version 2018-06-12
*/
@Controller
@RequestMapping(value = "${adminPath}/test/validation/testValidation")
public class TestValidationController extends BaseController {
@Autowired
private TestValidationService testValidationService;
@ModelAttribute
public TestValidation get(@RequestParam(required=false) String id) {
TestValidation entity = null;
if (StringUtils.isNotBlank(id)){
entity = testValidationService.get(id);
}
if (entity == null){
entity = new TestValidation();
}
return entity;
}
/**
* 测试校验列表页面
*/
@RequiresPermissions("test:validation:testValidation:list")
@RequestMapping(value = {"list", ""})
public String list(TestValidation testValidation, Model model) {
model.addAttribute("testValidation", testValidation);
return "modules/test/validation/testValidationList";
}
/**
* 测试校验列表数据
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:list")
@RequestMapping(value = "data")
public Map<String, Object> data(TestValidation testValidation, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<TestValidation> page = testValidationService.findPage(new Page<TestValidation>(request, response), testValidation);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑测试校验表单页面
*/
@RequiresPermissions(value={"test:validation:testValidation:view","test:validation:testValidation:add","test:validation:testValidation:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, TestValidation testValidation, Model model) {
model.addAttribute("testValidation", testValidation);
model.addAttribute("mode", mode);
return "modules/test/validation/testValidationForm";
}
/**
* 保存测试校验
*/
@ResponseBody
@RequiresPermissions(value={"test:validation:testValidation:add","test:validation:testValidation:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(TestValidation testValidation, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(testValidation);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
testValidationService.save(testValidation);//保存
j.setSuccess(true);
j.setMsg("保存测试校验成功");
return j;
}
/**
* 删除测试校验
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:del")
@RequestMapping(value = "delete")
public AjaxJson delete(TestValidation testValidation) {
AjaxJson j = new AjaxJson();
testValidationService.delete(testValidation);
j.setMsg("删除测试校验成功");
return j;
}
/**
* 批量删除测试校验
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
testValidationService.delete(testValidationService.get(id));
}
j.setMsg("删除测试校验成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(TestValidation testValidation, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "测试校验"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<TestValidation> page = testValidationService.findPage(new Page<TestValidation>(request, response, -1), testValidation);
new ExportExcel("测试校验", TestValidation.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出测试校验记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<TestValidation> list = ei.getDataList(TestValidation.class);
for (TestValidation testValidation : list){
try{
testValidationService.save(testValidation);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条测试校验记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条测试校验记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入测试校验失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入测试校验数据模板
*/
@ResponseBody
@RequiresPermissions("test:validation:testValidation:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "测试校验数据导入模板.xlsx";
List<TestValidation> list = Lists.newArrayList();
new ExportExcel("测试校验数据", TestValidation.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment