1. 程式人生 > >納稅服務投訴受理模組中投訴與回覆中的級聯查詢等細節

納稅服務投訴受理模組中投訴與回覆中的級聯查詢等細節

1、投訴和投訴回覆實體及hbm配置檔案

Complain.java

package cn.buaa.nsfw.complain.entity;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Complain entity. @author MyEclipse Persistence Tools
 */

public class Complain implements java.io.Serializable {

	// Fields

	private String compId;
	private String compCompany;
	private String compName;
	private String compMobile;
	private Boolean isNm;
	private Timestamp compTime;
	private String compTitle;
	private String toCompName;
	private String toCompDept;
	private String compContent;
	private String state;
	private Set complainReplies = new HashSet(0);

	//狀態
	//待受理
	public static String COMPLAIN_STATE_UNDONE = "0";
	//已受理
	public static String COMPLAIN_STATE_DONE = "1";
	//已失效
	public static String COMPLAIN_STATE_INVALID = "2";
	public static Map<String,String> COMPLAIN_STATE_MAP;
	static {
		COMPLAIN_STATE_MAP = new HashMap<String,String>();
		COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_UNDONE, "待受理");
		COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_DONE, "已受理");
		COMPLAIN_STATE_MAP.put(COMPLAIN_STATE_INVALID, "已失效");
	}
	// Constructors

	/** default constructor */
	public Complain() {
	}

	/** minimal constructor */
	public Complain(String compTitle) {
		this.compTitle = compTitle;
	}

	/** full constructor */
	public Complain(String compCompany, String compName, String compMobile, Boolean isNm, Timestamp compTime, String compTitle,
			String toCompName, String toCompDept, String compContent, String state, Set complainReplies) {
		this.compCompany = compCompany;
		this.compName = compName;
		this.compMobile = compMobile;
		this.isNm = isNm;
		this.compTime = compTime;
		this.compTitle = compTitle;
		this.toCompName = toCompName;
		this.toCompDept = toCompDept;
		this.compContent = compContent;
		this.state = state;
		this.complainReplies = complainReplies;
	}

	// Property accessors

	public String getCompId() {
		return this.compId;
	}

	public void setCompId(String compId) {
		this.compId = compId;
	}

	public String getCompCompany() {
		return this.compCompany;
	}

	public void setCompCompany(String compCompany) {
		this.compCompany = compCompany;
	}

	public String getCompName() {
		return this.compName;
	}

	public void setCompName(String compName) {
		this.compName = compName;
	}

	public String getCompMobile() {
		return this.compMobile;
	}

	public void setCompMobile(String compMobile) {
		this.compMobile = compMobile;
	}

	public Boolean getIsNm() {
		return this.isNm;
	}

	public void setIsNm(Boolean isNm) {
		this.isNm = isNm;
	}

	public Timestamp getCompTime() {
		return this.compTime;
	}

	public void setCompTime(Timestamp compTime) {
		this.compTime = compTime;
	}

	public String getCompTitle() {
		return this.compTitle;
	}

	public void setCompTitle(String compTitle) {
		this.compTitle = compTitle;
	}

	public String getToCompName() {
		return this.toCompName;
	}

	public void setToCompName(String toCompName) {
		this.toCompName = toCompName;
	}

	public String getToCompDept() {
		return this.toCompDept;
	}

	public void setToCompDept(String toCompDept) {
		this.toCompDept = toCompDept;
	}

	public String getCompContent() {
		return this.compContent;
	}

	public void setCompContent(String compContent) {
		this.compContent = compContent;
	}

	public String getState() {
		return this.state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public Set getComplainReplies() {
		return this.complainReplies;
	}

	public void setComplainReplies(Set complainReplies) {
		this.complainReplies = complainReplies;
	}

}
Complain.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="cn.buaa.nsfw.complain.entity.Complain" table="complain" >
        <id name="compId" type="java.lang.String">
            <column name="comp_id" length="32" />
            <generator class="uuid.hex" />
        </id>
        <property name="compCompany" type="java.lang.String">
            <column name="comp_company" length="100" />
        </property>
        <property name="compName" type="java.lang.String">
            <column name="comp_name" length="20" />
        </property>
        <property name="compMobile" type="java.lang.String">
            <column name="comp_mobile" length="20" />
        </property>
        <property name="isNm" type="java.lang.Boolean">
            <column name="is_NM" />
        </property>
        <property name="compTime" type="java.sql.Timestamp">
            <column name="comp_time" length="19" />
        </property>
        <property name="compTitle" type="java.lang.String">
            <column name="comp_title" length="200" not-null="true" />
        </property>
        <property name="toCompName" type="java.lang.String">
            <column name="to_comp_name" length="20" />
        </property>
        <property name="toCompDept" type="java.lang.String">
            <column name="to_comp_dept" length="100" />
        </property>
        <property name="compContent" type="text">
            <column name="comp_content"/>
        </property>
        <property name="state" type="java.lang.String">
            <column name="state" length="1" />
        </property>
        <set name="complainReplies" inverse="true" cascade="save-update,delete" lazy="false" order-by="reply_time">
            <key>
                <column name="comp_id" length="32" not-null="true" />
            </key>
            <one-to-many class="cn.buaa.nsfw.complain.entity.ComplainReply" />
        </set>
    </class>
