Date and string are converted to each other (including backward time periods) __java

Source: Internet
Author: User
Package Com.ds.hfcp.dao.impl;


Import Java.math.BigDecimal;
Import Java.text.SimpleDateFormat;
Import java.util.ArrayList;
Import Java.util.Date;
Import java.util.List;


Import Javax.persistence.EntityManager;
Import Javax.persistence.PersistenceContext;
Import Javax.persistence.Query;


Import Org.slf4j.Logger;
Import Org.slf4j.LoggerFactory;
Import Org.springframework.stereotype.Repository;


Import Com.ds.hfcp.dao.ITrivialAnalysisDao;
Import com.ds.hfcp.exception.PoliceSituationException;
Import Com.ds.hfcp.vo.HandleReasonVO;
Import Com.ds.hfcp.vo.HandleTrendVO;
Import Com.ds.hfcp.vo.HandleUnitVO;


/**
* Miscellaneous Analysis
* @author OP
*
*/
@Repository
public class Trivialanalysisdaoimpl implements Itrivialanalysisdao {

@PersistenceContext
Private Entitymanager em;


Private final Logger Logger = Loggerfactory.getlogger (GetClass ());



/**
* Miscellaneous-units-the previous period of shun-push time
*/
Public listLogger.error ("= = = = = = Trivialanalysisdaoimpl = = = Findhandleunitpublish = = Begin");
list

try {

String orgtwo = Handleunitvo.getorgtwo ();
String starttime = Handleunitvo.getstarttime ();
String endtime = Handleunitvo.getendtime ();
String Statisticsway = Handleunitvo.getstatisticsway ();

Date DateStart = new SimpleDateFormat ("Yyyy-mm-dd"). Parse (starttime);
Date dateend = new SimpleDateFormat ("Yyyy-mm-dd"). Parse (Endtime);
Number of days apart/(24*60*60*1000)
Long day= (Dateend.gettime ()-datestart.gettime ());
The start time of pushing forward
String earlystartdate = new SimpleDateFormat ("Yyyy-mm-dd"). Format (Datestart.gettime ()-day);

String sql = null;

if ("All". Equals (Orgtwo)) {

sql = "Select DISTINCT tt.jc,count (1)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2"
+ "and tt.sjdw=4"
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";

sql = "Select Temp.jc,sum (TEMP.BH)"
+ "from" (select DISTINCT t.sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and t.xxbb_t Ype=0 and TT. Sjdw=4 "
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ ' GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC ' temp GROUP by TEMP.JC;


sql = "Select DISTINCT tt.jc,sum (TT.BH)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue"
+ "and tt.sjdw=4"
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";



}else {

sql = "Select DISTINCT tt.jc,count (1)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2"
+ "and tt.sjdw=4"
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";

sql = "Select Temp.jc,sum (TEMP.BH)"
+ "from" (select DISTINCT t.sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and t.xxbb_t Ype=0 and TT. Sjdw=4 "
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ ' GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC ' temp GROUP by TEMP.JC;


sql = "Select DISTINCT tt.jc,sum (TT.BH)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue"
+ "and tt.sjdw=4"
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";




}


Query query = em.createnativequery (SQL);

@SuppressWarnings ("Unchecked")
list<object> objectList = Query.getresultlist ();


if (null!= objectList && 0 < Objectlist.size ()) {
for (int i = 0; i < objectlist.size (); i++) {
object[] obj = (object[]) objectlist.get (i);

Handleunitvo vo = new Handleunitvo ();

if (null!= obj[0]) {//unit abbreviation
VO.SETJC (obj[0].tostring (). Trim ());
} else {
VO.SETJC ("");
}
if (null!= obj[1]) {//Total number of cases
Vo.setcasenum ((BigDecimal) obj[1]);
} else {
Vo.setcasenum (new BigDecimal (0));
}

List.add (VO);

}
}

catch (Exception e) {
throw new Policesituationexception ("Method Execution Error: Findhandleunitpublish method execution failed");
}
Logger.error ("= = = = Trivialanalysisdaoimpl = = = Findhandleunitpublish = = End");
return list;
}





/**
* Miscellaneous-units
*/
Public listLogger.error ("= = = = = = Trivialanalysisdaoimpl = = = Findhandleunit = = Begin");
list

try {

String orgtwo = Handleunitvo.getorgtwo ();
String starttime = Handleunitvo.getstarttime ();
String endtime = Handleunitvo.getendtime ();

String sql = null;

if ("All". Equals (Orgtwo)) {

sql = "Select DISTINCT tt.jc,count (1)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2"
+ "and tt.sjdw=4"
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";

sql = "Select Temp.jc,sum (TEMP.BH)"
+ "from" (select DISTINCT t.sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and t.xxbb_t Ype=0 and TT. Sjdw=4 "
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ ' GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC ' temp GROUP by TEMP.JC;


sql = "Select DISTINCT tt.jc,sum (TT.BH)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue"
+ "and tt.sjdw=4"
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";


}else {


sql = "Select DISTINCT tt.jc,count (1)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2"
+ "and tt.sjdw=4"
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";

sql = "Select Temp.jc,sum (TEMP.BH)"
+ "from" (select DISTINCT t.sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and t.xxbb_t Ype=0 and TT. Sjdw=4 "
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ ' GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC ' temp GROUP by TEMP.JC;

sql = "Select DISTINCT tt.jc,sum (TT.BH)"
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where ttt.ref_typeid=301 and T.xxbb_type=0 and T.info_type=ttt.dicvalue"
+ "and tt.sjdw=4"
+ "and tt.jc= '" +orgtwo+ ""
+ "and T.SBSJ BETWEEN to_date (' +starttime+" ', ' Yyyy-mm-dd ') and to_date (' +endtime+ ', ' yyyy-mm-dd ') "
+ "GROUP by TT.JC";



}


Query query = em.createnativequery (SQL);

@SuppressWarnings ("Unchecked")
list<object> objectList = Query.getresultlist ();


if (null!= objectList && 0 < Objectlist.size ()) {
for (int i = 0; i < objectlist.size (); i++) {
object[] obj = (object[]) objectlist.get (i);

Handleunitvo vo = new Handleunitvo ();

if (null!= obj[0]) {//unit abbreviation
VO.SETJC (obj[0].tostring (). Trim ());
} else {
VO.SETJC ("");
}
if (null!= obj[1]) {//Total number of cases
Vo.setcasenum ((BigDecimal) obj[1]);
} else {
Vo.setcasenum (new BigDecimal (0));
}

List.add (VO);

}
}

catch (Exception e) {
throw new Policesituationexception ("Method Execution Error: Findhandleunit method execution failed");
}
Logger.error ("= = = = Trivialanalysisdaoimpl = = = Findhandleunit = = End");
return list;
}


/**
* Miscellaneous--Trends--release period
*/
@Override
Public listLogger.error ("= = = = = = Trivialanalysisdaoimpl = = = Findhandletrendpublish = = Begin");
list

try {

String orgtwo = Handletrendvo.getorgtwo ();
String starttime = Handletrendvo.getstarttime ();
String endtime = Handletrendvo.getendtime ();
String Statisticsway = Handletrendvo.getstatisticsway ();

Date DateStart = new SimpleDateFormat ("Yyyy-mm-dd"). Parse (starttime);
Date dateend = new SimpleDateFormat ("Yyyy-mm-dd"). Parse (Endtime);
Number of days apart/(24*60*60*1000)
Long day= (Dateend.gettime ()-datestart.gettime ());
The start time of pushing forward
String earlystartdate = new SimpleDateFormat ("Yyyy-mm-dd"). Format (Datestart.gettime ()-day);


String sql = null;

if ("Per day Analysis". Equals (Statisticsway)) {
if ("All". Equals (Orgtwo)) {
sql = "Select Temp.sbsj,sum (TEMP.BH)"
+ "from"
+ "(select To_char (T.SBSJ, ' yyyy-mm-dd ') sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and T.xxbb_type =0 and Tt.sjdw=4 and "
+ "T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC Order by T.SBSJ ASC", temp Group by TEMP.SBSJ;
}else {
sql = "Select Temp.sbsj,sum (TEMP.BH)"
+ "from"
+ "(select To_char (T.SBSJ, ' yyyy-mm-dd ') sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and T.xxbb_type =0 and Tt.sjdw=4 and "
+ "tt.jc= '" "+orgtwo+" "
+ "and T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC Order by T.SBSJ ASC", temp Group by TEMP.SBSJ;
}

} else {
Analysis by month
if ("All". Equals (Orgtwo)) {
sql = "Select Temp.sbsj,sum (TEMP.BH)"
+ "from"
+ "(select To_char (T.SBSJ, ' yyyy-mm ') sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBDWBH (+) and ttt.ref_typeid=301 and T.info_type=ttt.dicvalue and Ttt.dicvalue<>2 and T.xxbb_type =0 and Tt.sjdw=4 and "
+ "T.SBSJ BETWEEN to_date (' +earlystartdate+" ', ' Yyyy-mm-dd ') and to_date (' +starttime+ ', ' yyyy-mm-dd ') "
+ "GROUP by T.SBSJ,TT.BH,TT.SJDW,TT.DM,TT.JC Order by T.SBSJ ASC", temp Group by TEMP.SBSJ;
}else {
sql = "Select Temp.sbsj,sum (TEMP.BH)"
+ "from"
+ "(select To_char (T.SBSJ, ' yyyy-mm ') sbsj,tt.bh,tt. Sjdw,tt.jc,count (1) "
+ "from T_xxbb t,t_bd_dw tt, T_dictionary TTT"
+ "where TT.BH=T.SBD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.