AccountYmDataDao

package  com.ing.reinsurance.persistence.dao.parameterData;

import  java.text.SimpleDateFormat;
import  java.util.Date;
import  java.util.List;

import  org.apache.log4j.Logger;

import  com.ing.persistence.EntityManager;
import  com.ing.reinsurance.persistence.dao.BaseDao;
import  com.ing.reinsurance.persistence.mapping.parameterData.AccountYmData;
import  com.ing.reinsurance.util.CombinedQuery;
import  com.ing.reinsurance.util.Constant;
import  com.ing.reinsurance.util.DateUtility;
import  com.ing.reinsurance.view.parameterMaintenance.reItem.PageInfo;
import  com.ing.reinsurance.view.parameterMaintenance.reportParam.AccountYmVO;

public   class  AccountYmDataDao  extends  BaseDao  {

    
private static final Logger LOG = Logger.getLogger(AccountYmDataDao.class);

    
/**
     * AccountYmDataDao靜態實例
     
*/

    
private static AccountYmDataDao INSTANCE;

    
/**
     * 構造函數
     * 
     
*/

    
public AccountYmDataDao() {
        
// TODO Auto-generated constructor stub
    }

    

    
/**
     * description: 得到ReOthersTypeRateDataDao的實例,初始化EntityManager
     * 
     * 
@param entmgr
     *            EntityManager
     * 
@return ReOthersTypeRateDataDao
     
*/

    
public static AccountYmDataDao getInstance(EntityManager entmgr){
        
if (INSTANCE == null){
            INSTANCE 
= new AccountYmDataDao();
            INSTANCE.setMgr(entmgr);    
// 初始化EntityManager
        }

        
return INSTANCE;
    }

    
    
/**
     * description:根據會計年月查詢與之相符合的紀錄
     * 
     * 
@param strAccountYmDate
     *            String
     * 
@param startRow
     *            int
     * 
@param numberOfRows
     *            int
     * 
@return List
     
*/

    
public List selectListByAccountYmDate(String strAccountYmDate,
            
int startRow, int numberOfRows) {

        LOG.info(
"[AccountYmDataDao][FUNCTION:selectListByAccountYmDate]"
                
+ "[Param ParaMenuData:" + strAccountYmDate + "][begin]");
        
        String hql 
= " from AccountYmData as av";
        
if (!"".equals(strAccountYmDate)) {    // 如果輸入不為空,條件查詢
            hql += " where av.id.accountYmDate = '" + strAccountYmDate
                    
+ "' order by av.id.accountYmDate";
        }
 else // 如果輸入為空,模糊查詢
            hql += " order by av.id.accountYmDate";
        }


        List list 
= this.HQueryByPage(hql, startRow, numberOfRows);

        
if (list != null && list.size() > 0{
            LOG
                    .debug(
"[FUNCTION:selectListByAccountYmDate]select list success!");
            
return list;
        }
 else {
            LOG
                    .debug(
"[FUNCTION:selectListByAccountYmDate]select list return null!");
            
return null;
        }

    }


    
/**
     * description: 根據會計年月查詢與之相符合的紀錄
     * 
     * 
@param accountYmVO
     *            AccountYmVO
     * 
@param startRow
     *            起始行
     * 
@param numberOfRows
     *            讀取行數
     * 
@return List
     
*/

    
public List selectListByCode(AccountYmVO accountYmVO, int startRow,
            
int numberOfRows) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:selectListByCode][Param AccountYmVO"
                        
+ accountYmVO + "][begin]");
        
        CombinedQuery cq 
= new CombinedQuery("AccountYmData");
        
//hql.append(" from " + tableName + " as t where 1=1 ");
        
// hql 此時為 " from AccountYmData as t where 1 = 1
        
// 相當於查詢所有數據
        
        cq.appendKey(
"accountYmDate", accountYmVO.getAccountYmDate());// 會計年月
        cq.appendKeyOrderBy("boundDate,t.id.accountYmDate ", CombinedQuery.DESC);// 以會計年月排序
        
        List list 
= this.HQueryByPage(cq.getHql().toString(), cq.getMap(),
                startRow, numberOfRows);

        
if (list != null && list.size() > 0{
            LOG.debug(
"[FUNCTION:selectListByCode]select list success!");
            
return list;
        }
 else {
            LOG.debug(
"[FUNCTION:selectListByCode]select list return null!");
            
return null;
        }

    }


    