</hibernate-mapping>
注意,<set>中有個 order-by="reply_time"屬性,可以使set按資料庫中某個欄位,或者實體中某個屬性排序,還可以設定desc 或asc

ComplainReply.java

package cn.buaa.nsfw.complain.entity;

import java.sql.Timestamp;

/**
 * ComplainReply entity. @author MyEclipse Persistence Tools
 */

public class ComplainReply implements java.io.Serializable {

	// Fields

	private String replyId;
	private Complain complain;
	private String replyer;
	private String replyDept;
	private Timestamp replyTime;
	private String replyContent;

	// Constructors

	/** default constructor */
	public ComplainReply() {
	}

	/** minimal constructor */
	public ComplainReply(Complain complain) {
		this.complain = complain;
	}

	/** full constructor */
	public ComplainReply(Complain complain, String replyer, String replyDept, Timestamp replyTime, String replyContent) {
		this.complain = complain;
		this.replyer = replyer;
		this.replyDept = replyDept;
		this.replyTime = replyTime;
		this.replyContent = replyContent;
	}

	// Property accessors

	public String getReplyId() {
		return this.replyId;
	}

	public void setReplyId(String replyId) {
		this.replyId = replyId;
	}

	public Complain getComplain() {
		return this.complain;
	}

	public void setComplain(Complain complain) {
		this.complain = complain;
	}

	public String getReplyer() {
		return this.replyer;
	}

	public void setReplyer(String replyer) {
		this.replyer = replyer;
	}

	public String getReplyDept() {
		return this.replyDept;
	}

	public void setReplyDept(String replyDept) {
		this.replyDept = replyDept;
	}

	public Timestamp getReplyTime() {
		return replyTime;
	}

	public void setReplyTime(Timestamp replyTime) {
		this.replyTime = replyTime;
	}

	public String getReplyContent() {
		return this.replyContent;
	}

	public void setReplyContent(String replyContent) {
		this.replyContent = replyContent;
	}

}
ComplainReply.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="cn.buaa.nsfw.complain.entity.ComplainReply" table="complain_reply" >
        <id name="replyId" type="java.lang.String">
            <column name="reply_id" length="32" />
            <generator class="uuid.hex" />
        </id>
        <many-to-one name="complain" class="cn.buaa.nsfw.complain.entity.Complain" fetch="select">
            <column name="comp_id" length="32" not-null="true" />
        </many-to-one>
        <property name="replyer" type="java.lang.String">
            <column name="replyer" length="20" />
        </property>
        <property name="replyDept" type="java.lang.String">
            <column name="reply_dept" length="100" />
        </property>
        <property name="replyTime" type="java.sql.Timestamp">
            <column name="reply_time" length="19" />
        </property>
        <property name="replyContent" type="java.lang.String">
            <column name="reply_content" length="300" />
        </property>
    </class>
</hibernate-mapping>

