纳税服务系统七(投诉管理模块)【显示投诉信息、处理回复、我要投诉、Quartz自动受理、统计图FusionCharts】...
投訴受理管理模塊
接下來,就是來開發(fā)我們的投訴受理管理模塊了…..我們來看看原型圖與需求吧:
查詢用戶提交的投訴信息,可以根據(jù)投訴部門(部門A/B)、投訴時間段、狀態(tài)進行查詢。在列表信息中展示投訴標(biāo)題、被投訴部門、被投訴人、投訴時間、狀態(tài)(待受理、已受理、已失效)、操作;其中操作欄內(nèi)內(nèi)容為“處理”,點擊“處理”則在打開的查詢頁面中查看具體的投訴信息并且可以多次回復(fù)投訴信息;一旦回復(fù)則說明已受理該投訴。
投訴詳細信息:在本頁面中首先要明顯地展示出當(dāng)前投訴是否已經(jīng)受理;然后再顯示投訴人信息、被投訴信息、受理信息(歷史受理信息)三部分內(nèi)容,并且在頁面中可以無限次的對本次受理進行回復(fù)。投訴人信息包括:是否匿名投訴、投訴人單位、投訴人姓名、投訴人手機,如果是匿名投訴,則不顯示投訴人單位、姓名并對手機號中間4位號碼使用*號代替。被投訴信息包括:投訴時間、被投訴部門、被投訴人、投訴標(biāo)題、投訴內(nèi)容。受理信息:如果有多次回復(fù)則將多次的回復(fù)信息顯示,顯示內(nèi)容包括回復(fù)時間、回復(fù)部門、回復(fù)人、受理回復(fù)內(nèi)容;可以再次回復(fù)。
這里寫圖片描述這里寫圖片描述根據(jù)上面兩張原型圖以及文字說明,我們可以發(fā)現(xiàn):一個投訴信息可對應(yīng)多個回復(fù)。
在“工作主頁”中點擊“我要投訴”進入頁面,添加內(nèi)容包括:投訴標(biāo)題、被投訴部門(部門A/B)、被投訴人、投訴詳情、是否匿名投訴。
這里寫圖片描述關(guān)鍵在于匿名投訴的那一部分,我們該怎么寫….
統(tǒng)計:根據(jù)年度將相應(yīng)年度的每個月的投訴數(shù)進行統(tǒng)計,并以圖表的形式展示在頁面中;在頁面中可以選擇查看當(dāng)前年度及其前4年的投訴數(shù)。在頁面中可以選擇不同的年度,然后頁面展示該年度的曲線統(tǒng)計圖。
這里寫圖片描述這個統(tǒng)計圖,大概也需要用到組件來生成出來的吧???
自動投訴受理:在每個月月底最后一天對本月之前的投訴進行自動處理;將投訴信息的狀態(tài)改為 已失效。在后臺管理中不能對該類型投訴進行回復(fù)。
自動投訴受理??在每個月的最后一天判斷投訴信息,程序?qū)ζ渥詣邮芾怼!?/strong>
投訴受理開發(fā)
我們首先來畫一個流程圖看看它的大概思路是怎么樣的:
這里寫圖片描述Hibernate逆向工程
我們經(jīng)過上面的分析,知道了:一個投訴信息可對應(yīng)多個回復(fù)。是一對多的關(guān)系。我們下面使用powerdesginer來畫出它的概念數(shù)據(jù)模型圖
這里寫圖片描述生成物理模型圖:
這里寫圖片描述生成數(shù)據(jù)庫表:
/*==============================================================*//* DBMS name: ? ? ?MySQL 5.0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*//* Created on: ? ? 2017/6/12 19:06:20 ? ? ? ? ? ? ? ? ? ? ? ? ? *//*==============================================================*/drop table if exists complain;drop table if exists complain_reply;/*==============================================================*//* Table: complain ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*//*==============================================================*/create table complain( ? comp_id ? ? ? ? ? ? ?varchar(32) not null, ? comp_company ? ? ? ? varchar(100), ? comp_name ? ? ? ? ? ?varchar(20), ? comp_mobile ? ? ? ? ?varchar(20), ? is_NM ? ? ? ? ? ? ? ?bool, ? comp_time ? ? ? ? ? ?datetime, ? comp_title ? ? ? ? ? varchar(200) not null, ? to_comp_name ? ? ? ? varchar(20), ? to_comp_dept ? ? ? ? varchar(100), ? comp_content ? ? ? ? text, ? state ? ? ? ? ? ? ? ?varchar(1), ? primary key (comp_id));/*==============================================================*//* Table: complain_reply ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*//*==============================================================*/create table complain_reply( ? reply_id ? ? ? ? ? ? varchar(32) not null, ? comp_id ? ? ? ? ? ? ?varchar(32) not null, ? replyer ? ? ? ? ? ? ?varchar(20), ? reply_dept ? ? ? ? ? varchar(100), ? reply_time ? ? ? ? ? datetime, ? reply_content ? ? ? ?varchar(300), ? primary key (reply_id));alter table complain_reply add constraint FK_comp_reply foreign key (comp_id) ? ? ?references complain (comp_id) on delete restrict on update restrict;/* DBMS name: ? ? ?MySQL 5.0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*/
/* Created on: ? ? 2017/6/12 19:06:20 ? ? ? ? ? ? ? ? ? ? ? ? ? */
/*==============================================================*/
drop table if exists complain;
drop table if exists complain_reply;
/*==============================================================*/
/* Table: complain ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*/
/*==============================================================*/
create table complain
(
? comp_id ? ? ? ? ? ? ?varchar(32) not null,
? comp_company ? ? ? ? varchar(100),
? comp_name ? ? ? ? ? ?varchar(20),
? comp_mobile ? ? ? ? ?varchar(20),
? is_NM ? ? ? ? ? ? ? ?bool,
? comp_time ? ? ? ? ? ?datetime,
? comp_title ? ? ? ? ? varchar(200) not null,
? to_comp_name ? ? ? ? varchar(20),
? to_comp_dept ? ? ? ? varchar(100),
? comp_content ? ? ? ? text,
? state ? ? ? ? ? ? ? ?varchar(1),
? primary key (comp_id)
);
/*==============================================================*/
/* Table: complain_reply ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?*/
/*==============================================================*/
create table complain_reply
(
? reply_id ? ? ? ? ? ? varchar(32) not null,
? comp_id ? ? ? ? ? ? ?varchar(32) not null,
? replyer ? ? ? ? ? ? ?varchar(20),
? reply_dept ? ? ? ? ? varchar(100),
? reply_time ? ? ? ? ? datetime,
? reply_content ? ? ? ?varchar(300),
? primary key (reply_id)
);
alter table complain_reply add constraint FK_comp_reply foreign key (comp_id)
? ? ?references complain (comp_id) on delete restrict on update restrict;
生成實體與配置文件:
Intellij idea下生成出來的映射文件是沒有對應(yīng)的關(guān)聯(lián)關(guān)系的。也就是說:一對多或多對多的關(guān)系,它是不會幫你自動生成的【好像是這樣子的】。。。因此,需要我們自己添加Set【如果需要】
? ? ? ?<set name="complainReplies" inverse="true" cascade="save-update,delete" lazy="false" > ? ? ? ? ? ?<key> ? ? ? ? ? ? ? ?<column name="comp_id" length="32" not-null="true" /> ? ? ? ? ? ?</key> ? ? ? ? ? ?<one-to-many class="zhongfucheng.complain.entity.ComplainReply" /> ? ? ? ?</set>? ? ? ? ? ?<key>
? ? ? ? ? ? ? ?<column name="comp_id" length="32" not-null="true" />
? ? ? ? ? ?</key>
? ? ? ? ? ?<one-to-many class="zhongfucheng.complain.entity.ComplainReply" />
? ? ? ?</set>
編寫dao、service、action
編寫dao、service、action都非常簡單。記得要把模塊的配置文件加載到總配置文件中!
ComplainAction代碼如下:
public class ComplainAction extends BaseAction { ? ?/*************注入Service************************/ ? ?@Autowired ? ?private ComplainService complainServiceImpl; ? ?/************數(shù)據(jù)自動封裝,給出setter和getter*************************/ ? ?private Complain complain; ? ?public Complain getComplain() { ? ? ? ?return complain; ? ?} ? ?public void setComplain(Complain complain) { ? ? ? ?this.complain = complain; ? ?} ? ?/************Action中7大方法*************************/ ? ?//拋出Action異常 ? ?public String listUI() throws ServiceException, UnsupportedEncodingException { ? ? ? ?//把狀態(tài)的集合帶過去 ? ? ? ?QueryHelper queryHelper = new QueryHelper(Complain.class, "c"); ? ? ? ?//當(dāng)前頁數(shù)沒有值,那么賦值為1 ? ? ? ?if (currentPageCount == 0) { ? ? ? ? ? ?currentPageCount = 1; ? ? ? ?} ? ? ? ?//把狀態(tài)帶過去給JSP頁面 ? ? ? ?ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP); ? ? ? ?pageResult = complainServiceImpl.getPageResult(queryHelper,currentPageCount); ? ? ? ?return "listUI"; ? ?}}class ComplainAction extends BaseAction {? ?/*************注入Service************************/
? ?
? ?private ComplainService complainServiceImpl;
? ?/************數(shù)據(jù)自動封裝,給出setter和getter*************************/
? ?private Complain complain;
? ?public Complain getComplain() {
? ? ? ?return complain;
? ?}
? ?public void setComplain(Complain complain) {
? ? ? ?this.complain = complain;
? ?}
? ?/************Action中7大方法*************************/
? ?//拋出Action異常
? ?public String listUI() throws ServiceException, UnsupportedEncodingException {
? ? ? ?//把狀態(tài)的集合帶過去
? ? ? ?QueryHelper queryHelper = new QueryHelper(Complain.class, "c");
? ? ? ?//當(dāng)前頁數(shù)沒有值,那么賦值為1
? ? ? ?if (currentPageCount == 0) {
? ? ? ? ? ?currentPageCount = 1;
? ? ? ?}
? ? ? ?//把狀態(tài)帶過去給JSP頁面
? ? ? ?ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP);
? ? ? ?pageResult = complainServiceImpl.getPageResult(queryHelper,currentPageCount);
? ? ? ?return "listUI";
? ?}
}
導(dǎo)入對應(yīng)的JSP頁面…..得到的效果如下:
這里寫圖片描述條件查詢
我們來看一下條件查詢有幾個:可以根據(jù)投訴的標(biāo)題、投訴的時間、投訴的狀態(tài)進行查詢。
這里寫圖片描述對于投訴標(biāo)題和投訴的狀態(tài)我們都可以很容易地拿到條件:
? ? ? ?//根據(jù)complain標(biāo)題是否為null來判斷是否是條件查詢。如果complain為空,那么是查詢所有。 ? ? ? ?if (complain != null) { ? ? ? ? ? ?if (org.apache.commons.lang.StringUtils.isNotBlank(complain.getCompTitle())) { ? ? ? ? ? ? ? ?selectCondition = ?URLDecoder.decode(complain.getCompTitle(),"UTF-8"); ? ? ? ? ? ? ? ?complain.setCompTitle(selectCondition); ? ? ? ? ? ? ? ?queryHelper.addCondition(" c.compTitle like ? ", "%" + complain.getCompTitle() + "%"); ? ? ? ? ? ?} ? ? ? ? ? ?//投訴狀態(tài)并不需要編碼,因為它并不是中文。 ? ? ? ? ? ?if (org.apache.commons.lang.StringUtils.isNotBlank(complain.getState())) { ? ? ? ? ? ? ? ?queryHelper.addCondition(" c.state like ? ", "%" + complain.getState() + "%"); ? ? ? ? ? ?} ? ? ? ?}? ? ? ?if (complain != null) {
? ? ? ? ? ?if (org.apache.commons.lang.StringUtils.isNotBlank(complain.getCompTitle())) {
? ? ? ? ? ? ? ?selectCondition = ?URLDecoder.decode(complain.getCompTitle(),"UTF-8");
? ? ? ? ? ? ? ?complain.setCompTitle(selectCondition);
? ? ? ? ? ? ? ?queryHelper.addCondition(" c.compTitle like ? ", "%" + complain.getCompTitle() + "%");
? ? ? ? ? ?}
? ? ? ? ? ?//投訴狀態(tài)并不需要編碼,因為它并不是中文。
? ? ? ? ? ?if (org.apache.commons.lang.StringUtils.isNotBlank(complain.getState())) {
? ? ? ? ? ? ? ?queryHelper.addCondition(" c.state like ? ", "%" + complain.getState() + "%");
? ? ? ? ? ?}
? ? ? ?}
那么根據(jù)投訴時間來進行查詢,我們要怎么做呢???我們約定時間是這樣的格式:yyyy-MM-dd HH:mm。這樣的格式Struts2默認是不支持解析的,那么我們怎么獲取呢???
有的同學(xué)可能會想到類型轉(zhuǎn)換器,我們在Struts2的時候的確是學(xué)過類型轉(zhuǎn)換器。。。但是呢,這種方法并不是最好的。我們可以使用DateUtils工具類來得到日期數(shù)據(jù)!
? ?//先判斷時間,通過時間進行篩選后,再進行l(wèi)ike模糊查詢。那么性能會好一些 ? ?if (StringUtils.isNotBlank(startTime)) { ? ? ? ?startTime = ?URLDecoder.decode(startTime,"UTF-8"); ? ? ? ?queryHelper.addCondition(" c.compTime >= ? ", DateUtils.parseDate(startTime, new String[]{"yyyy-MM-dd HH:mm"})); ? ?} ? ?if (StringUtils.isNotBlank(endTime)) { ? ? ? ?endTime = ?URLDecoder.decode(endTime,"UTF-8"); ? ? ? ?queryHelper.addCondition(" c.compTime <= ? ", DateUtils.parseDate(endTime, new String[]{"yyyy-MM-dd HH:mm"})); ? ?}? ?if (StringUtils.isNotBlank(startTime)) {
? ? ? ?startTime = ?URLDecoder.decode(startTime,"UTF-8");
? ? ? ?queryHelper.addCondition(" c.compTime >= ? ", DateUtils.parseDate(startTime, new String[]{"yyyy-MM-dd HH:mm"}));
? ?}
? ?if (StringUtils.isNotBlank(endTime)) {
? ? ? ?endTime = ?URLDecoder.decode(endTime,"UTF-8");
? ? ? ?queryHelper.addCondition(" c.compTime <= ? ", DateUtils.parseDate(endTime, new String[]{"yyyy-MM-dd HH:mm"}));
? ?}
我們在JSP頁面上也使用datepicker組件來讓用戶選擇日期:
? ? ? 投訴時間:<s:textfield id="startTime" name="startTime" cssClass="s_text" ?cssStyle="width:160px;" readonly="true" onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd HH:mm'});"/> ? ? ? ? ?- ? ? ? ? <s:textfield id="endTime" name="endTime" cssClass="s_text" ?cssStyle="width:160px;" readonly="true" onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd HH:mm'});"/>? ? ? ? ?-
? ? ? ? <s:textfield id="endTime" name="endTime" cssClass="s_text" ?cssStyle="width:160px;" readonly="true" onfocus="WdatePicker({'skin':'whyGreen','dateFmt':'yyyy-MM-dd HH:mm'});"/>
受理回復(fù)
提供處理受理的UI界面。根據(jù)id查找投訴的全部信息。
? ?//提供受理的UI ? ?public String dealUI() { ? ? ? ?//把狀態(tài)傳遞過去 ? ? ? ?ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP); ? ? ? ?//得到想要受理的記錄 ? ? ? ?if (complain != null) { ? ? ? ? ? ?complain = complainServiceImpl.findObjectById(complain.getCompId()); ? ? ? ?} ? ? ? ?return "dealUI"; ? ?}? ?public String dealUI() {
? ? ? ?//把狀態(tài)傳遞過去
? ? ? ?ActionContext.getContext().getContextMap().put("complainStateMap", Complain.COMPLAIN_STATE_MAP);
? ? ? ?//得到想要受理的記錄
? ? ? ?if (complain != null) {
? ? ? ? ? ?complain = complainServiceImpl.findObjectById(complain.getCompId());
? ? ? ?}
? ? ? ?return "dealUI";
? ?}
在處理受理的JSP頁面上要把投訴的id給發(fā)送給Action處理。不然在保存信息的時候,就會把投訴信息丟失了!。在Action中通過id重新查找回投訴的信息!
? ?//受理 ? ?public String deal() { ? ? ? ?//修改投訴信息的處理狀態(tài) ? ? ? ?if (complain != null) { ? ? ? ? ? ?//查找到信息 ? ? ? ? ? ?complain = complainServiceImpl.findObjectById(complain.getCompId()); ? ? ? ? ? ?//如果狀態(tài)是已處理了,那么就不用再修改了 ? ? ? ? ? ?if (!complain.getState().equals(Complain.COMPLAIN_STATE_DONE)) { ? ? ? ? ? ? ? ?complain.setState(Complain.COMPLAIN_STATE_DONE); ? ? ? ? ? ?} ? ? ? ?} ? ? ? ?//保存回復(fù)的信息 ? ? ? ?if (reply != null) { ? ? ? ? ? ?//更新回復(fù)的日期 ? ? ? ? ? ?reply.setReplyTime(new Timestamp(new Date().getTime())); ? ? ? ? ? ?//把回復(fù)信息添加到投訴信息中【關(guān)聯(lián)關(guān)系】 ? ? ? ? ? ?reply.setComplain(complain); ? ? ? ? ? ?complain.getComplainReplies().add(reply); ? ? ? ?} ? ? ? ?//級聯(lián)更新 ? ? ? ?complainServiceImpl.update(complain); ? ? ? ?return "list"; ? ?}? ?public String deal() {
? ? ? ?//修改投訴信息的處理狀態(tài)
? ? ? ?if (complain != null) {
? ? ? ? ? ?//查找到信息
? ? ? ? ? ?complain = complainServiceImpl.findObjectById(complain.getCompId());
? ? ? ? ? ?//如果狀態(tài)是已處理了,那么就不用再修改了
? ? ? ? ? ?if (!complain.getState().equals(Complain.COMPLAIN_STATE_DONE)) {
? ? ? ? ? ? ? ?complain.setState(Complain.COMPLAIN_STATE_DONE);
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?//保存回復(fù)的信息
? ? ? ?if (reply != null) {
? ? ? ? ? ?//更新回復(fù)的日期
? ? ? ? ? ?reply.setReplyTime(new Timestamp(new Date().getTime()));
? ? ? ? ? ?//把回復(fù)信息添加到投訴信息中【關(guān)聯(lián)關(guān)系】
? ? ? ? ? ?reply.setComplain(complain);
? ? ? ? ? ?complain.getComplainReplies().add(reply);
? ? ? ?}
? ? ? ?//級聯(lián)更新
? ? ? ?complainServiceImpl.update(complain);
? ? ? ?return "list";
? ?}
顯示回復(fù)信息
我們在處理投訴的時候,應(yīng)該把回復(fù)的歷史信息給處理的人看…..
把回復(fù)的信息遍歷出來。
? ? ? ?<s:iterator value="complain.complainReplies" status="st"> ? ? ? ?<tr> ? ? ? ? ? ?<%--得到所有回復(fù)的信息--%> ? ? ? ? ? ?<td colspan="2"> ? ? ? ? ? ? ? ? ? ?<fieldset style="border: solid 1px #c0c0c0;margin-top:5px;"><legend style="color:green;font-weight:bold;"> ? ? ? ? ? ? ? ? ? ? ? ?回復(fù)<s:property ? ? ? ? ? ? ? ? ? ? ? ? ? ?value="#st.count"/> </legend> ? ? ? ? ? ? ? ? ? ? ? ?<div style="width:100%; text-align:center;color:#ccc;maring-top:5px;"> ? ? ? ? ? ? ? ? ? ? ? ?回復(fù)部門:<s:property value="replyDept"/> ? ? ? ? ? ? ? ? ? ? ? ?回復(fù)人:<s:property value="replyer"/> ? ? ? ? ? ? ? ? ? ? ? ?回復(fù)時間:<s:date name="replyTime" format="yyyy-MM-dd HH:mm"/> ? ? ? ? ? ? ? ? ? ? ? ?</div> ? ? ? ? ? ? ? ? ? ? ? ?<div style="width:100%;maring-top:10px;font-size:13px;padding-left:5px;"><s:property value="replyContent"/></div> ? ? ? ? ? ? ? ? ? ?</fieldset> ? ? ? ? ? ?</td> ? ? ? ?</tr> ? ? ? ?</s:iterator>? ? ? ?<tr>
? ? ? ? ? ?<%--得到所有回復(fù)的信息--%>
? ? ? ? ? ?<td colspan="2">
? ? ? ? ? ? ? ? ? ?<fieldset style="border: solid 1px #c0c0c0;margin-top:5px;"><legend style="color:green;font-weight:bold;">
? ? ? ? ? ? ? ? ? ? ? ?回復(fù)<s:property
? ? ? ? ? ? ? ? ? ? ? ? ? ?value="#st.count"/> </legend>
? ? ? ? ? ? ? ? ? ? ? ?<div style="width:100%; text-align:center;color:#ccc;maring-top:5px;">
? ? ? ? ? ? ? ? ? ? ? ?回復(fù)部門:<s:property value="replyDept"/>
? ? ? ? ? ? ? ? ? ? ? ?回復(fù)人:<s:property value="replyer"/>
? ? ? ? ? ? ? ? ? ? ? ?回復(fù)時間:<s:date name="replyTime" format="yyyy-MM-dd HH:mm"/>
? ? ? ? ? ? ? ? ? ? ? ?</div>
? ? ? ? ? ? ? ? ? ? ? ?<div style="width:100%;maring-top:10px;font-size:13px;padding-left:5px;"><s:property value="replyContent"/></div>
? ? ? ? ? ? ? ? ? ?</fieldset>
? ? ? ? ? ?</td>
? ? ? ?</tr>
? ? ? ?</s:iterator>
現(xiàn)在有一個問題,就是我們使用的是set集合,它所有的回復(fù)信息并不是按照順序來排列的。我們可以在hbm配置文件中指定我們set集合的順序:
這里寫圖片描述那么在顯示的時候,我們的回復(fù)順序就不會被搞亂了。
匿名投訴
在需求中,我們已經(jīng)看到了,如果投訴的人是匿名投訴的,那么我們不能顯示該投訴人的名字、部門。他的號碼應(yīng)該設(shè)置成1372342類型的。
其實我們只要在顯示對應(yīng)值的前面判斷該投訴人是否是匿名投訴就行了。
? ? ? ?<td> ? ? ? ? ? ?<s:if test="%{complain.isNm==0}"> ? ? ? ? ? ? ? ?<%--138****2342類型--%> ? ? ? ? ? ? ? ?<s:property value="complain.compMobile"/> ? ? ? ? ? ?</s:if> ? ? ? ? ? ?<s:else> ? ? ? ? ? ? ? ?<s:property value="%{complain.compMobile.substring(0,3)+'****'+complain.compMobile.substring(7,11)}"/> ? ? ? ? ? ?</s:else> ? ? ? ?</td>? ? ? ? ? ?<s:if test="%{complain.isNm==0}">
? ? ? ? ? ? ? ?<%--138****2342類型--%>
? ? ? ? ? ? ? ?<s:property value="complain.compMobile"/>
? ? ? ? ? ?</s:if>
? ? ? ? ? ?<s:else>
? ? ? ? ? ? ? ?<s:property value="%{complain.compMobile.substring(0,3)+'****'+complain.compMobile.substring(7,11)}"/>
? ? ? ? ? ?</s:else>
? ? ? ?</td>
我要投訴二級聯(lián)動
用戶可以在首頁上通過“我要投訴”超鏈接對工作人員進行投訴..當(dāng)然了,用戶點擊“我要投訴”超鏈接的時候,應(yīng)該在新的頁面上給出對應(yīng)的頁面,所以指定target為“_blank”..
我們在指定部門的時候,下拉菜單應(yīng)該在后臺給出對應(yīng)的的員工。這就需要我們用到ajax進行二級菜單的二級聯(lián)動了。
我們在返回JSON格式有兩種方式:第一種就是沒有使用Struts2框架的時候,
使用三個開發(fā)包commons-beanutils-1.8.0,ezmorph-1.0.6,json-lib-2.3-jdk15。使用JSONObject對象來構(gòu)建JSON字符串,使用流對象返回給瀏覽器。
我們?nèi)绻褂昧薙truts2框架的話,直接導(dǎo)入:struts2-json-plugin-2.3.20這么一個開發(fā)包,并且在配置文件中指定繼承json-defalut包,返回的類型是JSON的話。那么Struts2框架就會自動幫我們在該Action中所擁有g(shù)etter方法的屬性就生成JSON格式返回給瀏覽器。。。當(dāng)然了,我們可能不想Struts2把全部帶有g(shù)etter的屬性都生成JSON返回給瀏覽器,我們只要在返回JSON類型上指定參數(shù)root,就可以指定生成哪一個屬性自動生成JSON字符串返回給瀏覽器了。
這里寫圖片描述當(dāng)然了,無論是沒有使用Struts2框架,還是有使用Struts2框架,我們都是有過Demo的。詳情請參考博文:http://blog.csdn.net/hon_3y/article/details/72468761和http://blog.csdn.net/hon_3y/article/details/72480126
另外,我們手動訪問Acttion給出對應(yīng)的參數(shù),就可以看到服務(wù)器返回的JSON是什么了。最后我們使用HiJson這樣的工具,就可以把返回的JSON進行格式化。
這里寫圖片描述那么,我們的代碼是這樣的:
使用ajax返回服務(wù)器。
? ? ? ?function doSelectDept() { ? ? ? ? ? ?var $dept = $("#toCompDept option:selected").val(); ? ? ? ? ? ?//初始化清空 ? ? ? ? ? if($dept =="0"){ ? ? ? ? ? ? ? $("#toCompName").empty(); ? ? ? ? ? ?} ? ? ? ? ? ?$.ajax({ ? ? ? ? ? ? ? ?type: "post", ? ? ? ? ? ? ? ?url: "${basePath}sys/home_getUserJson.action", ? ? ? ? ? ? ? ?data: {"dept":$dept}, ? ? ? ? ? ? ? ?dataType: "json", ? ? ? ? ? ? ? ?success: function (data) { ? ? ? ? ? ? ? ? ? ?if("success" == data.msg){ ? ? ? ? ? ? ? ? ? ? ? ?var toCompName = $("#toCompName"); ? ? ? ? ? ? ? ? ? ? ? ?toCompName.empty(); ? ? ? ? ? ? ? ? ? ? ? ?$.each(data.userList, function(index, user){ ? ? ? ? ? ? ? ? ? ? ? ? ? ?toCompName.append("<option value='" + user.name + "'>" + user.name + "</option>"); ? ? ? ? ? ? ? ? ? ? ? ?}); ? ? ? ? ? ? ? ? ? ?} else {alert("獲取被投訴人列表失敗!");} ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ?error: function () { ? ? ? ? ? ? ? ? ? ?alert("失敗咯") ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}); ? ? ? ?}? ? ? ? ? ?var $dept = $("#toCompDept option:selected").val();
? ? ? ? ? ?//初始化清空
? ? ? ? ? if($dept =="0"){
? ? ? ? ? ? ? $("#toCompName").empty();
? ? ? ? ? ?}
? ? ? ? ? ?$.ajax({
? ? ? ? ? ? ? ?type: "post",
? ? ? ? ? ? ? ?url: "${basePath}sys/home_getUserJson.action",
? ? ? ? ? ? ? ?data: {"dept":$dept},
? ? ? ? ? ? ? ?dataType: "json",
? ? ? ? ? ? ? ?success: function (data) {
? ? ? ? ? ? ? ? ? ?if("success" == data.msg){
? ? ? ? ? ? ? ? ? ? ? ?var toCompName = $("#toCompName");
? ? ? ? ? ? ? ? ? ? ? ?toCompName.empty();
? ? ? ? ? ? ? ? ? ? ? ?$.each(data.userList, function(index, user){
? ? ? ? ? ? ? ? ? ? ? ? ? ?toCompName.append("<option value='" + user.name + "'>" + user.name + "</option>");
? ? ? ? ? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ? ? ?} else {alert("獲取被投訴人列表失敗!");}
? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ?error: function () {
? ? ? ? ? ? ? ? ? ?alert("失敗咯")
? ? ? ? ? ? ? ?}
? ? ? ? ? ?});
? ? ? ?}
使用一個Map集合裝載這些數(shù)據(jù),Struts2自動把Map集合的數(shù)據(jù)轉(zhuǎn)成是JSON格式的,返回給瀏覽器。
? ?private Map<String, Object> return_map; ? ?public Map<String, Object> getReturn_map() { ? ? ? ?return return_map; ? ?} ? ? ?public String getUserJson() { ? ? ? ? ? ?//得到帶過來的dept ? ? ? ? ? ?String dept = ServletActionContext.getRequest().getParameter("dept"); ? ? ? ? ? ?if (dept != null) { ? ? ? ? ? ? ? ?//根據(jù)部門查詢所有的員工 ? ? ? ? ? ? ? ?QueryHelper queryHelper = new QueryHelper(User.class, "u"); ? ? ? ? ? ? ? ?queryHelper.addCondition(" u.dept like ? ", "%" +dept); ? ? ? ? ? ? ? ?//2、根據(jù)部門查詢用戶列表 ? ? ? ? ? ? ? ?return_map = new HashMap(); ? ? ? ? ? ? ? ?return_map.put("msg", "success"); ? ? ? ? ? ? ? ?return_map.put("userList", userServiceImpl.findObjects(queryHelper)); ? ? ? ? ? ?} ? ? ? ? ? ?return "success"; ? ? ? ?}? ?public Map<String, Object> getReturn_map() {
? ? ? ?return return_map;
? ?}
? ? ?public String getUserJson() {
? ? ? ? ? ?//得到帶過來的dept
? ? ? ? ? ?String dept = ServletActionContext.getRequest().getParameter("dept");
? ? ? ? ? ?if (dept != null) {
? ? ? ? ? ? ? ?//根據(jù)部門查詢所有的員工
? ? ? ? ? ? ? ?QueryHelper queryHelper = new QueryHelper(User.class, "u");
? ? ? ? ? ? ? ?queryHelper.addCondition(" u.dept like ? ", "%" +dept);
? ? ? ? ? ? ? ?//2、根據(jù)部門查詢用戶列表
? ? ? ? ? ? ? ?return_map = new HashMap();
? ? ? ? ? ? ? ?return_map.put("msg", "success");
? ? ? ? ? ? ? ?return_map.put("userList", userServiceImpl.findObjects(queryHelper));
? ? ? ? ? ?}
? ? ? ? ? ?return "success";
? ? ? ?}
我要投訴保存信息
我們在投訴的內(nèi)容上添加上富文本框,讓用戶可以在文本域上傳上圖片….
加上一個富文本框是非常簡單的,只要導(dǎo)入對應(yīng)的js文件,在textarea上寫上ueditor的id就可以完成效果了。。。
? ?<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/ueditor.config.js"></script> ? ?<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/ueditor.all.min.js"> </script> ? ?<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/lang/zh-cn/zh-cn.js"></script> ? ?<script type="text/javascript"> ? ? ? ?//配置ueditor的根路徑 ? ? ? ?var UEDITOR_HOME_URL = "${basePath}js/ueditor/"; ? ? ? ?var ue = UE.getEditor('editor'); ? ?</script> ? ? <td><s:textarea id="editor" name="comp.compContent" cssStyle="width:90%;height:160px;"/></td>"utf-8" src="${basePath}js/ueditor/ueditor.config.js"></script>? ?<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/ueditor.all.min.js"> </script>
? ?<script type="text/javascript" charset="utf-8" src="${basePath}js/ueditor/lang/zh-cn/zh-cn.js"></script>
? ?<script type="text/javascript">
? ? ? ?//配置ueditor的根路徑
? ? ? ?var UEDITOR_HOME_URL = "${basePath}js/ueditor/";
? ? ? ?var ue = UE.getEditor('editor');
? ?</script>
? ? <td><s:textarea id="editor" name="comp.compContent" cssStyle="width:90%;height:160px;"/></td>
再次觀察我們的投訴頁面,表單里面的值只有是被投訴人的信息,投訴人的信息是沒有的。于是我們在表單中把投訴人的信息通過隱藏域?qū)⑵涮砑舆M去….
? ?<s:hidden name="comp.compCompany" value="%{#session.SYS_USER.dept}"></s:hidden> ? ?<s:hidden name="comp.compName" value="%{#session.SYS_USER.name}"></s:hidden> ? ?<s:hidden name="comp.compMobile" value="%{#session.SYS_USER.mobile}"></s:hidden></s:hidden>? ?<s:hidden name="comp.compName" value="%{#session.SYS_USER.name}"></s:hidden>
? ?<s:hidden name="comp.compMobile" value="%{#session.SYS_USER.mobile}"></s:hidden>
那我們保存“我要投訴”信息的流程應(yīng)該是怎么樣的呢???為了達到更好的用戶體驗,我們應(yīng)該先把提示用戶數(shù)據(jù)已經(jīng)保存起來了,然后刷新父窗口,接著把“我要投訴”本頁面給關(guān)閉了。這樣用戶看起來,就覺得他的操作已經(jīng)是成功了!
下面是整個“我要投訴”操作的時序圖:
這里寫圖片描述代碼:
? ?public void saveComplain() { ? ? ? ?try { ? ? ? ? ? ?if (comp != null) { ? ? ? ? ? ? ? ?//把投訴的缺少的信息補全 ? ? ? ? ? ? ? ?comp.setState(Complain.COMPLAIN_STATE_UNDONE); ? ? ? ? ? ? ? ?comp.setCompTime(new Timestamp(new Date().getTime())); ? ? ? ? ? ? ? ?//調(diào)用service保存 ? ? ? ? ? ? ? ?complainServiceImpl.save(comp); ? ? ? ? ? ? ? ?//告訴瀏覽器保存信息成功了。 ? ? ? ? ? ? ? ?ServletActionContext.getResponse().getWriter().write("success"); ? ? ? ? ? ?} ? ? ? ?} catch (IOException e) { ? ? ? ? ? ?e.printStackTrace(); ? ? ? ?} ? ?}? ? ? ?try {
? ? ? ? ? ?if (comp != null) {
? ? ? ? ? ? ? ?//把投訴的缺少的信息補全
? ? ? ? ? ? ? ?comp.setState(Complain.COMPLAIN_STATE_UNDONE);
? ? ? ? ? ? ? ?comp.setCompTime(new Timestamp(new Date().getTime()));
? ? ? ? ? ? ? ?//調(diào)用service保存
? ? ? ? ? ? ? ?complainServiceImpl.save(comp);
? ? ? ? ? ? ? ?//告訴瀏覽器保存信息成功了。
? ? ? ? ? ? ? ?ServletActionContext.getResponse().getWriter().write("success");
? ? ? ? ? ?}
? ? ? ?} catch (IOException e) {
? ? ? ? ? ?e.printStackTrace();
? ? ? ?}
? ?}
提示用戶已經(jīng)投訴成功,把父窗口刷新,本頁面關(guān)閉。
function saveComplain() { ? ? ? ? ? ?$.ajax({ ? ? ? ? ? ? ? ?url: "${basePath}sys/home_saveComplain.action", ? ? ? ? ? ? ? ?/*將整個表單的屬性轉(zhuǎn)成是JSON*/ ? ? ? ? ? ? ? ?data: $("form").serialize(), ? ? ? ? ? ? ? ?type: "post", ? ? ? ? ? ? ? ?success: function (backdata) { ? ? ? ? ? ? ? ? ? ?if(backdata == "success"){ ? ? ? ? ? ? ? ? ? ? ? ?//告訴用戶,保存成功了。 ? ? ? ? ? ? ? ? ? ? ? ?alert("投訴成功!!!"); ? ? ? ? ? ? ? ? ? ? ? ?//把父窗口刷新 ? ? ? ? ? ? ? ? ? ? ? ?window.opener.parent.location.reload(true); ? ? ? ? ? ? ? ? ? ? ? ?//把本頁面關(guān)閉 ? ? ? ? ? ? ? ? ? ? ? ?window.close(); ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ?error:function () { ? ? ? ? ? ? ? ? ? ?alert("保存投訴信息失敗了!"); ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}); ? ? ? ?}? ? ? ? ? ?$.ajax({
? ? ? ? ? ? ? ?url: "${basePath}sys/home_saveComplain.action",
? ? ? ? ? ? ? ?/*將整個表單的屬性轉(zhuǎn)成是JSON*/
? ? ? ? ? ? ? ?data: $("form").serialize(),
? ? ? ? ? ? ? ?type: "post",
? ? ? ? ? ? ? ?success: function (backdata) {
? ? ? ? ? ? ? ? ? ?if(backdata == "success"){
? ? ? ? ? ? ? ? ? ? ? ?//告訴用戶,保存成功了。
? ? ? ? ? ? ? ? ? ? ? ?alert("投訴成功!!!");
? ? ? ? ? ? ? ? ? ? ? ?//把父窗口刷新
? ? ? ? ? ? ? ? ? ? ? ?window.opener.parent.location.reload(true);
? ? ? ? ? ? ? ? ? ? ? ?//把本頁面關(guān)閉
? ? ? ? ? ? ? ? ? ? ? ?window.close();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ?error:function () {
? ? ? ? ? ? ? ? ? ?alert("保存投訴信息失敗了!");
? ? ? ? ? ? ? ?}
? ? ? ? ? ?});
? ? ? ?}
投訴受理的三圈問題
在信息管理模塊的時候,我們就提出了三圈的問題了。何為三圈問題呢???就是當(dāng)我們使用條件查詢出數(shù)據(jù)的時候,再對查詢出的數(shù)據(jù)進行操作【修改、保存】,當(dāng)保存完之后回到列表顯示頁面上的時候,查詢條件就會丟失掉了。也就是說,我們原來查詢出的數(shù)據(jù)不見了。
首先,我們在Action中使用兩個變量把有可能成為查詢條件的變量記住:
? ?/************三圈問題數(shù)據(jù)回顯*************************/ ? ?private String compTitle; ? ?private String state; ? ?public String getCompTitle() { ? ? ? ?return compTitle; ? ?} ? ?public void setCompTitle(String compTitle) { ? ? ? ?this.compTitle = compTitle; ? ?} ? ?public String getState() { ? ? ? ?return state; ? ?} ? ?public void setState(String state) { ? ? ? ?this.state = state; ? ?}? ?private String compTitle;
? ?private String state;
? ?public String getCompTitle() {
? ? ? ?return compTitle;
? ?}
? ?public void setCompTitle(String compTitle) {
? ? ? ?this.compTitle = compTitle;
? ?}
? ?public String getState() {
? ? ? ?return state;
? ?}
? ?public void setState(String state) {
? ? ? ?this.state = state;
? ?}
接著,在跳轉(zhuǎn)到處理投訴頁面的JSP上的時候,把查詢條件的數(shù)據(jù)查詢出來,把它賦值給變量。然后使用request域?qū)ο蟀褦?shù)據(jù)發(fā)給JSP頁面
? ? ? ? ? ?//把查詢條件帶過去給JSP頁面 ? ? ? ? ? ?ActionContext.getContext().getContextMap().put("compTitle", complain.getCompTitle()); ? ? ? ? ? ?ActionContext.getContext().getContextMap().put("state", complain.getState()); ? ? ? ? ? ?ActionContext.getContext().getContextMap().put("startTime", startTime); ? ? ? ? ? ?ActionContext.getContext().getContextMap().put("endTime", endTime);? ? ? ? ? ?ActionContext.getContext().getContextMap().put("compTitle", complain.getCompTitle());
? ? ? ? ? ?ActionContext.getContext().getContextMap().put("state", complain.getState());
? ? ? ? ? ?ActionContext.getContext().getContextMap().put("startTime", startTime);
? ? ? ? ? ?ActionContext.getContext().getContextMap().put("endTime", endTime);
然后在處理投訴頁面的JSP上,通過隱藏域把數(shù)據(jù)給回Action。。Action在重定向到listUI頁面的時候,就通過配置文件,把參數(shù)帶過去:
? ? ? ? ? ?<!--返回列表展示頁面,重定向到列表展示--> ? ? ? ? ? ?<result name="list" type="redirectAction"> ? ? ? ? ? ? ? ?<param name="actionName">complain_listUI</param> ? ? ? ? ? ? ? ?<param name="complain.state">${state}</param> ? ? ? ? ? ? ? ?<param name="complain.compTitle">${compTitle}</param> ? ? ? ? ? ? ? ?<param name="endTime">${startTime}</param> ? ? ? ? ? ? ? ?<param name="startTime">${startTime}</param> ? ? ? ? ? ? ? ?<param name="encode">true</param> ? ? ? ? ? ?</result>? ? ? ? ? ?<result name="list" type="redirectAction">
? ? ? ? ? ? ? ?<param name="actionName">complain_listUI</param>
? ? ? ? ? ? ? ?<param name="complain.state">${state}</param>
? ? ? ? ? ? ? ?<param name="complain.compTitle">${compTitle}</param>
? ? ? ? ? ? ? ?<param name="endTime">${startTime}</param>
? ? ? ? ? ? ? ?<param name="startTime">${startTime}</param>
? ? ? ? ? ? ? ?<param name="encode">true</param>
? ? ? ? ? ?</result>
這樣一來,我們的查詢條件就沒有丟失了。當(dāng)我們操作完數(shù)據(jù)的時候,我們的查詢出來的數(shù)據(jù)還是原來那部分。
Quartz自動受理
回到我們的需求:
自動投訴受理:在每個月月底最后一天對本月之前的投訴進行自動處理;將投訴信息的狀態(tài)改為 已失效。在后臺管理中不能對該類型投訴進行回復(fù)。
這個需求需求我們要怎么弄呢????要在每個月底最后一天對本月之前的投訴進行自動處理。。。。
記得我們以前在學(xué)習(xí)Java基礎(chǔ)的時候?qū)W過了一個Timer這么一個類,可以用規(guī)定的頻率來執(zhí)行我們的代碼。。。使用起來是非常簡單的:
這里寫圖片描述這里寫圖片描述但是呢,要精確到每個月的月底,這就需要我們?nèi)藶槿ヅ袛鄷r間了,這就非常不方便了。
因此,我們引入了另一個非常好用的框架:Quartz
Quartz
這是一個優(yōu)秀的開源任務(wù)調(diào)度框架“quartz”,可以簡單理解成他是Timer的升級版….Spring集成了該框架…
快速入門
我們要使用它,就要導(dǎo)入其開發(fā)包:quartz-1.8.6.jar,和Spring對其支持的開發(fā)包:org.springframework.context.support-3.0.2.RELEASE
使用它的步驟是十分簡單的,可分成三個步驟:
1、制定任務(wù)信息 bean
2、制定任務(wù)執(zhí)行時機(執(zhí)行觸發(fā)器) bean
3、設(shè)置任務(wù)調(diào)度工廠 bean
jobDetail任務(wù)詳細信息
1、jobDetail 任務(wù)詳細信息;包括調(diào)用哪個類;類中的哪個方法;執(zhí)行時是否可并行執(zhí)行任務(wù)。
? <!-- 1、制定任務(wù)信息信息 --> ? <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> ? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象 --> ? ? ? ? ? ? ?<property name="targetObject" ref="quartzTask"></property> ? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 --> ? ? ? ? ? ? ?<property name="targetMethod" value="doSimpleTriggerTask"></property> ? ? ? ? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 --> ? ? ? ? ? ? ?<property name="concurrent" value="false"></property> ? </bean> ? <bean id="jobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> ? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象 --> ? ? ? ? ? ? ?<property name="targetObject" ref="quartzTask"></property> ? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 --> ? ? ? ? ? ? ?<property name="targetMethod" value="doCronTriggerTask"></property> ? ? ? ? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 --> ? ? ? ? ? ? ?<property name="concurrent" value="false"></property> ? </bean>? <bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象 -->
? ? ? ? ? ? ?<property name="targetObject" ref="quartzTask"></property>
? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 -->
? ? ? ? ? ? ?<property name="targetMethod" value="doSimpleTriggerTask"></property>
? ? ? ? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 -->
? ? ? ? ? ? ?<property name="concurrent" value="false"></property>
? </bean>
? <bean id="jobDetail2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象 -->
? ? ? ? ? ? ?<property name="targetObject" ref="quartzTask"></property>
? ? ? ? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 -->
? ? ? ? ? ? ?<property name="targetMethod" value="doCronTriggerTask"></property>
? ? ? ? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 -->
? ? ? ? ? ? ?<property name="concurrent" value="false"></property>
? </bean>
這里寫圖片描述
trigger任務(wù)調(diào)度觸發(fā)器
2、trigger 任務(wù)調(diào)度觸發(fā)器;主要用于定義jobDetail什么時候執(zhí)行。觸發(fā)器最常用的有兩種:簡單觸發(fā)器SimpleTrigger 和 任務(wù)觸發(fā)器CronTrigger 。SimpleTrigger和jdk的timer類似,只能指定任務(wù)執(zhí)行以什么樣的頻率執(zhí)行,但無法制定精確的執(zhí)行時間。CronTrigger則既可以執(zhí)行簡單觸發(fā)器所制定的以頻率來執(zhí)行的時間,也可以制定復(fù)雜的時間計劃來執(zhí)行。
? <!-- 2、制定任務(wù)執(zhí)行時機(任務(wù)執(zhí)行觸發(fā)器) --> ? <bean id="simplerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> ? ? ? ? ? <!-- 設(shè)置任務(wù)詳細 --> ? ? ? ? ? <property name="jobDetail" ref="jobDetail1"></property> ? ? ? ? ? <!-- 設(shè)置任務(wù)延遲執(zhí)行時間 ;延遲2秒執(zhí)行--> ? ? ? ? ? <property name="startDelay" value="2000"></property> ? ? ? ? ? <!-- 設(shè)置任務(wù)執(zhí)行頻率;執(zhí)行頻率為每4秒執(zhí)行一下 --> ? ? ? ? ? <property name="repeatInterval" value="2000"></property> ? </bean> ? <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> ? ? ? ?<!-- 設(shè)置任務(wù)詳細 --> ? ? ? ? ? <property name="jobDetail" ref="jobDetail2"></property> ? ? ? ? ? <!-- 設(shè)置任務(wù)執(zhí)行時機,cron表達式 --> ? ? ? ? ? <property name="cronExpression" value="* * * 18c * ?"></property> ? </bean>? <bean id="simplerTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
? ? ? ? ? <!-- 設(shè)置任務(wù)詳細 -->
? ? ? ? ? <property name="jobDetail" ref="jobDetail1"></property>
? ? ? ? ? <!-- 設(shè)置任務(wù)延遲執(zhí)行時間 ;延遲2秒執(zhí)行-->
? ? ? ? ? <property name="startDelay" value="2000"></property>
? ? ? ? ? <!-- 設(shè)置任務(wù)執(zhí)行頻率;執(zhí)行頻率為每4秒執(zhí)行一下 -->
? ? ? ? ? <property name="repeatInterval" value="2000"></property>
? </bean>
? <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
? ? ? ?<!-- 設(shè)置任務(wù)詳細 -->
? ? ? ? ? <property name="jobDetail" ref="jobDetail2"></property>
? ? ? ? ? <!-- 設(shè)置任務(wù)執(zhí)行時機,cron表達式 -->
? ? ? ? ? <property name="cronExpression" value="* * * 18c * ?"></property>
? </bean>
這里寫圖片描述
這里我們著重要了解表達式怎么寫:秒 分 時 日 月 周 年【日和周不能同時出現(xiàn)】
這里寫圖片描述schedulerFactory 任務(wù)調(diào)度工廠
schedulerFactory 任務(wù)調(diào)度工廠;用于調(diào)度各個任務(wù)觸發(fā)器。
任務(wù)調(diào)度工廠可以調(diào)度多個任務(wù)同時進行
? <!-- 3、設(shè)置調(diào)度工廠 --> ? <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> ? ? ? ? ? <property name="triggers"> ? ? ? ? ? ? ? <list> ? ? ? ? ? ? ? ? ? <!-- <ref bean="simplerTrigger"/> --> ? ? ? ? ? ? ? ? ? <ref bean="cronTrigger"/> ? ? ? ? ? ? ? </list> ? ? ? ? ? </property> ? </bean>? <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
? ? ? ? ? <property name="triggers">
? ? ? ? ? ? ? <list>
? ? ? ? ? ? ? ? ? <!-- <ref bean="simplerTrigger"/> -->
? ? ? ? ? ? ? ? ? <ref bean="cronTrigger"/>
? ? ? ? ? ? ? </list>
? ? ? ? ? </property>
? </bean>
這里寫圖片描述
自動受理
回到我們的需求,我們已經(jīng)大概了解了Quartz這么一個開源框架使用了。我們就可以在每個月的最后一天中去執(zhí)行我們對應(yīng)的代碼就行了。
在Spring配置文件中加入Quartz框架….
我們在Service中執(zhí)行對應(yīng)的代碼:
? ?<!-- 1、制定任務(wù)信息信息 --> ? ?<bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> ? ? ? ?<!-- 設(shè)置執(zhí)行對象 --> ? ? ? ?<property name="targetObject" ref="complainServiceImpl"></property> ? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 --> ? ? ? ?<property name="targetMethod" value="doTask"></property> ? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 --> ? ? ? ?<property name="concurrent" value="false"></property> ? ?</bean> ? ?<!-- 2、制定任務(wù)執(zhí)行時機(任務(wù)執(zhí)行觸發(fā)器) --> ? ?<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> ? ? ? ?<!-- 設(shè)置任務(wù)詳細 --> ? ? ? ?<property name="jobDetail" ref="jobDetail1"></property> ? ? ? ?<!-- 設(shè)置任務(wù)執(zhí)行時機,cron表達式 --> ? ? ? ?<property name="cronExpression" value="10 10 2 L * ?"></property> ? ?</bean> ? ?<!-- 3、設(shè)置調(diào)度工廠 --> ? ?<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> ? ? ? ?<property name="triggers"> ? ? ? ? ? ?<list> ? ? ? ? ? ? ? ?<ref bean="cronTrigger"/> ? ? ? ? ? ?</list> ? ? ? ?</property> ? ?</bean></beans>? ?<bean id="jobDetail1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
? ? ? ?<!-- 設(shè)置執(zhí)行對象 -->
? ? ? ?<property name="targetObject" ref="complainServiceImpl"></property>
? ? ? ?<!-- 設(shè)置執(zhí)行對象中對應(yīng)的執(zhí)行方法 -->
? ? ? ?<property name="targetMethod" value="doTask"></property>
? ? ? ?<!-- 是否可以同步執(zhí)行;不可同步執(zhí)行 -->
? ? ? ?<property name="concurrent" value="false"></property>
? ?</bean>
? ?<!-- 2、制定任務(wù)執(zhí)行時機(任務(wù)執(zhí)行觸發(fā)器) -->
? ?<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
? ? ? ?<!-- 設(shè)置任務(wù)詳細 -->
? ? ? ?<property name="jobDetail" ref="jobDetail1"></property>
? ? ? ?<!-- 設(shè)置任務(wù)執(zhí)行時機,cron表達式 -->
? ? ? ?<property name="cronExpression" value="10 10 2 L * ?"></property>
? ?</bean>
? ?<!-- 3、設(shè)置調(diào)度工廠 -->
? ?<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
? ? ? ?<property name="triggers">
? ? ? ? ? ?<list>
? ? ? ? ? ? ? ?<ref bean="cronTrigger"/>
? ? ? ? ? ?</list>
? ? ? ?</property>
? ?</bean>
</beans>
查詢出未處理和是本月前的記錄,修改成是失效的。
? ?@Override ? ?public void doTask() { ? ? ? ?//查詢所有待受理的信息 ? ? ? ?QueryHelper queryHelper = new QueryHelper(Complain.class, "c"); ? ? ? ?queryHelper.addCondition(" ?c.state=?", Complain.COMPLAIN_STATE_UNDONE); ? ? ? ?//只要在本月之前 ? ? ? ?Calendar calendar = Calendar.getInstance(); ? ? ? ?calendar.set(Calendar.DAY_OF_MONTH, 1); ? ? ? ?calendar.set(Calendar.HOUR_OF_DAY, 0); ? ? ? ?calendar.set(Calendar.MINUTE, 0); ? ? ? ?calendar.set(Calendar.SECOND, 0); ? ? ? ?queryHelper.addCondition(" c.compTime <?", calendar.getTime()); ? ? ? ?//拿到本月之前所有未處理的數(shù)據(jù) ? ? ? ?List<Complain> complains = findObjects(queryHelper); ? ? ? ?//將數(shù)據(jù)全部改成是失效的了。 ? ? ? ?for (Complain complain : complains) { ? ? ? ? ? ?complain.setState(Complain.COMPLAIN_STATE_INVALID); ? ? ? ?} ? ?}}? ?public void doTask() {
? ? ? ?//查詢所有待受理的信息
? ? ? ?QueryHelper queryHelper = new QueryHelper(Complain.class, "c");
? ? ? ?queryHelper.addCondition(" ?c.state=?", Complain.COMPLAIN_STATE_UNDONE);
? ? ? ?//只要在本月之前
? ? ? ?Calendar calendar = Calendar.getInstance();
? ? ? ?calendar.set(Calendar.DAY_OF_MONTH, 1);
? ? ? ?calendar.set(Calendar.HOUR_OF_DAY, 0);
? ? ? ?calendar.set(Calendar.MINUTE, 0);
? ? ? ?calendar.set(Calendar.SECOND, 0);
? ? ? ?queryHelper.addCondition(" c.compTime <?", calendar.getTime());
? ? ? ?//拿到本月之前所有未處理的數(shù)據(jù)
? ? ? ?List<Complain> complains = findObjects(queryHelper);
? ? ? ?//將數(shù)據(jù)全部改成是失效的了。
? ? ? ?for (Complain complain : complains) {
? ? ? ? ? ?complain.setState(Complain.COMPLAIN_STATE_INVALID);
? ? ? ?}
? ?}
}
如果已經(jīng)失效了,那么我們就不讓管理員對其進行回復(fù)了。
? ? ?<s:if test="state!=2"> <a href="javascript:doDeal('<s:property value='compId'/>')">受理</a></s:if><a href="javascript:doDeal('<s:property value='compId'/>')">受理</a></s:if>這里寫圖片描述
統(tǒng)計圖Fusionchart
我們在投訴模塊中還有一個功能沒有實現(xiàn):
統(tǒng)計:根據(jù)年度將相應(yīng)年度的每個月的投訴數(shù)進行統(tǒng)計,并以圖表的形式展示在頁面中;在頁面中可以選擇查看當(dāng)前年度及其前4年的投訴數(shù)。在頁面中可以選擇不同的年度,然后頁面展示該年度的曲線統(tǒng)計圖。
我們到目前為止是沒有學(xué)過任何的統(tǒng)計圖的工具的,那么我們要怎么解決這個功能呢???我們有另外的組件來把統(tǒng)計圖顯示出來:FusionCharts
FusionCharts 是使用javascript 實現(xiàn)統(tǒng)計圖表的js組件;其官網(wǎng)地址:http://www.fusioncharts.com。
具體的是怎么操作的可以看官方文檔,我們以項目的需求來完成對應(yīng)的功能就行了。
FusionCharts使用
FusionCharts安裝
首先,我們要把對應(yīng)的JS文檔加入到我們的項目中:
引入Demo
我們只要根據(jù)修改Demo的值就可以實現(xiàn)出我們想要的效果了。
需求分析
再次回到我們的需求原型圖,我們看看是怎么樣的:
這里寫圖片描述根據(jù)不同的年份,就顯示出不同的統(tǒng)計圖數(shù)據(jù)…..這明顯就用到了ajax技術(shù)。 ?因此可以確定下來,我們的前端就是用ajax進行交互,渲染出對應(yīng)的統(tǒng)計圖的。
我們的后端就是根據(jù)不同的年份,去獲取不同的年份每個月的數(shù)據(jù),返回給瀏覽器…
前端分析
我們的需求是得讓我們顯示近5年的統(tǒng)計圖…于是下拉框是我們近5年的….
我們雖然是可以把option中的數(shù)據(jù)寫死,但是呢,如果過了一年的話,那么我們的數(shù)據(jù)是不會同步的。當(dāng)我在2017年寫的時候,到2018年,頁面顯示還是2017年的數(shù)據(jù)….所以這明顯是不合理的….
要想近5年是動態(tài)產(chǎn)生的,就不能夠把數(shù)據(jù)寫死….于是我們可以在JSP頁面上得到當(dāng)前年的值,根據(jù)當(dāng)前年就非常容易推出近5年的數(shù)據(jù)了…
于是我們又可以使用到Calendar這個日歷類了…
在JSP頁面得到當(dāng)前年的數(shù)據(jù),并裝載到list集合中
? ?Calendar calendar = Calendar.getInstance(); ? ?//得到當(dāng)前年的值 ? ?int ?year = calendar.get(Calendar.YEAR); ? ?//把年份用一個集合裝載 ? ?List yearList = new ArrayList(); ? ?//獲取近5年的值 ? ?for(int i =0; i<5; i++) { ? ? ? ?yearList.add(i, year--); ? ?} ? ?request.setAttribute("yearList", yearList); ? ?request.setAttribute("year", year);? ?//得到當(dāng)前年的值
? ?int ?year = calendar.get(Calendar.YEAR);
? ?//把年份用一個集合裝載
? ?List yearList = new ArrayList();
? ?//獲取近5年的值
? ?for(int i =0; i<5; i++) {
? ? ? ?yearList.add(i, year--);
? ?}
? ?request.setAttribute("yearList", yearList);
? ?request.setAttribute("year", year);
在Struts的select標(biāo)簽中把這個集合迭代出來
<s:select id="year" list="#request.yearList" onchange="doAnnualStatistic()"></s:select></s:select>下面是我們的效果:
這里寫圖片描述接著,我們發(fā)現(xiàn)FusionCharts這個組件,想要把數(shù)據(jù)顯示在統(tǒng)計圖表中,我們的JSON數(shù)據(jù)的格式是需要這樣的:
這里寫圖片描述還有值得注意的地方是,一進入頁面中需要加載當(dāng)前年度的投訴統(tǒng)計數(shù)
? ?<script> ? ? ? ?//頁面一加載就執(zhí)行方法 ? ? ? ?$(function () { ? ? ? ? ? ?doAnnualStatistic(); ? ? ? ?}); ? ? ? ?//根據(jù)年份獲取投訴數(shù) ? ? ? ?function doAnnualStatistic() { ? ? ? ? ? ?//獲取當(dāng)前年份 ? ? ? ? ? ?var $year = $("#year option:selected").val(); ? ? ? ? ? ?//一進來,如果沒有選擇任何的年數(shù),就顯示當(dāng)前年份的 ? ? ? ? ? ?if($year=="" || $year==undefined) { ? ? ? ? ? ? ? $year = "${year}"; ? ? ? ? ? ?} ? ? ? ? ? ?//2、統(tǒng)計年度投訴數(shù)據(jù)并展示圖表 ? ? ? ? ? ?$.ajax({ ? ? ? ? ? ? ? ?url: "${basePath}complain/complain_getAnnualStatisticData.action", ? ? ? ? ? ? ? ?type: "post", ? ? ? ? ? ? ? ?dataType: "json", ? ? ? ? ? ? ? ?data: {"year",$year}, ? ? ? ? ? ? ? ?success: function (backData) { ? ? ? ? ? ? ? ? ? ?if(backData!=null && backData!=""){ ? ? ? ? ? ? ? ? ? ? ? ?var revenueChart = new FusionCharts({ ? ? ? ? ? ? ? ? ? ? ? ? ? ?"type": "line", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"renderAt": "chartContainer", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"width": "600", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"height": "400", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataFormat": "json", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataSource": { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"chart": { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"caption": "年度統(tǒng)計投訴數(shù)", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xAxisName": "月 ? 份", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"yAxisName": "投 ?訴 數(shù)", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"theme": "fint" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"data":backData.chartData ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ?}); ? ? ? ? ? ? ? ? ? ? ? ?revenueChart.render(); ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ?error:function () { ? ? ? ? ? ? ? ? ? ?alert("統(tǒng)計投訴數(shù)失敗!"); ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}); ? ? ? ?} ? ?</script>? ? ? ?//頁面一加載就執(zhí)行方法
? ? ? ?$(function () {
? ? ? ? ? ?doAnnualStatistic();
? ? ? ?});
? ? ? ?//根據(jù)年份獲取投訴數(shù)
? ? ? ?function doAnnualStatistic() {
? ? ? ? ? ?//獲取當(dāng)前年份
? ? ? ? ? ?var $year = $("#year option:selected").val();
? ? ? ? ? ?//一進來,如果沒有選擇任何的年數(shù),就顯示當(dāng)前年份的
? ? ? ? ? ?if($year=="" || $year==undefined) {
? ? ? ? ? ? ? $year = "${year}";
? ? ? ? ? ?}
? ? ? ? ? ?//2、統(tǒng)計年度投訴數(shù)據(jù)并展示圖表
? ? ? ? ? ?$.ajax({
? ? ? ? ? ? ? ?url: "${basePath}complain/complain_getAnnualStatisticData.action",
? ? ? ? ? ? ? ?type: "post",
? ? ? ? ? ? ? ?dataType: "json",
? ? ? ? ? ? ? ?data: {"year",$year},
? ? ? ? ? ? ? ?success: function (backData) {
? ? ? ? ? ? ? ? ? ?if(backData!=null && backData!=""){
? ? ? ? ? ? ? ? ? ? ? ?var revenueChart = new FusionCharts({
? ? ? ? ? ? ? ? ? ? ? ? ? ?"type": "line",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"renderAt": "chartContainer",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"width": "600",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"height": "400",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataFormat": "json",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataSource": {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"chart": {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"caption": "年度統(tǒng)計投訴數(shù)",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xAxisName": "月 ? 份",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"yAxisName": "投 ?訴 數(shù)",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"theme": "fint"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"data":backData.chartData
? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ? ? ? ? ?revenueChart.render();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ?error:function () {
? ? ? ? ? ? ? ? ? ?alert("統(tǒng)計投訴數(shù)失敗!");
? ? ? ? ? ? ? ?}
? ? ? ? ? ?});
? ? ? ?}
? ?</script>
后端分析
我們的后端就是根據(jù)年份,獲取對應(yīng)的值,返回一個JSON格式給瀏覽器,那就行了…
但是呢,我們還有其他的細節(jié)需要考慮:今年是2017年7月,但是在查詢年度投訴數(shù)是要把整個年的信息查詢出來,8-12月的投訴數(shù)肯定是沒有的。那么我們會將還沒到的時間設(shè)置成“”,如果在2016年的某月是沒有投訴數(shù)的,我們應(yīng)該將其替換成0,而不是“"….
在action中,我們得獲取到用戶傳遞過來的年份,我們調(diào)用service、dao層的方法獲取該年度對應(yīng)每個月的投訴數(shù),轉(zhuǎn)換成JSON格式輸出就行了。
我們知道前端需要的JSON格式是一個對象數(shù)組,最終目的就是數(shù)組:Struts2框架在最后解析的時候,會把集合解析成是數(shù)組。對象數(shù)組在java編程語言就是List集合中嵌套著Map集合。
在后端中,還有一個難點,就是我們的SQL語句該怎么寫????我們要從數(shù)據(jù)庫查詢的是該年份每個月的投訴數(shù)….
通過該年而查詢每個月,我們可以很快地想到要用到分組查詢。但是還有一個問題,我們在進行分組查詢的時候,如果表中是沒有1月或2月等數(shù)組的話,分組查詢出來的數(shù)據(jù)是沒有這些月份的。而我們的統(tǒng)計圖是需要所有月份的數(shù)據(jù)的。咋看一下,我們是需要把查詢出來的數(shù)據(jù)做循環(huán)判斷,得看看有沒有該月份,如果沒有該月份還得把數(shù)據(jù)填充進去。。還得判斷該月份是不是本年度的….這樣想一下就覺得麻煩了……
select month(comp_time) as '月份',count(*) '總數(shù)'from complainwhere year(comp_time)=?group by month(comp_time)month(comp_time) as '月份',count(*) '總數(shù)'from complain
where year(comp_time)=?
group by month(comp_time)
這里寫圖片描述
再次回到前面分析的,如果本年度的月份還沒有到,那么將該月的數(shù)據(jù)設(shè)置為“”,如果是其他年份的的月份查出的數(shù)據(jù)為null,那么我們應(yīng)該把這些月份的投訴數(shù)設(shè)置為0而不是”“…..
但是呢,我們現(xiàn)在有一個辦法,可以在查詢的時候,不管該月份有沒有數(shù)據(jù),都得顯示出來….這就是左外連接
于是我們自己手動生成一張擁有12個月份的數(shù)據(jù)表,跟我們的投訴表進行左外連接…
這里寫圖片描述 ? ?select imonth, count(comp_id) ? ?from t_month left join complain on imonth=month(comp_time) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?and year(comp_time)=2017 ? ?group by imonth ? ?order by imonth;count(comp_id)? ?from t_month left join complain on imonth=month(comp_time)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?and year(comp_time)=2017
? ?group by imonth
? ?order by imonth;
這里寫圖片描述
上面的sql語句的查詢效率是有點低的,我們改造一下,改成是子查詢:
select imonth,c2from t_month left join (select month(comp_time) c1, count(comp_id) c2 from complain where year(comp_time)=? group by month(comp_time)) ton imonth = c1order by imonth;from t_month left join (select month(comp_time) c1, count(comp_id) c2 from complain where year(comp_time)=? group by month(comp_time)) t
on imonth = c1
order by imonth;
代碼實現(xiàn)
dao層根據(jù)年份查詢出每個月份的投訴數(shù)據(jù)
? ?/** ? ? * ? ? * @param year 根據(jù)年獲取數(shù)據(jù) ? ? * @return ?返回的是一個列表數(shù)組 ? ? */ ? ?@Override ? ?public List<Object[]> getAnnualStatisticByYear(int year) { ? ? ? ?//拼接SQL語句 ? ? ? ?StringBuffer buffer = new StringBuffer(); ? ? ? ?buffer.append(" SELECT imonth,c2 ") ? ? ? ?.append(" FROM t_month") ? ? ? ?.append(" LEFT JOIN (SELECT month(comp_time) c1, count(comp_id) c2 FROM complain WHERE YEAR(comp_time)=? GROUP BY MONTH(comp_time)) t") ? ? ? ?.append(" ON imonth = c1") ? ? ? ?.append(" ORDER BY imonth;"); ? ? ? ?SQLQuery sqlQuery = getSession().createSQLQuery(buffer.toString()); ? ? ? ?sqlQuery.setParameter(0, year); ? ? ? ?List<Object[]> list = sqlQuery.list(); ? ? ? ?return list; ? ?}? ?
? ?public List<Object[]> getAnnualStatisticByYear(int year) {
? ? ? ?//拼接SQL語句
? ? ? ?StringBuffer buffer = new StringBuffer();
? ? ? ?buffer.append(" SELECT imonth,c2 ")
? ? ? ?.append(" FROM t_month")
? ? ? ?.append(" LEFT JOIN (SELECT month(comp_time) c1, count(comp_id) c2 FROM complain WHERE YEAR(comp_time)=? GROUP BY MONTH(comp_time)) t")
? ? ? ?.append(" ON imonth = c1")
? ? ? ?.append(" ORDER BY imonth;");
? ? ? ?SQLQuery sqlQuery = getSession().createSQLQuery(buffer.toString());
? ? ? ?sqlQuery.setParameter(0, year);
? ? ? ?List<Object[]> list = sqlQuery.list();
? ? ? ?return list;
? ?}
service層拿到Dao層的數(shù)據(jù),判斷是否是本年度的,如果是本年度的,那么還沒有到的月份的數(shù)據(jù)就設(shè)置為”“,如果已經(jīng)過的了月份,如果沒有數(shù)據(jù)就設(shè)置為0.
返回一個List集合嵌套著Map集合,就可以給前臺解析了。
? ?@Override ? ?public List getAnnualStatisticByYear(int year) { ? ? ? ?List<Object[]> annualStatisticByYear = complainDao.getAnnualStatisticByYear(year); ? ? ? ?List<Map> returnList = new ArrayList<>(); ? ? ? ?//得到本年度和本月份 ? ? ? ?int curYear = Calendar.getInstance().get(Calendar.YEAR); ? ? ? ?//Calerdar月份從0開始, ? ? ? ?int curMonth = Calendar.getInstance().get(Calendar.MONTH)+1; ? ? ? ?//使用Map集合裝載著數(shù)據(jù) ? ? ? ?Map<String,Object> map = null; ? ? ? ?for (Object[] objects : annualStatisticByYear) { ? ? ? ? ? ?map = new HashedMap(); ? ? ? ? ? ?//得到月份 ? ? ? ? ? ?Integer month = Integer.valueOf(objects[0] + ""); ? ? ? ? ? ?map.put("label", month + "月"); ? ? ? ? ? ?if (curYear == year) { //是本年度,那么看看月份是否大于本月份 ? ? ? ? ? ? ? ?if (month > curMonth) { ? ? ? ? ? ? ? ? ? ?//將數(shù)據(jù)設(shè)置為"" ? ? ? ? ? ? ? ? ? ?map.put("value", ""); ? ? ? ? ? ? ? ?} else { ? ? ? ? ? ? ? ? ? ?if (objects[1] != null) { ? ? ? ? ? ? ? ? ? ? ? ?map.put("value", objects[1]); ? ? ? ? ? ? ? ? ? ?} else { ? ? ? ? ? ? ? ? ? ? ? ?map.put("value", "0"); ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}else {//不是本年度 ? ? ? ? ? ? ? ?if (objects[1] != null) { ? ? ? ? ? ? ? ? ? ?map.put("value", objects[1]); ? ? ? ? ? ? ? ?} else { ? ? ? ? ? ? ? ? ? ?map.put("value", "0"); ? ? ? ? ? ? ? ?} ? ? ? ? ? ?} ? ? ? ? ? ?returnList.add(map); ? ? ? ?} ? ? ? ?return returnList; ? ?}? ?public List getAnnualStatisticByYear(int year) {
? ? ? ?List<Object[]> annualStatisticByYear = complainDao.getAnnualStatisticByYear(year);
? ? ? ?List<Map> returnList = new ArrayList<>();
? ? ? ?//得到本年度和本月份
? ? ? ?int curYear = Calendar.getInstance().get(Calendar.YEAR);
? ? ? ?//Calerdar月份從0開始,
? ? ? ?int curMonth = Calendar.getInstance().get(Calendar.MONTH)+1;
? ? ? ?//使用Map集合裝載著數(shù)據(jù)
? ? ? ?Map<String,Object> map = null;
? ? ? ?for (Object[] objects : annualStatisticByYear) {
? ? ? ? ? ?map = new HashedMap();
? ? ? ? ? ?//得到月份
? ? ? ? ? ?Integer month = Integer.valueOf(objects[0] + "");
? ? ? ? ? ?map.put("label", month + "月");
? ? ? ? ? ?if (curYear == year) { //是本年度,那么看看月份是否大于本月份
? ? ? ? ? ? ? ?if (month > curMonth) {
? ? ? ? ? ? ? ? ? ?//將數(shù)據(jù)設(shè)置為""
? ? ? ? ? ? ? ? ? ?map.put("value", "");
? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ?if (objects[1] != null) {
? ? ? ? ? ? ? ? ? ? ? ?map.put("value", objects[1]);
? ? ? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ? ? ?map.put("value", "0");
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}else {//不是本年度
? ? ? ? ? ? ? ?if (objects[1] != null) {
? ? ? ? ? ? ? ? ? ?map.put("value", objects[1]);
? ? ? ? ? ? ? ?} else {
? ? ? ? ? ? ? ? ? ?map.put("value", "0");
? ? ? ? ? ? ? ?}
? ? ? ? ? ?}
? ? ? ? ? ?returnList.add(map);
? ? ? ?}
? ? ? ?return returnList;
? ?}
action層把service層的數(shù)據(jù)封裝到Map集合中,嵌套ajax解析Map集合,得到的就是對象數(shù)組了。
? ?//返回JSON格式的數(shù)據(jù),這里我們就直接用Struts2框架來返回對應(yīng)的數(shù)據(jù)就行了。 ? ?public String getAnnualStatisticData() { ? ? ? ?//獲取用戶傳遞過來的年份 ? ? ? ?String str_year = ServletActionContext.getRequest().getParameter("year"); ? ? ? ?if (str_year != null) { ? ? ? ? ? ?int year = Integer.valueOf(str_year); ? ? ? ? ? ?//根據(jù)年份去獲取每個月的投訴數(shù) ? ? ? ? ? ?map.put("msg", "success"); ? ? ? ? ? ?map.put("chartData", complainServiceImpl.getAnnualStatisticByYear(year)); ? ? ? ?} ? ? ? ?return "getAnnualStatisticData"; ? ?}? ?public String getAnnualStatisticData() {
? ? ? ?//獲取用戶傳遞過來的年份
? ? ? ?String str_year = ServletActionContext.getRequest().getParameter("year");
? ? ? ?if (str_year != null) {
? ? ? ? ? ?int year = Integer.valueOf(str_year);
? ? ? ? ? ?//根據(jù)年份去獲取每個月的投訴數(shù)
? ? ? ? ? ?map.put("msg", "success");
? ? ? ? ? ?map.put("chartData", complainServiceImpl.getAnnualStatisticByYear(year));
? ? ? ?}
? ? ? ?return "getAnnualStatisticData";
? ?}
前臺把年份提交給Action,解析出后臺返回的數(shù)據(jù),渲染成折線圖….
function doAnnualStatistic() { ? ? ? ? ? ?//獲取當(dāng)前年份 ? ? ? ? ? ?var $year = $("#year option:selected").val(); ? ? ? ? ? ?//一進來,如果沒有選擇任何的年數(shù),就顯示當(dāng)前年份的 ? ? ? ? ? ?if($year=="" || $year==undefined) { ? ? ? ? ? ? ? $year = "${year}"; ? ? ? ? ? ?} ? ? ? ? ? ?//2、統(tǒng)計年度投訴數(shù)據(jù)并展示圖表 ? ? ? ? ? ?$.ajax({ ? ? ? ? ? ? ? ?url: "${basePath}complain/complain_getAnnualStatisticData.action", ? ? ? ? ? ? ? ?type: "post", ? ? ? ? ? ? ? ?dataType: "json", ? ? ? ? ? ? ? ?data: {"year":$year}, ? ? ? ? ? ? ? ?success: function (backData) { ? ? ? ? ? ? ? ? ? ?if(backData!=null && backData!=""){ ? ? ? ? ? ? ? ? ? ? ? ?var revenueChart = new FusionCharts({ ? ? ? ? ? ? ? ? ? ? ? ? ? ?"type": "line", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"renderAt": "chartContainer", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"width": "600", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"height": "400", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataFormat": "json", ? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataSource": { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"chart": { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"caption": "年度統(tǒng)計投訴數(shù)", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xAxisName": "月 ? 份", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"yAxisName": "投 ?訴 數(shù)", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"theme": "fint" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"data":backData.chartData ? ? ? ? ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ? ? ? ? ?}); ? ? ? ? ? ? ? ? ? ? ? ?revenueChart.render(); ? ? ? ? ? ? ? ? ? ?} ? ? ? ? ? ? ? ?}, ? ? ? ? ? ? ? ?error:function () { ? ? ? ? ? ? ? ? ? ?alert("統(tǒng)計投訴數(shù)失敗!"); ? ? ? ? ? ? ? ?} ? ? ? ? ? ?}); ? ? ? ?}? ? ? ? ? ?//獲取當(dāng)前年份
? ? ? ? ? ?var $year = $("#year option:selected").val();
? ? ? ? ? ?//一進來,如果沒有選擇任何的年數(shù),就顯示當(dāng)前年份的
? ? ? ? ? ?if($year=="" || $year==undefined) {
? ? ? ? ? ? ? $year = "${year}";
? ? ? ? ? ?}
? ? ? ? ? ?//2、統(tǒng)計年度投訴數(shù)據(jù)并展示圖表
? ? ? ? ? ?$.ajax({
? ? ? ? ? ? ? ?url: "${basePath}complain/complain_getAnnualStatisticData.action",
? ? ? ? ? ? ? ?type: "post",
? ? ? ? ? ? ? ?dataType: "json",
? ? ? ? ? ? ? ?data: {"year":$year},
? ? ? ? ? ? ? ?success: function (backData) {
? ? ? ? ? ? ? ? ? ?if(backData!=null && backData!=""){
? ? ? ? ? ? ? ? ? ? ? ?var revenueChart = new FusionCharts({
? ? ? ? ? ? ? ? ? ? ? ? ? ?"type": "line",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"renderAt": "chartContainer",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"width": "600",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"height": "400",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataFormat": "json",
? ? ? ? ? ? ? ? ? ? ? ? ? ?"dataSource": {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"chart": {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"caption": "年度統(tǒng)計投訴數(shù)",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"xAxisName": "月 ? 份",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"yAxisName": "投 ?訴 數(shù)",
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"theme": "fint"
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?"data":backData.chartData
? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?});
? ? ? ? ? ? ? ? ? ? ? ?revenueChart.render();
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ?},
? ? ? ? ? ? ? ?error:function () {
? ? ? ? ? ? ? ? ? ?alert("統(tǒng)計投訴數(shù)失敗!");
? ? ? ? ? ? ? ?}
? ? ? ? ? ?});
? ? ? ?}
總結(jié)
如果文章有錯的地方歡迎指正,大家互相交流。習(xí)慣在微信看技術(shù)文章,想要獲取更多的Java資源的同學(xué),可以關(guān)注微信公眾號:Java3y
總結(jié)
以上是生活随笔為你收集整理的纳税服务系统七(投诉管理模块)【显示投诉信息、处理回复、我要投诉、Quartz自动受理、统计图FusionCharts】...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 路由记录文件,Linux路由
- 下一篇: 对网站的疑惑