/**
     * 根據查詢條件返回頁面的信息
     * 
     * 
@param accountYmVO
     *            封裝查詢條件的VO
     * 
@param iCurrentPage
     *            當前頁碼
     * 
@return PageInfo 頁面信息
     
*/

    
public PageInfo getPageInfo(AccountYmVO accountYmVO,
            
int iCurrentPage) {
        LOG
                .info(
"[AccountYmDataDao][FUNCTION:getPageInfo][Param AccountYmVO:"
                        
+ accountYmVO
                        
+ ";currentPage:"
                        
+ iCurrentPage
                        
+ "][begin]");
        List list 
= null;
        CombinedQuery cq 
= new CombinedQuery("AccountYmData");
        
        
        cq.appendKey(
"accountYmDate", accountYmVO.getAccountYmDate());
//        hql.append(" and t.id." + fieldName + " =:" + fieldName);
//        map.put(fieldName, value);
        
// sql 語句後面添加:" and t.id.accountYmDate =: accountYmDate ???
        
// 同時將值放入map中
        cq.appendSelect("select count(*) "); // 在hql前面添加字符串
        
        list 
= this.createQuery(cq.getHql().toString(), cq.getMap());

        
// 查詢頁面結果,封裝入PageInfo
        if (list != null && list.size() > 0{
            LOG.debug(
"[FUNCTION:getPageInfo]select list success!");
            PageInfo pageInfo 
= null;
            Integer integer 
= (Integer) list.get(0);
            
int totalRecord = integer.intValue();
            
if (totalRecord > 0{
                
int totalPage = (totalRecord - 1/ Constant.PAGE_PAGESIZE + 1;
                
int currentPage = iCurrentPage;
                
int startItem = (currentPage - 1* Constant.PAGE_PAGESIZE + 1;
                
int endItem = currentPage * Constant.PAGE_PAGESIZE;
                
if (endItem > totalRecord)
                    endItem 
= totalRecord;
                pageInfo 
= new PageInfo();
                pageInfo.setQueryInfo(totalRecord 
+ " items found, displaying "
                        
+ startItem + " to " + endItem);
                pageInfo.setCurrentPage(currentPage);
                pageInfo.setPageSize(Constant.PAGE_PAGESIZE);
                pageInfo.setTotalPage(totalPage);
                pageInfo.setTotalRecord(totalRecord);
                pageInfo.init();
            }

            
return pageInfo;
        }
 else {
            LOG.debug(
"[FUNCTION:getPageInfo]select list return null!");
            
return null;
        }

    }


    
/**
     * description: 取除了生效日期不同,其他key值都相同的最後一筆記錄
     * 
     * 
@param accountYmTemp
     *            AccountYmTemp
     * 
@return List
     
*/

    
public List selectLastRecord(AccountYmVO accountYmVO) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:selectLastRecorder][Param AccountYmVO: "
                        
+ accountYmVO + "]");
        List list 
= null;
        CombinedQuery cq 
= new CombinedQuery("AccountYmData");
        cq.appendKey(
"accountYmDate", accountYmVO.getAccountYmDate());// 會計年月

        cq.appendKeyOrderBy(
"boundDate", CombinedQuery.DESC);// 按日期降序排列

        list 
= this.HQueryByPage(cq.getHql().toString(), cq.getMap(), 11); // 取一條記錄
        
        
if (list != null && list.size() > 0{
            LOG.debug(
"[FUNCTION:selectLastRecord]select list success!");
            
return list;
        }
 else {
            LOG.debug(
"[FUNCTION:selectLastRecord]select list return null!");
            
return null;
        }

    }


    
/**
     * description: 取除了生效日期不同,其他key值都相同的前一筆記錄
     * 
     * 
@param accountYmVO *
     *            AccountYmVO
     * 
@return List
     
*/

    
public List selectPrewRecord(AccountYmVO accountYmVO) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:selectPrewRecord][Param AccountYmVO: "
                        
+ accountYmVO + "]");
        
        SimpleDateFormat myFmt 
= new SimpleDateFormat("yyyy-MM-dd");
        
        CombinedQuery cq 
= new CombinedQuery("AccountYmData");
        
        cq.appendKey(
"accountYmDate", accountYmVO.getAccountYmDate());// 會計年月

        cq.appendKeyLt(
"boundDate", myFmt.format(accountYmVO.getBoundDate()));//
        
        cq.appendKeyOrderBy(
"boundDate", CombinedQuery.DESC);// 按日期降序排列
        
        List list 
= this.HQueryByPage(cq.getHql().toString(), cq.getMap(), 11); // 取一條記錄
        
        
if (list != null && list.size() > 0{
            LOG.debug(
"[FUNCTION:selectLastRecord]select list success!");
            
return list;
        }
 else {
            LOG.debug(
"[FUNCTION:selectLastRecord]select list return null!");
            
return null;
        }

    }


    
/**
     * 新增數據時判斷是否新增的時間是最新的時間
     * 
     * 
@param AccountYmVO
     *            vo
     * 
     * 
@return boolean
     
*/

    
public boolean isNewRecord(AccountYmVO vo) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:isNewRecord][Param AccountYmVO:"
                
+ vo + "][begin]");
        SimpleDateFormat myFmt 
= new SimpleDateFormat("yyyy-MM-dd");

        String hql 
= "from AccountYmData as t where t.id.accountYmDate='"
                
+ vo.getAccountYmDate() // 會計年月
                + "' and t.id.boundDate>='" + myFmt.format(vo.getBoundDate())
                
+ "'";
        
        List list 
= this.HQueryByPage(hql, 11);    // 取一條記錄
        
        
if (list != null && list.size() > 0{
            LOG.debug(
"[FUNCTION:isExistSimilarRecord]select list success!");
            
return true;
        }
 else {
            LOG
                    .debug(
"[FUNCTION:isExistSimilarRecord]select list return null!");
            
return false;
        }

    }

    
    
/**
     * 新增數據時: 會計年月的日期不可以交叉,也不可以出現空缺
     * 
     * 
@param AccountYmVO
     *            vo
     * 
     * 
@return boolean
     
*/

    
public boolean isLinkedDay(AccountYmVO vo) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:isNewRecord][Param AccountYmVO:"
                
+ vo + "][begin]");
        
        
//SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");
        CombinedQuery cq = new CombinedQuery("AccountYmData");
        cq.appendOrderBy(
"t.accountEndDate",CombinedQuery.DESC);
//        String hql = "from AccountYmData order by AccountEndDate";
        
        List list 