2、action中對級聯查詢的操作
//儲存回覆處理結果
	public String deal(){
		if(complain != null){
			Complain tem = complainService.findObjectById(complain.getCompId());
			//1、更新投訴的狀態為已受理
			if(!Complain.COMPLAIN_STATE_DONE.equals(tem.getState())){ //更新狀態為已受理
				tem.setState(Complain.COMPLAIN_STATE_DONE);
			}
			//2、儲存回覆資訊
			if(reply != null){
				reply.setComplain(tem);
				reply.setReplyTime(new Timestamp(new Date().getTime()));
				tem.getComplainReplies().add(reply);
			}
			complainService.update(tem);
		}
		return "list";
	}

3、jsp頁面
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<%@include file="/common/header.jsp"%>
<title>使用者管理</title>
<!--   引入日曆外掛-->
<script type="text/javascript" src="${basePath}js/datepicker/WdatePicker.js"></script>
<script type="text/javascript">
	var vResult = false;
	function doVerify() {
		//1.獲取賬號
		var account = $("#account").val();
		if (account != "") {
			//2.效驗
			$.ajax({
				url : "${basePath}nsfw/user_verifyAccount.action",
				data : {
					"user.account" : account
				},
				type : "post",
				async : false,//非非同步,主要為了下邊的提交
				success : function(msg) {
					if ("true" != msg) {
						//賬號已經存在
						alert("賬號已經存在,請使用其他賬號!");
						//定焦
						$("#account").focus();
						vResult = false;
					} else {
						vResult = true;
					}
				}
			});
		}
	}
	//2.提交表單
	function doSubmit() {
		var name = $("#name");
		if (name.val() == "") {
			alert("使用者名稱不能為空");
			name.focus();
			return false;
		}
		var password = $("#password");
		if (password.val() == "") {
			alert("密碼不能為空");
			password.focus();
			return false;
		}
		//賬號驗證
		doVerify();
		//表單提交
		if (vResult) {
			document.forms[0].submit();
		}
	}
</script>
</head>
<body class="rightBody">
	<form id="form" name="form" action="${basePath}nsfw/user_add.action" method="post" enctype="multipart/form-data">
		<div class="p_d_1">
			<div class="p_d_1_1">
				<div class="content_info">
					<div class="c_crumbs">
						<div>
							<b></b><strong>使用者管理</strong> - 新增使用者
						</div>
					</div>
					<div class="tableH2">新增使用者</div>
					<table id="baseInfo" width="100%" align="center" class="list" border="0" cellpadding="0" cellspacing="0">
						<tr>
							<td class="tdBg" width="200px">所屬部門:</td>
							<td>
								<s:select name="user.dept" list="#{'部門A':'部門A','部門B':'部門B'}" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">頭像:</td>
							<td>
								<input type="file" name="headImg" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">使用者名稱:</td>
							<td>
								<s:textfield name="user.name" id="name" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">帳號:</td>
							<td>
								<s:textfield name="user.account" id="account" onchange="doVerify()" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">密碼:</td>
							<td>
								<s:textfield name="user.password" id="password" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">性別:</td>
							<td>
								<s:radio list="#{'true':'男','false':'女'}" name="user.gender" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">角色:</td>
							<td>
								<s:checkboxlist list="#roleList" name="userRoleIds" listKey="roleId" listValue="name"></s:checkboxlist>
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">電子郵箱:</td>
							<td>
								<s:textfield name="user.email" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">手機號:</td>
							<td>
								<s:textfield name="user.mobile" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">生日:</td>
							<td>
								<s:textfield id="birthday" name="user.birthday" readonly="true"
									onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd'})" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">狀態:</td>
							<td>
								<s:radio list="#{'1':'有效','0':'無效'}" name="user.state" value="1" />
							</td>
						</tr>
						<tr>
							<td class="tdBg" width="200px">備註:</td>
							<td>
								<s:textarea name="user.memo" cols="75" rows="3" />
							</td>
						</tr>
					</table>
					<div class="tc mt20">
						<input type="button" class="btnB2" value="儲存" onclick="doSubmit()" />
						    
						<input type="button" onclick="javascript:history.go(-1)" class="btnB2" value="返回" />
					</div>
				</div>
			</div>
		</div>
	</form>
</body>
</html>