- 浏览: 17126 次
- 性别:
- 来自: 北京
最新评论
收藏列表
- 全部 [10]
- 默认 [1]
- js [2]
- js ajax [1]
- html框架 [1]
- java 统计组件 [1]
- jdbc hibernate java [1]
- xml解析 java [2]
- js jq [1]
标题 | 标签 | 来源 | |
js判断日期是否为所在月月末 | js | ||
思路:取日期的下一天,判断取得日期的月份是否与当前日期所在月相同,如相同则不是月末 function isLastDay(inputDate) { var d = new Date(inputDate.replace(/\-/,"/")); var nd = new Date(d.getTime()+24*60*60*1000); return (d.getMonth()!=nd.getMonth()) } |
|||
window.location.href的target控制 | html框架 | ||
window.location.href的target控制 window.location.href的target控制 在使用框架时,经常会对框架子页面进行页面引导的情况,如果只是简单的设置location. href="",会使得整个页面显示在子框架中,导致出现重叠框架。如何解决呢?很简单。只要指定子框架的父级框架页面链接至目标页面即可。如 window.top.framename.location.href = url; window.parent.location.href=url; mainframe.location.href=url; |
|||
dat处理JS | js | ||
//判断输入的内容是否为日期格式 function checkDateFormate(Field) { var inputDateValue = Field.value; var desc = Field.description; if(inputDateValue == null || inputDateValue == '') { return false; } //获取输入字符串的长度 var inputValueLength = inputDateValue.length; //如果满足下面判断的所有条件才算合法的日期,否则不合法 if(checkNumeric(inputDateValue) && checkLegth(inputValueLength) && checkSpecialChar(inputDateValue) ) { return true; }else { errorMessage("请输入合法的" + desc +"\n类型为日期,格式为YYYY-MM-DD 或者YYYYMMDD"); Field.focus(); return false; } } //日期只能是8~10位 function checkLegth(length) { if(length < 8 || length > 10) { return false; } return true; } //如果输入的内容中包含‘-’,则按照‘-’分割来去年月日,否则直接按照位数取 function checkSpecialChar(inputDateValue) { var index = inputDateValue.indexOf('-'); var year = 0; var month = 0; var day = 0; if(index > -1) { var lastIndex = inputDateValue.lastIndexOf('-'); //只能是YYYY-M-DD或者YYYY-MM-DD的形式 if(lastIndex - index < 1 || lastIndex - index > 3) { return false; } var arrDate = inputDateValue.split('-'); year = arrDate[0]; month = arrDate[1]; day = arrDate[2]; } else { year = inputDateValue.substring(0,4); month = inputDateValue.substring(4,6); day = inputDateValue.substring(6,8); } if(Number(month) > 12 || Number(day) > 31 ||Number(month)<1 || Number(day)<1 || year.length != 4) { return false; } else if(day > getLastDayOfMonth(Number(year),Number(month))) { return false; } return true; } //判断输入的内容将‘-’替换成为数字1后,是否全部为数字 function checkNumeric(inputDateValue) { var replacedValue = inputDateValue.replace(/-/g,'1'); return isNumeric(replacedValue); } //判断是否为数字 function isNumeric(strValue) { var result = regExpTest(strValue,/\d*[.]?\d*/g); return result; } function regExpTest(source,re) { var result = false; if(source==null || source=="") return false; if(source==re.exec(source)) result = true; return result; } //获得一个月中的最后一天 function getLastDayOfMonth(year,month){ var days=0; switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: days=31;break; case 4: case 6: case 9: case 11: days=30;break; case 2: if(isLeapYear(year)) days=29;else days=28;break; } return days; } //判断是否为闰年 function isLeapYear(year){ if((year %4==0 && year %100!=0) || (year %400==0)) return true; else return false; } |
|||
js通用方法 | |||
<script language="javascript"> //新增初始日期方法 liangbo 20130517 function initDate() { var tDate = new Date(); y = tDate.getFullYear(); m = tDate.getMonth() + 1 + ""; M = m.length > 1 ? m : "0" + m; d = tDate.getDate()+""; D = d.length > 1 ? d : "0" + d; var dtpStr = y + "-" + M + "-" + D; alert(dtpStr); DataRq2.value = dtpStr; DataRq1.value = dtpStr; dtpYw.value = dtpStr; dtpRq.value = dtpStr; } </script> /// 格式化显示日期时间 /// </summary> /// <param name="x">待显示的日期时间,例如new Date()</param> /// <param name="y">需要显示的格式,例如yyyy-MM-dd hh:mm:ss</param> function date2str(x,y) { var z = {M:x.getMonth()+1,d:x.getDate(),h:x.getHours(),m:x.getMinutes(),s:x.getSeconds()}; y = y.replace(/(M+|d+|h+|m+|s+)/g,function(v) {return ((v.length>1?"0":"")+eval('z.'+v.slice(-1))).slice(-2)}); return y.replace(/(y+)/g,function(v) {return x.getFullYear().toString().slice(-v.length)}); } //alert(date2str(new Date(),"yyyy-MM-dd hh:mm:ss")); //alert(date2str(new Date(),"yyyy-M-d h:m:s")); </script> 详细出处参考:http://www.jb51.net/article/35509.htm |
|||
web开发中前、后端常用数据处理方法整理 | js jq | web开发中前、后端常用数据处理方法整理 | |
------------------------- 前端 /** * 前端公共函数方法整理 * @author Weige * 备注: 配合jqury.js 使用 * 2012-04 */ //获取字符串长度 function getWordSize(str) { if(!str) return null; var length = 0; var str = str; var regDoub = /[^x00-xff]/g; var regSingl = /[x00-xff]/g var douL = str.match(regDoub); var singL = str.match(regSingl) if(douL){ length+=douL.length*2; } if(singL){ length+=singL.length; } length/=2; length = Math.ceil(length); return length; } //祛除前后空格 function trim(str) { return str.replace(/(^\s*)|(\s*$)/g, ''); } //中文汉字编码判断 function isChinese(str) { var str = str.replace(/(^\s*)|(\s*$)/g,''); if (!(/^[\u4E00-\uFA29]*$/.test(str) && (!/^[\uE7C7-\uE7F3]*$/.test(str)))) { return false; } return true; } //手机判断 function isMobile(str) { if(/^1[345689]\d{9}/.test(str)) { return true; } return false; } // oschina //特殊字符转换 function htmlEncode(str) { var s = ""; if (str.length == 0) return ""; //s = s.replace(/ /g, " "); s = str.replace(/&/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/\'/g, "'"); s = s.replace(/\"/g, """); s = s.replace(/\n/g, "<br>"); return s; } function htmlDecode(str) { var s = ""; if (str.length == 0) return ""; s = str.replace(/>/g, "&"); s = s.replace(/</g, "<"); s = s.replace(/>/g, ">"); s = s.replace(/ /g, " "); s = s.replace(/'/g, "\'"); s = s.replace(/"/g, "\""); s = s.replace(/<br>/g, "\n"); return s; } //使用ajax提交数据 function ajaxPost(the_url,the_param,succ_callback) { $.ajax({ type : 'POST', cache : false, url : the_url, data : the_param, success : succ_callback }); } //使用ajax获取数据 function ajaxGet(the_url,succ_callback,error_callback) { $.ajax({ type : 'GET', cache : true, url : the_url, success : succ_callback, error : error_callback }); } //发送json格式数据 function ajaxPostJson(the_url,data_pro,succ_callback,error_callback) { $.ajax({ async : false,//同步更新 type : 'post', dataType : 'json', data : data_pro, url : the_url, success : succ_callback, error : error_callback }); } function real_len(name) { return (name.replace(/[^\x00-\xff]/g,"**").length); } function is_email(email) { var reg=/^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/; return reg.test(email); } function is_number(name) { var reg = /^\d+$/g; return reg.test(name); } function is_pwd(name) { var reg = /^[A-Za-z@0-9_-]+$/g; return reg.test(name); } ---------------------------------后端 <?php /** * Weige * 2012-05 * */ /** * 唯一名字 * */ function get_unique_name($srand_id=0) { $id = $srand_id?$srand_id:mt_rand(0,99999999); $index = 'z6OmlGsC9xqLPpN7iw8UDAb4HIBXfgEjJnrKZSeuV2Rt3yFcMWhakQT1oY5v0d'; $base = 62; $out = ""; for ( $t = floor( log10( $id ) / log10( $base ) ); $t >= 0; $t-- ) { $a = floor( $id / pow( $base, $t ) ); $out = $out . substr( $index, $a, 1 ); $id = $id - ( $a * pow( $base, $t ) ); } return $out; } /** * 短链接密钥 * */ function url_key($url,$key="wei爱微博") { $x = sprintf("%u", crc32($key.$url)); $show = ''; while($x> 0) { $s = $x% 62; if($s> 35) $s = chr($s+61); elseif($s> 9 && $s<=35) $s = chr($s+ 55); $show.= $s; $x = floor($x/62); } return $show; } /** * 标签key * */ function tag_key($tag,$key="wei爱话题") { $tag = str_replace(" ", "", $tag); $tag.= $key; $hash = md5($tag); $hash = $hash[0] | ($hash[1] <<8 ) | ($hash[2] <<16) | ($hash[3] <<24) | ($hash[4] <<32) | ($hash[5] <<40) | ($hash[6] <<48) | ($hash[7] <<56); return $hash % 99999999; } /** * 过滤非法标签 * */ function strip_selected_tags($str,$disallowable="<script><iframe><style><link>") { $disallowable = trim(str_replace(array(">","<"),array("","|"),$disallowable),'|'); $str = str_replace(array('<', '>'),array('<', '>'),$str); $str = preg_replace("~<({$disallowable})[^>]*>(.*?<\s*\/(\\1)[^>]*>)?~is",'$2',$str); return $str; } /** * 替换或转义标签 * */ function convert_tags($str) { if($str) // $str = str_replace(array('&','<', '>',"'",'"'),array('&','<', '>',''','"'),$str); $str = str_replace(array('<', '>',"'",'"'),array('<', '>',''','"'),$str); return $str; } // function jstrpos($haystack, $needle, $offset = null) // { // $needle = trim($needle); // $jstrpos = false; // if(function_exists('mb_strpos')) // { // $jstrpos = mb_strpos($haystack, $needle, $offset, self::$charset); // } // elseif(function_exists('strpos')) // { // $jstrpos = strpos($haystack, $needle, $offset); // } // return $jstrpos; // } /** * 检查是否为一个http开头并带有.com的url地址 **/ function is_http($url) { if(filter_var($url, FILTER_VALIDATE_URL)) return true;return false; } /** * 发送一个http请求 * @param $url 请求链接 * @param $method 请求方式 * @param array $vars 请求参数 * @param $time_out 请求过期时间 * @return JsonObj */ function get_curl($url, array $vars=array(), $method = 'post') { $method = strtolower($method); if($method == 'get' && !empty($vars)) { if(strpos($url, '?') === false) $url = $url . '?' . http_build_query($vars); else $url = $url . '&' . http_build_query($vars); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if ($method == 'post') { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $vars); } $result = curl_exec($ch); if(!curl_errno($ch)) { $result = trim($result); } else { $result = '[error:1]'; } curl_close($ch); return $result; } /** * 获取客户端ip * */ function getIp() { if (isset($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } else if (isset($_SERVER['REMOTE_ADDR'])) { return $_SERVER['REMOTE_ADDR']; } return '0.0.0'; } /** * 图片大小验证器 * $_FILES['file']数组 * * 只支持 jpg png gif 格式 默认5M * */ function check_img($file,$limitSize=5242880) { $type_maping = array(1=>'image/gif', 2=>'image/jpeg', 3=>'image/png',4=>'image/pjpeg',5=>'image/x-png',6=>'image/jpg'); if($file['size']>$limitSize) { $rs['error'] = '1'; $rs['msg'] = '图片超过规定大小!'; } elseif($file['error']==4) { $rs['error'] = '1'; $rs['msg'] = '图片文件损害!'; } elseif($file['size']==0) { $rs['error'] = '1'; $rs['msg'] = '空图片或者超过规定大小'; } elseif( !in_array($file['type'],$type_maping) ) { $rs['error'] = '1'; $rs['msg'] = '图片类型错误!'; } else { $rs['error'] = 'no'; $rs['msg'] = 'success'; } return $rs; } /** * 递归方式的对变量中的特殊字符进行转义以及过滤标签 */ function addslashes_deep($value) { if (empty($value))return $value; //Huige 过滤html标签,防止sql注入 return is_array($value) ? array_map('addslashes_deep', $value) : strip_tags(addslashes($value)); } /** * @param mix $value * @return mix */ function stripslashes_deep($value) { if (empty($value))return $value; return is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); } /** * 以新浪微博的字数统计方式统计字数(简单版) * 中文算1个,英文算0.5个,全角字符算1个,半角字符算0.5个。 * @param string $string * @return integer */ function strlen_weibo($string) { if(is_string($string)) { $string=trim(trim($string,' ')); return (strlen($string) + mb_strlen($string,'UTF-8')) / 4; } return false; } /** * 截取指定长度的字符串,超出部分用 ..替换 * @param string $text * @param int $length * @param string $replace * @param string $encoding */ function substr_format($text, $length, $replace='..', $encoding='UTF-8') { if ($text && mb_strlen($text, $encoding)>$length) { return mb_substr($text, 0, $length, $encoding).$replace; } return $text; } /** * * 字符编码转换 * * */ function xwb_iconv($source, $in, $out) { $in = strtoupper($in); $out = strtoupper($out); if ($in == "UTF8"){ $in = "UTF-8"; } if ($out == "UTF8"){ $out = "UTF-8"; } if($in==$out){ return $source; } if(function_exists('mb_convert_encoding')) { return mb_convert_encoding($source, $out, $in ); }elseif (function_exists('iconv')) { return iconv($in,$out."//IGNORE", $source); } return $source; } /** * Created: 2010-10-28 * * 截取一定长度的字符串 * @Author guoliang1 * ***************************************************/ function cut_string($str, $len) { // 检查长度 if (mb_strwidth($str, 'UTF-8')<=$len) { return $str; } // 截取 $i = 0; $tlen = 0; $tstr = ''; while ($tlen < $len) { $chr = mb_substr($str, $i, 1, 'UTF-8'); $chrLen = ord($chr) > 127 ? 2 : 1; if ($tlen + $chrLen > $len) break; $tstr .= $chr; $tlen += $chrLen; $i ++; } if ($tstr != $str) { $tstr .= '...'; } return $tstr; } /** * Created: 2010-10-28 * * 防止XSS攻击,htmlspecialchars的别名 * ***************************************************/ function escape($str, $quote_style = ENT_COMPAT ) { return htmlspecialchars($str, $quote_style); } /** * 格式化时间 * * */ function wb_date_format($time,$format='m月d日 H:i') { $now = time(); $t = $now - $time; if($t >= 3600) { if(date('Y')==date('Y',$time)) $time =date($format,$time); else $time =date('Y年m月d日 H:i',$time); } elseif ($t < 3600 && $t >= 60) $time = floor($t / 60) . "分钟前"; else $time = "刚刚"; return $time; } function isChinese($string) { if(preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$string)) return true; return false; } function isMobile($mobile) { if(preg_match("/^1[345689]\d{9}$/", $mobile)) return true; return false; } function dayToWeek($time) { $time = empty($time) ? TIME : $time; $date[0] = '周日'; $date[1] = '周一'; $date[2] = '周二'; $date[3] = '周三'; $date[4] = '周四'; $date[5] = '周五'; $date[6] = '周六'; return $date[Date('w',$time)]; } /** * 检测是否为邮箱 * @param $val * @param $domain * @return boolean */ function is_email($val,$domain="") { if(!$domain) { if( preg_match("/^[a-z0-9-_.]+@[\da-z][\.\w-]+\.[a-z]{2,4}$/i", $val) ) return TRUE; return FALSE; } if( preg_match("/^[a-z0-9-_.]+@".$domain."$/i", $val) ) return TRUE; return FALSE; } // junz先生 //http://www.oschina.net/code/snippet_162279_7186 //可逆加密 function extend_decrypt($encryptedText,$key) { $cryptText = base64_decode($encryptedText); $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND); $decryptText = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $cryptText, MCRYPT_MODE_ECB, $iv); return trim($decryptText); } //http://www.oschina.net/code/snippet_162279_7186 //可逆解密 function extend_encrypt($plainText,$key) { $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB); $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND); $encryptText = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $plainText, MCRYPT_MODE_ECB, $iv); return trim(base64_encode($encryptText)); } ?> |
|||
无刷新异步提交表单 | js ajax | ||
<script type="text/javascript"> //为id为tXxSet的按钮绑定事件处理函数 liangbo 04/06/2012 $("#tXxSet").click(function() { //指定向loginPro发送请求,以id为xmlDownload表单里各表单控件作为请求参数 $.get("sfrXxXMLAction!thSet.action" , $("#xmlDownload").serializeArray() , //指定回调函数 function(data , statusText) { alert(data); }, //指定服务器响应为html "html"); }); </script> |
|||
xml导出 | xml解析 java | ||
package com.css.action; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import org.apache.struts2.ServletActionContext; import org.dom4j.Document; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.css.bean.VXfSfrDj; import com.css.business.QueryBusiness; import com.css.common.action.BaseAction; import com.css.common.util.DateUtils; import com.css.common.util.QueryUtils; import com.css.common.util.StringUtils; import com.css.common.util.dicache.Authority; import com.css.dto.TXfSfrDTO; import com.css.dto.TXtYhDTO; import com.css.dto.VXfZhDTO; import com.css.service.SfWtService; import com.css.service.ZhQueryService; import com.css.util.ConstantParam; import com.css.bean.TXtJg; import com.css.bean.VXfZh; /** * @function 上访人信息XML文件导出 * @description 从数据库导出数据生成XML文件 * @version 1.0 * @author liangbo * @time 22/05/2012 * @modify by liangbo time at 25/05/2012 新增xml导出数据头文件从系统配置读取数据功能 * @modify by liangbo time at 30/05/2012 新增交办地区交办单位批量设置功能 */ @Controller("sfrXxXMLAction") @Scope("prototype") public class SfrXxXMLAction extends BaseAction { @Resource private ZhQueryService zhQueryService; @Resource private QueryBusiness queryBusiness; @Resource private SfWtService sfWtService; private String relation; private VXfZhDTO vxfZhDTO; // 综合查询DTO private List<VXfZhDTO> excelList; private List<TXfSfrDTO> sfrList;// 上访人列表 //liangbo 30/05/2012 private String thdqid; private String thdwid; public List<TXfSfrDTO> getSfrList() { return sfrList; } public void setSfrList(List<TXfSfrDTO> sfrList) { this.sfrList = sfrList; } private InputStream istream;// 下载输入流 private String downloadFileName = "信访人信访问题信息汇总(" + DateUtils.formatDate2Str(DateUtils.FORMAT_YYYYMMDD_HHMMSS_ZN, new Date()) + ")"; private String[] checkedIds; private String[] curIds; public InputStream getIstream() { return istream; } public void setIstream(InputStream istream) { this.istream = istream; } public String[] getCheckedIds() { return checkedIds; } public void setCheckedIds(String[] checkedIds) { this.checkedIds = checkedIds; } public String[] getCurIds() { return curIds; } public void setCurIds(String[] curIds) { this.curIds = curIds; } public String getDownloadFileName() { try { downloadFileName = new String(downloadFileName.getBytes(), "ISO8859-1"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return downloadFileName; } public String download() throws Exception { Set<String> idSet = (Set<String>) ServletActionContext.getRequest().getSession().getAttribute("idSet"); if (idSet != null) { if (curIds != null && curIds.length != 0) { for (String s : curIds) { if (idSet.contains(s)) { idSet.remove(s); } } } if (checkedIds != null && checkedIds.length != 0) { for (String s : checkedIds) { idSet.add(s); } } int i = 0; String[] temp = new String[idSet.size()]; for (String string : idSet) { temp[i] = string; i++; } checkedIds = temp; } Map<VXfZhDTO, Set<VXfSfrDj>> sfrwtMap = null; if (checkedIds != null && checkedIds.length != 0) { sfrwtMap = zhQueryService.getsfrsfwt(checkedIds); } else { addActionMessage("请选择需要导出的数据!!"); return SUCCESS; } //导出数据前对交办单位交办地区进行判重判空 Set<VXfZhDTO> keySet = sfrwtMap.keySet(); List dqdwList = checkDqDw(keySet); if(dqdwList == null || dqdwList.size() <=0) { addActionMessage("导出失败!"); return SUCCESS; } if (sfrwtMap.size() != 0) { istream = new ByteArrayInputStream(createXML(sfrwtMap,dqdwList)); } return "download"; } //批量设置数据 public void thSet() throws Exception { PrintWriter out = null; ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); out = ServletActionContext.getResponse().getWriter(); Set<String> idSet = (Set<String>) ServletActionContext.getRequest().getSession().getAttribute("idSet"); if(thdqid == null || thdqid.equals("")) { out.print("请录入交办地区!"); return ; } if(thdwid == null || thdwid.equals("")) { out.print("请录入交办单位!"); return; } if (idSet != null) { if (curIds != null && curIds.length != 0) { for (String s : curIds) { if (idSet.contains(s)) { idSet.remove(s); } } } if (checkedIds != null && checkedIds.length != 0) { for (String s : checkedIds) { idSet.add(s); } } int i = 0; String[] temp = new String[idSet.size()]; for (String string : idSet) { temp[i] = string; i++; } checkedIds = temp; } List<VXfZh> zhList = null; if (checkedIds != null && checkedIds.length != 0) { zhList = zhQueryService.getlList(checkedIds); } else { out.print("请选择需要设置的数据!"); return; } if(zhList != null || zhList.size() > 0) { for(VXfZh vXfZh : zhList) { sfWtService.updateTh(vXfZh.getWtid(), thdqid, thdwid); } } out.print("设置成功!"); return; } public byte[] createXML(Map<VXfZhDTO, Set<VXfSfrDj>> sfrwtMap, List dqdwList) { //获得当前会话的用户 TXtYhDTO yhDTO = (TXtYhDTO)session.get(ConstantParam.USER_SESSION_KEY); //根据用户获取系统组织配置 TXtJg txtJg = zhQueryService.findJg(yhDTO.getId()); if(txtJg == null) { return null; } byte[] xmlString = null; Document document = DocumentHelper.createDocument(); Element element = document.addElement("gbsfss"); Element headElement = element.addElement("head"); headElement.addElement("function").addText(ConstantParam.XML_BiaoB); headElement.addElement("description").addText(ConstantParam.XML_BiaoBName); headElement.addElement("fromxzqh").addText(txtJg.getXzqh()); headElement.addElement("fromzfbm").addText(txtJg.getJgjb()); headElement.addElement("toxzqh").addText((String) dqdwList.get(0)); headElement.addElement("tozfbm").addText((String) dqdwList.get(1)); headElement.addElement("date").addText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); Element resourceElement = element.addElement("resource"); Set<VXfZhDTO> keySet = sfrwtMap.keySet(); for (VXfZhDTO vXfZh : keySet) { Element listElement = resourceElement.addElement("list"); Element sfwtElement = listElement.addElement("xfwt"); addElementText(sfwtElement.addElement("id"), vXfZh.getWtid());// 问题主键 addElementText(sfwtElement.addElement("sfly"), vXfZh.getSflx()); // 上访类型 addElementText(sfwtElement.addElement("lfsj"), vXfZh.getLfsj() == null ? null : getDatetoString(vXfZh.getLfsj()));// 信访时间 addElementText(sfwtElement.addElement("lxxs"), vXfZh.getLxxs());// 初信初访形式 addElementText(sfwtElement.addElement("wtfsd"), vXfZh.getWtfsd());// 上访问题发生地 addElementText(sfwtElement.addElement("wtfsdxz"), vXfZh.getWtfsdxz());// 信访问题发生地详址 addElementText(sfwtElement.addElement("lxcs"), vXfZh.getLxcs());// 重复访来信次数 addElementText(sfwtElement.addElement("lfcs"), vXfZh.getLfcs());// 重复访来访次数 addElementText(sfwtElement.addElement("jjzcf"), vXfZh.getJjzcf());// 进京正常访 addElementText(sfwtElement.addElement("jjfzcf"), vXfZh.getJjfzcf());// 进京非正常访 addElementText(sfwtElement.addElement("yjfcs"), vXfZh.getYjfcs());// 越级访次数 addElementText(sfwtElement.addElement("sjbmjsfwt"), vXfZh.getSjbmjsfwt());// 涉及部门及上访问题 addElementText(sfwtElement.addElement("xfsq"), vXfZh.getXfsq());// 信访诉求 addElementText(sfwtElement.addElement("jyaq"), vXfZh.getJyaq());// 简要案情 addElementText(sfwtElement.addElement("sfsksfl"), vXfZh.getSfsksfl());// 是否三跨三分离 addElementText(sfwtElement.addElement("ajfssj"), vXfZh.getAjfssj() == null ? null : getDatetoString(vXfZh.getAjfssj()));// 案件发生时间 addElementText(sfwtElement.addElement("jjzcfcs"), vXfZh.getJjzcfcs());// 进京正常访次数 addElementText(sfwtElement.addElement("jjfzcfcs"), vXfZh.getJjzcfcs());// 进京正常访次数 addElementText(sfwtElement.addElement("djr"), vXfZh.getDjr());//登记人 addElementText(sfwtElement.addElement("djbm"), vXfZh.getDjbm());// 登记部门 addElementText(sfwtElement.addElement("ah"), vXfZh.getAh());// 案件编号 addElementText(sfwtElement.addElement("xfly"), vXfZh.getXfly());// 信访来源 addElementText(sfwtElement.addElement("thdqid"), vXfZh.getThdqid());// 交办地区id addElementText(sfwtElement.addElement("thdwid"), vXfZh.getThdwid());// 交办单位ID addElementText(sfwtElement.addElement("ldcs"), vXfZh.getLdcs());// 信访来源 addElementText(sfwtElement.addElement("czcs"), vXfZh.getCzcs());// 信访来源 addElementText(sfwtElement.addElement("wsxfcs"), vXfZh.getWsxfcs());// 信访来源 addElementText(sfwtElement.addElement("yjfcs"), vXfZh.getYjfcs());// 信访来源 addElementText(sfwtElement.addElement("xfsqqt"),vXfZh.getXfsqqt());// 信访来 //addElementText(sfwtElement.addElement("sjdwxzqh"), vXfZh.getsjd);// 信访来源 //addElementText(sfwtElement.addElement("sjdwxzid"), vXfZh.);// 信访来源 addElementText(sfwtElement.addElement("yxbz"), vXfZh.getYxbz());// 有效标志 addElementText(sfwtElement.addElement("wtzt"), vXfZh.getWtzt());// 问题状态 addElementText(sfwtElement.addElement("cjsj"), vXfZh.getCjsj() == null ? null : getDatetoString(vXfZh.getCjsj()));// 采集时间 addElementText(sfwtElement.addElement("gxsj"), vXfZh.getGxsj() == null ? null : getDatetoString(vXfZh.getGxsj()));// 有效标志 Set<VXfSfrDj> sfrDjSet = sfrwtMap.get(vXfZh); for(VXfSfrDj sfrDj : sfrDjSet){ Element sfrElement = listElement.addElement("xfr"); addElementText(sfrElement.addElement("id"), sfrDj.getId());// 人员id addElementText(sfrElement.addElement("xm"), sfrDj.getXm()); // 姓名 addElementText(sfrElement.addElement("xb"), sfrDj.getXb());// 性别 addElementText(sfrElement.addElement("mz"), sfrDj.getMz());//民族 addElementText(sfrElement.addElement("csrq"), sfrDj.getCsrq() == null ? null : getDatetoString(sfrDj.getCsrq()));// 出生日期 addElementText(sfrElement.addElement("hjd"), sfrDj.getHjd());//户籍地 addElementText(sfrElement.addElement("xzd"), sfrDj.getXzd());// 现住地 addElementText(sfrElement.addElement("zjlx"), sfrDj.getZjlx());// 证件类型 addElementText(sfrElement.addElement("zjhm"), sfrDj.getZjhm());// 证件号码 addElementText(sfrElement.addElement("yddh"), sfrDj.getYddh());// 移动电话 addElementText(sfrElement.addElement("gddh"), sfrDj.getGddh());// 固定电话 addElementText(sfrElement.addElement("mqdx"), sfrDj.getMqdx());// 目前动向 addElementText(sfrElement.addElement("yyadsrgx"), sfrDj.getYyadsrgx());// 与原案当事人关系 addElementText(sfrElement.addElement("txdz"), sfrDj.getTxdz());// 通讯地址 addElementText(sfrElement.addElement("yzbm"), sfrDj.getYzbm());// 邮政编码 addElementText(sfrElement.addElement("xzdxz"), sfrDj.getXzdxz());// 现住地详址 addElementText(sfrElement.addElement("hjdxz"), sfrDj.getHjdxz());// 户籍地详址 addElementText(sfrElement.addElement("gddhqh"), sfrDj.getGddhqh());//固定电话区号 addElementText(sfrElement.addElement("zy"), sfrDj.getZy());//职业 addElementText(sfrElement.addElement("djr"), sfrDj.getDjr());// 登记人 addElementText(sfrElement.addElement("djbm"), sfrDj.getDjbm());// 登记部门 addElementText(sfrElement.addElement("xfly"), sfrDj.getXfly());// 信访来源 addElementText(sfrElement.addElement("cym"), sfrDj.getCym());// 信访来源 addElementText(sfrElement.addElement("zjlxqt"), sfrDj.getZjlxqt());// 信访来源 addElementText(sfrElement.addElement("gzdw"), sfrDj.getGzdw());// 信访来源 addElementText(sfrElement.addElement("zw"), sfrDj.getZw());// 信访来源 addElementText(sfrElement.addElement("whcd"), sfrDj.getWhcd());// 信访来源 addElementText(sfrElement.addElement("zzmm"), sfrDj.getZzmm());// 信访来源 addElementText(sfrElement.addElement("hyzk"), sfrDj.getHyzk());// 信访来源 addElementText(sfrElement.addElement("dzyx"), sfrDj.getDzyx());// 信访来源 //addElementText(sfrElement.addElement("xmpy"), sfrDj.getXm());// 信访来源 //addElementText(sfrElement.addElement("pyzt"), sfrDj.getp);// 信访来源 //addElementText(sfrElement.addElement("qtqk"), sfrDj.getqtq);// 信访来源 addElementText(sfrElement.addElement("zc"), sfrDj.getZc());// 信访来源 //addElementText(sfrElement.addElement("finaldate"), sfrDj.getf);// 信访来源 addElementText(sfrElement.addElement("zjqsxm"), sfrDj.getZjqsxm());// 信访来源 addElementText(sfrElement.addElement("zjqszz"), sfrDj.getZjqszz());// 信访来源 addElementText(sfrElement.addElement("zjqsdh"), sfrDj.getZjqsdh());// 信访来源 addElementText(sfrElement.addElement("zjqsgx"), sfrDj.getZjqsgx());// 信访来源 addElementText(sfrElement.addElement("zjljddz"), sfrDj.getZjljddz());// 信访来源 addElementText(sfrElement.addElement("zjljdlxfs"), sfrDj.getZjljdlxfs());// 信访来源 addElementText(sfrElement.addElement("zjwgdwmc"), sfrDj.getZjwgdwmc());// 信访来源 addElementText(sfrElement.addElement("zjwgdwdz"), sfrDj.getZjwgdwdz());// 信访来源 addElementText(sfrElement.addElement("zjwgdwlxfs"), sfrDj.getZjwgdwlxfs());// 信访来源 // addElementText(sfrElement.addElement("zjxzqt"), sfrDj.zjxz);// 信访来源 addElementText(sfrElement.addElement("yxbz"), sfrDj.getYxbz());// 有效标志 addElementText(sfrElement.addElement("cjsj"), sfrDj.getCjsj() == null ? null : getDatetoString(sfrDj.getCjsj()));// 有效标志 addElementText(sfrElement.addElement("gxsj"), sfrDj.getGxsj() == null ? null : getDatetoString(sfrDj.getGxsj()));// 采集时间 } } // 内存方式,不通过文件. ByteArrayOutputStream os = new ByteArrayOutputStream(); try { XMLWriter output = new XMLWriter(os, new OutputFormat("", true, "UTF-8")); output.write(document); } catch (Exception e) { e.printStackTrace(); return null; } xmlString = os.toByteArray(); return xmlString; } public void addElementText(Element element, String text) { if (text != null) { element.addText(text); } } //进行判重判空,成功后返回交办地区交办单位List用于header的toxzqh和tozfbm元素设置 public List checkDqDw(Set<VXfZhDTO> keySet) { List dqdw = new ArrayList(); for(VXfZhDTO vxfzh : keySet){ if(vxfzh != null){ if(vxfzh.getThdqid() == null || vxfzh.getThdqid().equals("")) { addActionMessage("交办地区不能为空,请设置后重新导出!"); return null; } if(vxfzh.getThdwid() == null || vxfzh.getThdwid().equals("")) { addActionMessage("交办单位不能为空,请设置后重新导出!"); return null; } //找到第一个交办地区交办单位不为空的进行判重 String dq = vxfzh.getThdqid(); String dw = vxfzh.getThdwid(); for(VXfZhDTO zh : keySet) { if(zh != null) { if(!(dq.equals(zh.getThdqid()))) { addActionMessage("交办地区不一致,请检查设置后重新导出!"); return null; } if(!(dw.equals(zh.getThdwid()))) { addActionMessage("交办单位不一致,请检查设置后重新导出!"); return null; } } } dqdw.add(dq); dqdw.add(dw); } } return dqdw; } public Map<VXfZhDTO, Set<VXfSfrDj>> getDownloadFileMap() throws Exception { vxfZhDTO = (VXfZhDTO) session.get("vxfZhDTO"); Map<VXfZhDTO, Set<VXfSfrDj>> sfrwtMap = new HashMap<VXfZhDTO, Set<VXfSfrDj>>(); TXtYhDTO yhDTO = (TXtYhDTO) session.get(ConstantParam.USER_SESSION_KEY); StringBuilder where = new StringBuilder(ConstantParam.BYTJ); if (vxfZhDTO != null) { relation = QueryUtils.getSQL(vxfZhDTO, yhDTO, true, null); } if (StringUtils.isNotEmpty(relation)) { where.append(ConstantParam.BYTJ_AND).append(relation); } where.append(Authority.newInstance().getRelation(yhDTO)); List<?> excelCountList = queryBusiness.getDistinctZh(where.toString()); if (excelCountList != null && excelCountList.size() > 0) { Map<String, String> dataMap = StringUtils.listConvertMap(excelCountList); StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> me : dataMap.entrySet()) { if (!"".equals(me.getKey())) { sb.append(" wtid = '" + me.getKey() + "' OR "); } } sb.delete(sb.lastIndexOf("OR"), sb.length()); excelList = queryBusiness.queryExcelPage(sb.toString() + " ORDER BY lfsj DESC,wtid"); List<VXfZhDTO> delList = new ArrayList<VXfZhDTO>(); String id = ""; String tempId = ""; String clfsStr = ""; String jzsjStr = ""; String pzsjStr = ""; for (int index = 0; excelList != null && excelList != null && index < excelList.size(); index++) { VXfZhDTO vxfZhDTO = excelList.get(index); id = vxfZhDTO.getWtid(); if (id.equals(tempId)) { if (vxfZhDTO.getClfsStr() == null || "".equals(vxfZhDTO.getClfsStr())) { vxfZhDTO.setClfsStr("\r\n" + clfsStr); } else { vxfZhDTO.setClfsStr(vxfZhDTO.getClfsStr() + "\r\n" + clfsStr); } if (vxfZhDTO.getJzsjStr() == null || "".equals(vxfZhDTO.getJzsjStr())) { vxfZhDTO.setJzsjStr("\r\n" + jzsjStr); } else { vxfZhDTO.setJzsjStr(vxfZhDTO.getJzsjStr() + "\r\n" + jzsjStr); } if (vxfZhDTO.getPzychjzsjStr() == null || "".equals(vxfZhDTO.getPzychjzsjStr())) { vxfZhDTO.setPzychjzsjStr("\r\n" + pzsjStr); } else { vxfZhDTO.setPzychjzsjStr(vxfZhDTO.getPzychjzsjStr() + "\r\n" + pzsjStr); } delList.add(excelList.get(index - 1)); } clfsStr = vxfZhDTO.getClfsStr(); jzsjStr = vxfZhDTO.getJzsjStr(); pzsjStr = vxfZhDTO.getPzychjzsjStr(); tempId = id; } if (delList.size() > 0) { excelList.removeAll(delList); } if(excelList != null && excelList.size()>0){ for(VXfZhDTO vxfZhDTO : excelList){ Set<VXfSfrDj> sfrDj = new HashSet<VXfSfrDj>(); String sfrSql = "WHERE sfwtid='" + vxfZhDTO.getWtid() + "' AND yxbz IN ('"+ConstantParam.YXBZ_YX+"','"+ConstantParam.YXBZ_DJ+"')"; List<VXfSfrDj> sfrDjList = zhQueryService.getSfrDj(sfrSql); if( sfrDjList != null && sfrDjList.size() > 0 ) { for( VXfSfrDj sfr : sfrDjList ) { sfrDj.add(sfr); } } sfrwtMap.put(vxfZhDTO, sfrDj); } } } return sfrwtMap; } public List<?> getDownloadFileList() throws Exception { vxfZhDTO = (VXfZhDTO) session.get("vxfZhDTO"); TXtYhDTO yhDTO = (TXtYhDTO) session.get(ConstantParam.USER_SESSION_KEY); StringBuilder where = new StringBuilder(ConstantParam.BYTJ); where.append(ConstantParam.BYTJ_AND).append("substr(xfly,0,2) ='").append(ConstantParam.XFLY_RD).append("'"); // yuhj 只读取人大数据2012-05-16 if (vxfZhDTO != null) { relation = QueryUtils.getSQL(vxfZhDTO, yhDTO, true, null); } if (StringUtils.isNotEmpty(relation)) { where.append(ConstantParam.BYTJ_AND).append(relation); } where.append(Authority.newInstance().getRelation(yhDTO)); List<?> excelCountList = queryBusiness.getDistinctZh(where.toString()); if (excelCountList != null && excelCountList.size() > 0) { Map<String, String> dataMap = StringUtils.listConvertMap(excelCountList); StringBuffer sb = new StringBuffer(); for (Map.Entry<String, String> me : dataMap.entrySet()) { if (!"".equals(me.getKey())) { sb.append(" wtid = '" + me.getKey() + "' OR "); } } sb.delete(sb.lastIndexOf("OR"), sb.length()); excelList = queryBusiness.queryExcelPage(sb.toString() + " ORDER BY lfsj DESC,wtid"); List<VXfZhDTO> delList = new ArrayList<VXfZhDTO>(); String id = ""; String tempId = ""; String clfsStr = ""; String jzsjStr = ""; String pzsjStr = ""; for (int index = 0; excelList != null && excelList != null && index < excelList.size(); index++) { VXfZhDTO vxfZhDTO = excelList.get(index); id = vxfZhDTO.getWtid(); if (id.equals(tempId)) { if (vxfZhDTO.getClfsStr() == null || "".equals(vxfZhDTO.getClfsStr())) { vxfZhDTO.setClfsStr("\r\n" + clfsStr); } else { vxfZhDTO.setClfsStr(vxfZhDTO.getClfsStr() + "\r\n" + clfsStr); } if (vxfZhDTO.getJzsjStr() == null || "".equals(vxfZhDTO.getJzsjStr())) { vxfZhDTO.setJzsjStr("\r\n" + jzsjStr); } else { vxfZhDTO.setJzsjStr(vxfZhDTO.getJzsjStr() + "\r\n" + jzsjStr); } if (vxfZhDTO.getPzychjzsjStr() == null || "".equals(vxfZhDTO.getPzychjzsjStr())) { vxfZhDTO.setPzychjzsjStr("\r\n" + pzsjStr); } else { vxfZhDTO.setPzychjzsjStr(vxfZhDTO.getPzychjzsjStr() + "\r\n" + pzsjStr); } delList.add(excelList.get(index - 1)); } clfsStr = vxfZhDTO.getClfsStr(); jzsjStr = vxfZhDTO.getJzsjStr(); pzsjStr = vxfZhDTO.getPzychjzsjStr(); tempId = id; } if (delList.size() > 0) { excelList.removeAll(delList); } } return excelList; } public void setThdqid(String thdqid) { this.thdqid = thdqid; } public String getThdqid() { return thdqid; } public void setThdwid(String thdwid) { this.thdwid = thdwid; } public String getThdwid() { return thdwid; } public String getDatetoString(Date date) { Date dt = date; //创建日期格式化对象 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(dt); } } |
|||
xml导入 | xml解析 java | ||
package com.css.action; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import javax.annotation.Resource; import org.apache.commons.io.FileUtils; import org.apache.struts2.ServletActionContext; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.Element; import org.dom4j.io.SAXReader; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.css.bean.TXfBljg; import com.css.bean.TXfWtcl; import com.css.service.SfWtService; import com.css.service.TXfBljgService; import com.css.service.WtClService; import com.css.util.ConstantParam; import com.opensymphony.xwork2.ActionSupport; /** * @function 提供xml文件上传解析和数据存储 * @author liangbo time at 08/05/2012 * modify by liangbo time at 08/06/2012 //新增从xmlhead节点获取反馈单位和区划并保存 * modify by liangbo time at 12/06/2012 //新增备案审查机关和完成时间元素的导入 */ @Controller("rdfjXMLAction") @Scope("prototype") public class RdfjXMLAction extends ActionSupport{ private static final long serialVersionUID = 1L; @Resource private SfWtService sfWtService; @Resource private TXfBljgService tXfBljgService; @Resource private WtClService wtClService; //封装上传文件域的属性 private File upload; //封装上传文件类型的属性 private String uploadContentType; //封装上传文件名的属性 private String uploadFileName; //直接在struts.xml文件中配置的属性 private String savePath; private boolean update; //接受struts.xml文件配置值的方法 public void setSavePath(String savePath) { this.savePath = savePath; } public String getSavePath() { return savePath; } //上传文件对应文件内容的setter和getter方法 public void setUpload(File upload) { this.upload = upload; } public File getUpload() { return upload; } //上传文件的文件类型的setter和getter方法 public void setUploadContentType(String uploadContentType) { this.uploadContentType = uploadContentType; } public String getUploadContentType() { return (this.uploadContentType); } //上传文件的文件名的setter和getter方法 public void setUploadFileName(String uploadFileName) { this.uploadFileName = uploadFileName; } public String getUploadFileName() { return (this.uploadFileName); } public boolean isUpdate() { return update; } public void setUpdate(boolean update) { this.update = update; } /** * 文件导入校验说明: * 1:根据文件头文件内容校验该数: * <function>BiaoC</function>中值校验数据标准为BiaoA 校验返回结果:错误:文件标准错误,请您联系相关单位或管理员! * <toxzqh>110000</toxzqh>中值校验是否来自110000 校验返回结果:错误:文件接收单位信息错误,请您联系相关单位或管理员! * <tozfbm>0501</tozfbm>中值校验来自"全国人大" 校验返回结果:错误:文件接收单位信息错误,请您联系相关单位或管理员! * * 2:根据XML中<id>64357A04-D963-42F9-8102-922373848A5D</id>中值,校验TXfSfwt表中是否存在该数据,存在正常往下进行,不存在返回:该信访问题在本系统中无对应信息,请核对后导入! * 若以上校验通过,再根据id校验TXfBljg表该数据是否已经存在该数据,若存在返回结果:错误:该信访问题处理结果信息已存在,请确认是否重新导入!。 * * 3:导入成功后:将文件按照:文件命名方式:“fromxzqh(XML中对应字段)+ fromzfbm+时间形式”保存在D盘RdzbData/DfToZzw/文件夹下。 * 导入成功后刷新列表数据显示。 * 注意:文件导入可能需要时间较长,页面要有“等待导入”提示,导入成功与失败都要在页面返回结果信息。 * **/ //文件上传 public void upload() { File file = null; PrintWriter out = null; if(upload == null) { out.print("无上传文件,请选择你需要上传的文件!"); return; } try { ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); out = ServletActionContext.getResponse().getWriter(); file = new File(savePath, uploadFileName); FileUtils.copyFile(upload, file); //获得xml文件头数据标准 String function = this.getHeadXML(file, "function"); //获得xml文件头toxzqh String toxzqh = this.getHeadXML(file, "toxzqh"); //获得xml文件头tozfbm String tozfbm = this.getHeadXML(file, "tozfbm"); if(!(ConstantParam.XML_BiaoC.equals(function))){ //上传失败,删除文件 FileUtils.forceDelete(file); out.print("错误:文件标准错误,请您联系相关单位或管理员!"); return ; } /** * 放开接收单位、接收地区校验 07062012liangbo * else if(!(ConstantParam.XML_XZQH.equals(toxzqh))){ //上传失败,删除文件 FileUtils.forceDelete(file); out.print("错误:文件接收单位信息错误,请您联系相关单位或管理员!"); return ; } else if(!(ConstantParam.XML_ZFBM.equals(tozfbm))){ //上传失败,删除文件 FileUtils.forceDelete(file); out.print("错误:文件接收单位信息错误,请您联系相关单位或管理员!"); return ; }*/ int wtclCount = 0;// 记录问题处理添加成功次数 int bljgCount = 0;// 记录处理结果添加成功次数 int wtclupdatCount = 0;// 记录问题处理更新成功次数 int bljgupdateCount = 0;// 记录处理结果更新成功次数 Map<TXfBljg, Set<TXfWtcl>> tXfSfwtMap = saveFromXML(file); Set<TXfBljg> keySet = tXfSfwtMap.keySet(); //遍历Map并数据到数据库 //默认已正常方式进行数据处理 for (TXfBljg tXfBljg : keySet) { // 保存问题处理结果,先检查问题是否存在 if ((sfWtService.getTXfSfwt(tXfBljg.getWtid()) == null)) { out.print("上传信访处理数据无对应信访问题数据,请确认后重新上传!</br>"); // 上传失败,删除文件 FileUtils.forceDelete(file); return; } // 保存问题处理结果,先检查数据库是否已有对应数据 if (tXfBljgService.findWtJG(tXfBljg.getWtid()) != null) { if (!update) { out.print("处理结果: " + tXfBljg.getWtid() + "数据已存在,系统默认自动跳过!</br>"); } else { tXfBljgService.updateObject(tXfBljg); out.print("更新信访问题唯一标识为【" + tXfBljg.getId() + "】的处理结果信息!</br>"); // 更新问题 sfWtService.updateWtZt(tXfBljg.getWtid(), ConstantParam.WTZT_WTJA); bljgupdateCount++; } } else { tXfBljgService.save(tXfBljg); out.print("添加信访问题唯一标识为【" + tXfBljg.getWtid() + "】的处理结果信息!</br>"); // 更新问题 sfWtService.updateWtZt(tXfBljg.getWtid(), ConstantParam.WTZT_WTJA); bljgCount++; } Set<TXfWtcl> wtclSet = tXfSfwtMap.get(tXfBljg); for (TXfWtcl tXfWtcl : wtclSet) { // 保存问题处理,先检查数据库是否已有对应数据 if (wtClService.findWtcl(tXfWtcl.getWtid()) != null) { if (!update) { out.print("问题处理: " + tXfWtcl.getWtid() + "数据已存在,系统默认自动跳过!</br>"); } else { wtClService.updateObject(tXfWtcl); out.print("更新信访问题唯一标识为【" + tXfWtcl.getWtid() + "】的处理结果信息!</br>"); // 更新问题 sfWtService.updateWtZt(tXfWtcl.getWtid(), ConstantParam.WTZT_WTJA); wtclupdatCount++; } } else { wtClService.save(tXfWtcl); out.print("添加信访问题唯一标识为【" + tXfWtcl.getId() + "】的问题处理信息!</br>"); // 更新问题 sfWtService.updateWtZt(tXfBljg.getWtid(), ConstantParam.WTZT_WTJA); wtclCount++; } } } if (wtclCount != 0 || wtclupdatCount != 0 || bljgCount != 0 || bljgupdateCount != 0 ) { //获得xml文件来自行政区划 String tXzqh = this.getHeadXML(file, "fromxzqh"); //获得xml文件来自部门 String tZfbm = this.getHeadXML(file, "fromzfbm"); //以文件命名方式:“fromxzqh(XML中对应字段)+ fromzfbm+时间形式保存上传文件 Date dt = new Date(); //创建日期格式化对象 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String sdate = sdf.format(dt); //定义指定保存文件名 String nFileName = tXzqh + " " + tZfbm + " " + sdate + uploadFileName; File nFile = new File(savePath,nFileName); FileUtils.copyFile(upload, nFile); //删除临时文件 FileUtils.forceDelete(file); out.print("恭喜你,数据上传成功!"); return ; } else { out.print("无数据添加或更新!"); file.delete(); } } catch (IOException e) { e.printStackTrace(); out.print("上传出现异常!"); //上传失败,删除文件 file.delete(); return ; } } //获得xml文件头信息 public String getHeadXML(File file,String st){ SAXReader saxReader = new SAXReader(); Document document; try { document = saxReader.read(file); List<Element> elements = document.selectNodes("//gbsfss"); for(Element listElement :elements ) { Element sfwtElement = listElement.element("head"); if(sfwtElement != null) { return getElementText(sfwtElement, st); } else { return null; } } } catch (DocumentException e) { e.printStackTrace(); return null; } return null; } //xml解析并返回对象 public Map<TXfBljg, Set<TXfWtcl>> saveFromXML(File file) { SAXReader saxReader = new SAXReader(); Document document; Map<TXfBljg, Set<TXfWtcl>> tXfSfwtMap = new HashMap<TXfBljg, Set<TXfWtcl>>(); try { document = saxReader.read(file); Element et = (Element)document.selectSingleNode("//gbsfss"); Element headElement = et.element("head"); String fromxzqh = getElementText(headElement,"fromxzqh");//反馈区划 String fromzfbm = getElementText(headElement,"fromzfbm");//反馈部门 String fromcjsj = getElementText(headElement,"date");//反馈时间 List<Element> elements = document.selectNodes("//gbsfss/resource/list"); for(Element listElement:elements) { TXfBljg tXfBljg = new TXfBljg(); Set<TXfWtcl> tXfwtclSet = new HashSet<TXfWtcl>(); TXfWtcl tXfwtcl = new TXfWtcl(); Element sfwtElement = listElement.element("xfwt"); if (sfwtElement != null) { //id tXfBljg.setId(UUID.randomUUID().toString().toUpperCase()); //化解结果 tXfBljg.setHjjg(getElementText(sfwtElement, "hjjg")); //化解方法 tXfBljg.setHjff(getElementText(sfwtElement, "hjff")); //是否依法处置上访人 tXfBljg.setSfyfczsfrqt(getElementText(sfwtElement, "sfyfczsfr")); //化解单位 tXfBljg.setHjdw(getElementText(sfwtElement, "hjdw")); //问题性质 tXfBljg.setWtxz(getElementText(sfwtElement, "wtxz")); //评查单位 tXfBljg.setPcdw(getElementText(sfwtElement, "pcdw")); //评查结果 tXfBljg.setPcjg(getElementText(sfwtElement, "pcjg")); //处理上访人部门 tXfBljg.setClsfrbm(getElementText(sfwtElement, "clsfrbm")); //化解时间 tXfBljg.setHjsj(getDate((getElementText(sfwtElement, "hjsj")))); //备案审查中央机关 tXfBljg.setBascdw(getElementText(sfwtElement, "bascdw")); //备案审查完成时间 tXfBljg.setBascwcsj(getDate((getElementText(sfwtElement, "bascwcsj")))); tXfBljg.setFkxzqh(fromxzqh); tXfBljg.setFkzfbm(fromzfbm); tXfBljg.setFkcjsj(getDate(fromcjsj)); //问题处理ID tXfBljg.setWtid(getElementText(sfwtElement, "id")); //问题ID ----->问题id 为外键,与问题信息表id对应 tXfBljg.setWtid(getElementText(sfwtElement, "id")); } Element wtclElement = listElement.element("xfwtcl"); if(wtclElement != null) { // 问题处理id tXfwtcl.setId(UUID.randomUUID().toString().toUpperCase()); //经办人 tXfwtcl.setJdr(getElementText(wtclElement, "jdr")); //经办单位 tXfwtcl.setJddw(getElementText(wtclElement, "jddw")); // 承办人 tXfwtcl.setCbr(getElementText(wtclElement, "cbr")); // 承办单位 tXfwtcl.setCbdw(getElementText(wtclElement, "cbdw")); // 稳控责任单位 tXfwtcl.setWkzrdw(getElementText(wtclElement, "wkzrdw")); // 拟办意见 tXfwtcl.setNbyj(getElementText(wtclElement, "nbyj")); // 领导批示 tXfwtcl.setLdps(getElementText(wtclElement, "ldps")); //问题ID ----->问题id 为外键,与问题信息表id对应 tXfwtcl.setWtid(getElementText(sfwtElement, "id")); tXfwtclSet.add(tXfwtcl); } tXfSfwtMap.put(tXfBljg,tXfwtclSet); } } catch (Exception e) { e.printStackTrace(); return null; } return tXfSfwtMap; } // 获取XML元素的子元素值,没有则赋为空 public String getElementText(Element element, String name) { String text = null; if (element.element(name) != null) { text = element.element(name).getText(); } return text; } // 字符串转换为date public Date getDate(String string) { Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (string != null && !string.trim().equals("")) { try { date = sdf.parse(string); } catch (ParseException e) { e.printStackTrace(); return null; } } return date; } } |
|||
数据访问层通用核心DAO | jdbc hibernate java | ||
package com.htsoft.core.command; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Session; import org.hibernate.SessionFactory; import com.htsoft.core.command.util.GenericsUtils; import com.htsoft.core.command.util.SpringUtil; import com.zd6.bean.TauthAccount; import com.zd6.common.util.annotation.MethodAnnotation; import com.zd6.common.util.annotation.MethodAnnotation.DML; /** * @function DAO * @description 抽象的数据访问对象,只能被扩展,不能实例化;视为数据访问层的核心之一 * @version 1.0 * @author CS&S * @time 19/02/2013 */ @SuppressWarnings("unchecked") public abstract class DAOSupport<T> implements DAO<T> { // 动态型别辨识 protected Class<T> entityClass = GenericsUtils.getSuperClassGenricType(this.getClass()); @Resource protected SessionFactory sessionFactory; public Session getCurrnentSession() { if( sessionFactory == null ){ sessionFactory=(SessionFactory)SpringUtil.getInstance().getBean("sessionFactory"); } return sessionFactory.getCurrentSession(); } /** * @function delete * @param Serializable... entityids * @description 根据主键值批量删除数据 */ @MethodAnnotation(description="依据主键批量删除", dml=DML.DELETE) public void delete(Serializable... entityids) { if (entityids != null) { for (Object id : entityids) { Object obj = sessionFactory.getCurrentSession().get(this.entityClass, (Serializable) id); sessionFactory.getCurrentSession().delete(obj); } } } /** * @function delete * @param Object obj * @description 根据对象删除数据 */ public void delete(Object obj) { sessionFactory.getCurrentSession().delete(obj); } /** * @function delete * @param List objList * @description 删除List对象数据,为空时不做任何处理 */ public void delete(List<Object> objList) { if( objList != null && objList.size() > 0 ) { for( Object obj : objList ) { sessionFactory.getCurrentSession().delete(obj); } } } /** * @function get * @param Serializable entityId * @description 根据主键值得到对象数据 * @return T 泛型 */ @MethodAnnotation(description="依据主键取值", dml=DML.SELECT) public T get(Serializable entityId) { if( entityId != null ) { //sessionFactory.getCurrentSession().get(this.entityClass, entityId) return (T) sessionFactory.getCurrentSession().get(this.entityClass, entityId); } else { throw new RuntimeException(this.entityClass.getName()); } } /** * @function save * @param Object entity * @description 实体持久化,不返回实体Bean */ public void save(Object entity) { if (entity != null) { sessionFactory.getCurrentSession().persist(entity); } else { throw new RuntimeException(this.entityClass.getName()); } } /** * @function save * @param Object entity * @description 实体持久化,返回实体对象数据主键 * @return T model object */ public T saveObject(Object entity) { if (entity != null) { Serializable entityId = sessionFactory.getCurrentSession().save(entity); return (T) get(entityId); } else { throw new RuntimeException(this.entityClass.getName()); } } /** * @function update * @param Object entity * @description 实体持久化,不返回实体Bean */ public void update(Object entity) { if (entity != null) { sessionFactory.getCurrentSession().update(entity); } else { throw new RuntimeException(this.entityClass.getName()); } } /** * @function update * @param Object entity * @description 实体持久化,返回实体对象数据Bean * @return T model object */ public T updateObject(Object entity) { if ( entity != null ) { return (T) sessionFactory.getCurrentSession().merge(entity); } else { throw new RuntimeException(this.entityClass.getName()); } } /** * @function findAll * @param Object entity * @description 返回所有记录 * @return List<T> 结果集 */ public List<T> findAll(String ObjectName) { return sessionFactory.getCurrentSession().createQuery("FROM " + ObjectName).setCacheable(true).list(); //return sessionFactory.getCurrentSession().createQuery("FROM " + ObjectName).setCacheable(false).list(); } /** * @function findAll * @param Object entity * @description 返回所有记录 * @return List<T> 结果集 */ public List<T> findAll() { return sessionFactory.getCurrentSession().createQuery("FROM " + this.getClassName()).setCacheable(true).list(); //return sessionFactory.getCurrentSession().createQuery("FROM " + ObjectName).setCacheable(false).list(); } /** * @function 生成HQL查询工具 使用getEntityName()+属性名的形式来拼接字符串 * @param hql 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 */ protected List<T> commonHQL(String hql, Object[] params) { return this.commonAddSelectHQL(null, hql, params, 0, 0); } /** * @function 生成HQL查询工具 * @param where 查询语句 "WHERE" + this.getEntityName()+".name=? " * @return List<T> 查询结果集 */ public List<T> commonHQL(String where) { StringBuilder commonHql = new StringBuilder("FROM " + this.getClassName()); if( where != null && where.length() > 0 ) { commonHql.append(" ").append(where); } //Query query = this.getCurrnentSession().createQuery(commonHql.toString()).setCacheable(true); Query query = this.getCurrnentSession().createQuery(commonHql.toString()); return query.list(); } /** * @function 生成HQL查询工具,返回最后一条记录 * @param where 查询语句 "WHERE" + this.getEntityName()+".name=? " * @return List<T> 查询结果集 */ public T commonHQLLast(String where) { StringBuilder commonHql = new StringBuilder("FROM " + this.getClassName()); if( where != null && where.length() > 0 ) { commonHql.append(" ").append(where); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()); query.setMaxResults(1).uniqueResult(); if( query != null && query.list().size() > 0 ) { return (T) query.list().get(0); } else { return null; } } /** * @function 生成HQL查询工具 使用getEntityName()+属性名字的形式来拼接字符串 分页显示查询数据 * @param hql 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @param first 第一条索引位置 * @param max 最大索引数量 * @return List */ protected List<T> commonHQLofIndex(String hql, Object[] params, int first, int max) { return this.commonAddSelectHQL(null, hql, params, first, max); } /** * @function 生成HQL查询工具 使用getEntityName()+属性名字的形式来拼接字符串 分页显示查询数据 * @param hql 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @param currentPage 当前页码 * @param rowNum 每页显示记录数 * @return QueryResult 带有翻页数据的bean */ protected QueryResult<T> commonHQLofPage(String hql, Object[] params, int currentPage, int rowNum) { List<T> resultList = this.commonAddSelectHQL(null, hql, params, (currentPage-1)*rowNum, rowNum); Long totalrecord = getCount(hql, params); QueryResult<T> qResult = new QueryResult<T>(totalrecord, currentPage, rowNum); qResult.setResultlist(resultList); //设置结果集 return qResult; } /** * @function 生成HQL查询工具 使用getEntityName()+属性名字的形式来拼接字符串 分页显示查询数据 * @param where 查询语句 this.getEntityName()+".name=? " * @param currentPage 当前页码 * @param rowNum 每页显示记录数 * @return QueryResult 带有翻页数据的bean */ protected QueryResult<T> commonHQLofPage(String where, int currentPage, int rowNum) { List<T> resultList = this.commonAddSelectHQL(null, where, (currentPage-1)*rowNum, rowNum); Long totalrecord = getCount(where); QueryResult<T> qResult = new QueryResult<T>(totalrecord, currentPage, rowNum); qResult.setResultlist(resultList); //设置结果集 return qResult; } /** * @function 生成HQL查询工具 使用getEntityName()+属性名字的形式来拼接字符串 分页显示查询数据,提供定制查询结果 * @param select 指定查询返回的结果 * @param hql 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @param first 第一条索引位置 * @param max 最大索引数量 * @return List */ protected List<T> commonAddSelectHQL(String select, String hql, Object[] params, int first, int max) { StringBuilder commonHql = new StringBuilder("FROM " + this.getClassName()); if (StringUtils.isNotEmpty(hql)) { commonHql.append(" " + this.getEntityName() + " WHERE "); commonHql.append(hql); } if (StringUtils.isNotEmpty(select)) { commonHql.insert(0, select); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()); for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } query.setCacheable(true); //query.setCacheable(false); //query.setFetchSize(30); if (max != 0) { query.setFirstResult(first); query.setMaxResults(max); } commonHql.delete(0, commonHql.length()); List<T> list = query.list(); return list; } /** * @function 生成HQL查询工具 使用getEntityName()+属性名字的形式来拼接字符串 分页显示查询数据,提供定制查询结果 * @param select 指定查询返回的结果 * @param where 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @param first 第一条索引位置 * @param max 最大索引数量 * @return List */ protected List<T> commonAddSelectHQL(String select, String where, int first, int max) { StringBuilder commonHql = new StringBuilder("FROM " + this.getClassName()); if (StringUtils.isNotEmpty(where)) { commonHql.append(" " + this.getEntityName() + " WHERE "); commonHql.append(where); } if (StringUtils.isNotEmpty(select)) { commonHql.insert(0, select); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()); //query.setCacheable(true); //query.setCacheable(false); //query.setFetchSize(30); if( max != 0 ) { query.setFirstResult(first); query.setMaxResults(max); } commonHql.delete(0, commonHql.length()); List<T> list = query.list(); return list; } /** * @function 取得当前表数据的总数 * @param hql 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @return long 数据总数 */ protected long getCount() { final String hql = "SELECT COUNT(*) FROM " + this.getClassName(); return Integer.valueOf(this.getCurrnentSession().createQuery(hql).uniqueResult().toString()); } /** * @function 取得复合查询条件的记录数 * @param where 查询语句 this.getEntityName()+".name=? " * @param params 查询的条件 * @return long 数据总数 */ protected long getCount(String hql, Object[] params) { if (params == null) { return getCount(); } StringBuilder commonHql = new StringBuilder("SELECT COUNT(*) FROM " + this.getClassName()); if (StringUtils.isNotEmpty(hql)) { commonHql.append(" " + this.getEntityName() + " WHERE "); commonHql.append(hql); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()).setCacheable(true); for (int i = 0; i < params.length; i++) { query.setParameter(i, params[i]); } commonHql.delete(0, commonHql.length()); return Long.valueOf(String.valueOf(query.list().get(0))); } /** * @function 取得复合查询条件的记录数 * @param where 查询语句 this.getEntityName()+".name=? " * @return long 数据总数 */ protected long getCount(String where) { if( StringUtils.isEmpty(where) ) { return getCount(); } StringBuilder commonHql = new StringBuilder("SELECT COUNT(*) FROM " + this.getClassName()); if (StringUtils.isNotEmpty(where)) { commonHql.append(" " + this.getEntityName() + " WHERE "); commonHql.append(where); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()); commonHql.delete(0, commonHql.length()); return Long.valueOf(String.valueOf(query.list().get(0))); } protected String getEntityName() { return this.entityClass.getSimpleName().toLowerCase(); } private String getClassName() { return this.entityClass.getSimpleName(); } /** * @function 取得TOP n条记录 * @param String where * @param int top * @return List<T> */ protected List<T> topHQL(String where, int top) { StringBuilder commonHql = new StringBuilder(" FROM " + this.getClassName()); if (StringUtils.isNotEmpty(where)) { commonHql.append(" ").append(where); } Query query = this.getCurrnentSession().createQuery(commonHql.toString()); query.setFirstResult(0); query.setMaxResults(top); //query.setFetchSize(top); commonHql.delete(0, commonHql.length()); List<T> list = query.list(); return list; } /** * @function HQL查询原生接口 * @param sql select * from entityClass where ? * @return List resultSet */ protected List commonSQL(String sql) { Query query = this.getCurrnentSession().createQuery(sql); return query.list(); } /** * @function SQL查询原生接口 * @param sql select * from tablename where ? * @return List resultSet */ public List commonSql(String sql) { SQLQuery query = this.getCurrnentSession().createSQLQuery(sql); return query.list(); } /** * @function SQL查询原生接口 * @param sql create table tablename * @return int sql执行状态 */ public int commondSql(String sql) { SQLQuery query = this.getCurrnentSession().createSQLQuery(sql); return query.executeUpdate(); } /** * @function 调用存储过程 * @param String pro 调用存储过程语句 * @return int 执行状态 */ public int callProcedure(String pro) { StringBuilder builder = new StringBuilder("CALL ").append(pro).append(""); SQLQuery query = this.getCurrnentSession().createSQLQuery(builder.toString()); return query.executeUpdate(); } /** * @function 生成HQL连接查询工具 * @param where 查询语句 select... * @param currentPage 当前页码 * @param rowNum 每页显示记录数 * @return QueryResult 带有翻页数据的bean * @author Zhangtr * @since 20120917 */ protected QueryResult<T> commonConHQLofPage(String where, int currentPage, int rowNum) { StringBuilder commonHql = new StringBuilder(where); int first=(currentPage-1)*rowNum; int max=rowNum; Query query = this.getCurrnentSession().createQuery(where); if( max > 0 ) { query.setFirstResult(first); query.setMaxResults(max); } commonHql.delete(0, commonHql.length()); List<T> list = query.list(); //设置结果集 Long totalrecord = getConCount(where); QueryResult<T> qResult = new QueryResult<T>(totalrecord, currentPage, rowNum); qResult.setResultlist(list); //设置结果集 return qResult; } /** * @function 根据hql连接查询语句生成查询行数的语句 * @param where 查询语句 select... * @author Zhangtr * @since 20120918 */ protected long getConCount(String where) { final String hql =where.replaceAll("select", "SELECT COUNT(").replaceAll("from", ") from"); return Long.valueOf(this.getCurrnentSession().createQuery(hql).uniqueResult().toString()); } /** * @function 原生sql查分页 * @param where 查询语句 select... * @param currentPage 当前页码 * @param rowNum 每页显示记录数 * @return QueryResult 带有翻页数据的bean * @author Zhangtr * @since 20120920 */ protected QueryResult<T> commonSQLofPage(String where, int currentPage, int rowNum) { StringBuilder commonHql = new StringBuilder(where); int first=(currentPage-1)*rowNum; int max=rowNum; Query query = this.getCurrnentSession().createSQLQuery(where).addEntity(TauthAccount.class); if( max > 0 ) { query.setFirstResult(first); query.setMaxResults(max); } commonHql.delete(0, commonHql.length()); List<T> list = query.list(); //设置结果集 Long totalrecord = getSqlCount(where); QueryResult<T> qResult = new QueryResult<T>(totalrecord, currentPage, rowNum); if(list!=null&&list.size()>0){ qResult.setResultlist(list); //设置结果集 } return qResult; } //原生sql查行数 protected long getSqlCount(String where) { final String sql ="SELECT COUNT(*) from ("+where+")"; return Long.valueOf(this.getCurrnentSession().createSQLQuery(sql).uniqueResult().toString()); } /** * @function 生成HQL查询工具,添加应用缓存策略 * @param where 查询语句 "WHERE" + this.getEntityName()+".name=? " * @return List<T> 查询结果集 */ public List<T> cacheHql(String where) { System.out.println("执行查询"); StringBuilder cacheHql = new StringBuilder("FROM " + this.getClassName()); if( where != null && where.length() > 0 ) { cacheHql.append(" ").append(where); } Query query = this.getCurrnentSession().createQuery(cacheHql.toString()).setCacheable(true); return query.list(); } /** * @function 根据实体类查找sortnum列最大的数 * @param where 查询语句 select... * @author Zhangtr * @since 20120918 */ protected long getMaxSortNum(Object obj) { String hql="SELECT MAX(u.sortnum) FROM "+obj.getClass().getName()+" u "; return Long.valueOf(this.getCurrnentSession().createQuery(hql).uniqueResult().toString()); } } |
|||
二维柱状图/饼状图统计组件 | java 统计组件 | ||
package com.css.service.impl; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import com.css.bean.TXtDm; import com.css.dao.TZddqZddqDao; import org.springframework.stereotype.Service; import org.apache.commons.lang.StringUtils; import com.css.service.TjfxService; import com.css.sys.service.TXtDmService; /** * @function 统计分析业务组件 * @description * @version 1.0 * @author liangbo time at 29/1/2013 */ @Service("tjfxService") public class TjfxServiceImpl implements TjfxService { @Resource private TXtDmService tXtDmService; @Resource private TZddqZddqDao tZddqZddqDao; final String monthNames[] = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}; /** * @function 重点地区区域统计业务方法 * @param area 区域行政编码 * @param fromdate 开始时间 * @param todate 结束时间 * @return 返回统计xml数据 */ public String showAreaCharts(String area, String fromdate, String todate) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area)){ StringBuilder dmsql =new StringBuilder("WHERE 1=1 AND CODETYPE = 'XZQH'"); //省级统计 if(area.matches("[1-9]{2}0000")) { dmsql.append(" AND code like '13%00' and code <> '130000'"); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { dmsql.append(" AND code like '" + area.substring(0, 4) + "%'"); } List<TXtDm> xzqhList = tXtDmService.getTXtDmList(dmsql.toString()); dmsql.delete(0, dmsql.length()); if(xzqhList!=null&&xzqhList.size()>0){ //省级统计 if(area.matches("[1-9]{2}0000")){ for (TXtDm tXtDm : xzqhList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); String code=tXtDm.getCode(); if(!StringUtils.isEmpty(code)&&code.matches("[1-9]{2}[0-9]{4}")){ hql.append(" and a.xzqh like '"+code.substring(0, 4)+"%' "); } if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } }else if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")){ for (TXtDm tXtDm : xzqhList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); String code=tXtDm.getCode(); if(!StringUtils.isEmpty(code)&&code.matches("[1-9]{2}[0-9]{4}")){ hql.append(" and a.xzqh = '"+code+"' "); } if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } } } return result.toString(); } /** * @function 重点地区按月统计业务方法 统计以开始时间年份为统计基础 * @param area 区域行政编码 * @param fromdate 开始时间 * @return 返回统计xml数据 */ public String showMouthCharts(String area, String fromdate) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area)){ if(StringUtils.isEmpty(fromdate)){ Calendar cal = Calendar.getInstance(); fromdate=new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()); } StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a where 1=1 "); //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String date = fromdate.substring(0, 4); getTimeLabel(result,hql,date); } return result.toString(); } /** * @function 重点地区分类统计业务方法 * @param area 区域行政编码 * @param fromdate 开始时间 * @param todate 结束时间 * @param type 统计类型 * @return 返回统计xml数据 */ public String showCharts(String area, String fromdate, String todate,String type) { StringBuilder result=new StringBuilder(""); if(!StringUtils.isEmpty(area) && !StringUtils.isEmpty(type)){ StringBuilder dmsql = new StringBuilder(""); if(type.contains("SF")) { dmsql.append("WHERE 1=1 AND CODETYPE = '" + type.substring(0, 2) + "' "); } else { dmsql.append("WHERE 1=1 AND CODETYPE = '" + type + "' "); } List<TXtDm> codeTypeList = tXtDmService.getTXtDmList(dmsql.toString()); dmsql.delete(0, dmsql.length()); if(codeTypeList!=null && codeTypeList.size()>0){ //如果统计类型为GPLB或zzqx查询条件以B表为基准,否则以a表为基准 if(type.equalsIgnoreCase("GPLB") || type.equalsIgnoreCase("ZZQX")) { for (TXtDm tXtDm : codeTypeList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a , ZDDQ.T_ZDDQ_GPDB b where 1=1 AND a.id = b.zddqid "); String code=tXtDm.getCode(); String bType = "b." + type; hql.append(" AND " + bType + "='" + code + "' "); if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } else { for (TXtDm tXtDm : codeTypeList) { StringBuilder hql=new StringBuilder("select COUNT(1) from ZDDQ.T_ZDDQ_ZDDQ a , ZDDQ.T_ZDDQ_GPDB b where 1=1 AND a.id = b.zddqid "); String code=tXtDm.getCode(); String aType = "a." + type; hql.append(" AND " + aType + "='" + code + "' "); if(!StringUtils.isEmpty(fromdate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)>='"+fromdate+"'" ); } if(!StringUtils.isEmpty(todate)){ hql.append(" and SUBSTRING(convert(varchar,a.cjsj),0,10)<='"+todate+"'" ); } //省级统计 if(area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh like '13%' "); } //市级统计 if(area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00")) { hql.append(" AND a.xzqh like '" + area.substring(0, 4) + "%' "); } if(area.matches("[1-9]{2}[0-9]{4}") && !area.matches("[1-9]{2}([1-9]{1}[0-9]{1}|[0-9]{1}[1-9]{1})00") && !area.matches("[1-9]{2}0000")) { hql.append(" AND a.xzqh = '" + area + "' "); } String count=tZddqZddqDao.queryCount(hql.toString()); hql.delete(0, hql.length()); result.append(" <set value='"+count+"' label='"+tXtDm.getCodename()+"' />"); } } } } return result.toString(); } public void getTimeLabel(StringBuilder result,StringBuilder where,String date) { if(where != null && !StringUtils.isEmpty(date)) { for(int i=0; i<=11;i++) { String sql = where.toString(); int j = i + 1; String mDate = ""; if(j < 10) { mDate = date + "-0" + j; } else if( j >= 10){ mDate = date + "-" + j; } sql = sql + " AND SUBSTRING(convert(varchar,a.cjsj),0,7) = '" + mDate + "' "; //System.out.println(sql.toString()); String count=tZddqZddqDao.queryCount(sql); result.append(" <set value='"+count+"' label='"+monthNames[i] +"' />"); } } } } |