= this.HQueryByPage(cq.getHql().toString(), 11);    // 取一條記錄
        
        
if (list != null && list.size() > 0{
            
            AccountYmData accountYmData 
= (AccountYmData)list.get(0);
            
            System.out.println(
"AccountEndData: " + accountYmData.getAccountEndDate());
            
            Date tomorrow 
= DateUtility.getTomorrow(accountYmData.getAccountEndDate());
//            System.out.println("AccountEndData's tomorrow: " + tomorrow);
//            System.out.println("VO.AccountStartData: " + vo.getAccountStartDate());
//            System.out.println( tomorrow.compareTo(vo.getAccountStartDate()));
            if0 == tomorrow.compareTo(vo.getAccountStartDate())){
                System.out.println(
"OK");
                LOG.debug(
"[FUNCTION:isExistSimilarRecord]select list success!");
                
return true;
            }

            
            
return false;
        }
 else {
            LOG.debug(
"[FUNCTION:isExistSimilarRecord]select list return null!");
            
return false;
        }

    }

    
    
/**
     * 新增數據時: 會計年月的日期不可以交叉,也不可以出現空缺
     * 
     * 
@param AccountYmVO
     *            vo
     * 
     * 
@return boolean
     
*/

    
public boolean isEndRecord(AccountYmVO vo) {
        LOG.info(
"[AccountYmDataDao][FUNCTION:isNewRecord][Param AccountYmVO:"
                
+ vo + "][begin]");
        
        
//SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd");
        CombinedQuery cq = new CombinedQuery("AccountYmData");
        cq.appendOrderBy(
"t.accountEndDate",CombinedQuery.DESC);
//        String hql = "from AccountYmData order by AccountEndDate";
        
        List list 
= this.HQueryByPage(cq.getHql().toString(), 11);    // 取一條記錄
        
        
if (list != null && list.size() > 0{
            
            AccountYmData accountYmData 
= (AccountYmData)list.get(0);
            
            System.out.println(
"AccountEndData: " + accountYmData.getAccountEndDate());
            
//            Date tomorrow = DateUtility.getTomorrow(accountYmData.getAccountEndDate());
//            System.out.println("AccountEndData's tomorrow: " + tomorrow);
//            System.out.println("VO.AccountStartData: " + vo.getAccountStartDate());
//            System.out.println( tomorrow.compareTo(vo.getAccountStartDate()));
            if0 == accountYmData.getAccountEndDate().compareTo(vo.getAccountEndDate())){
                
//System.out.println("OK");
                LOG.debug("[FUNCTION:isExistSimilarRecord]select list success!");
                
return true;
            }

            
            
return false;
        }
 else {
            LOG.debug(
"[FUNCTION:isExistSimilarRecord]select list return null!");
            
return false;
        }

    }


}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值