apzl_leasing/src_tenwa/com/tenwa/loan/action/LoanFundBalanceAction.java
2018-06-03 22:26:41 +08:00

185 lines
6.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.loan.action;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.BizObjectKey;
import com.amarsoft.are.jbo.BizObjectManager;
import com.amarsoft.are.jbo.JBOFactory;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.are.util.json.JSONEncoder;
import com.amarsoft.are.util.json.JSONObject;
import com.amarsoft.awe.util.json.JSONValue;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.flow.action.comm.BaseTable;
import jbo.loan.LOAN_FUND_BALANCE;
public class LoanFundBalanceAction extends BaseTable {
private String calcDate;
private String fundBalanceParam;
private String queryDate;
public String getCalcDate() {
return calcDate;
}
public void setCalcDate(String calcDate) {
this.calcDate = calcDate;
}
public String getFundBalanceParam() {
return fundBalanceParam;
}
public void setFundBalanceParam(String fundBalanceParam) {
this.fundBalanceParam = fundBalanceParam;
}
public String getQueryDate() {
return queryDate;
}
public void setQueryDate(String queryDate) {
this.queryDate = queryDate;
}
/**
* ÐÂÔö±¾·½ÕË»§Óà¶î
* @param tx
* @return
* @throws JBOException
* @throws RecordNotFoundException
*/
public String addFundBalance(JBOTransaction tx) throws Exception{
String[] params = fundBalanceParam.split("@");
BizObjectManager lfbManager = JBOFactory.getBizObjectManager(LOAN_FUND_BALANCE.CLASS_NAME, tx);
for(int i=0; i<params.length;i+=3){
BizObject newlfb = lfbManager.newObject();
BizObject lfb = lfbManager.createQuery(" OWN_ACCOUNT_ID=:ownaccountid and INPUTDATE=:inputdate ").setParameter("ownaccountid",params[i]).setParameter("inputdate",calcDate).getSingleResult(false);
if(lfb==null){
newlfb.setAttributeValue("OWN_ACCOUNT_ID",params[i]);
newlfb.setAttributeValue("OWN_ACCOUNT",params[i+1]);
newlfb.setAttributeValue("OWN_ACCOUNT_BALANCE",params[i+2]);
newlfb.setAttributeValue("INPUTDATE",calcDate);
newlfb = this.initTabeUserInfo(newlfb);
lfbManager.saveObject(newlfb);
}else{
BizObjectKey key=lfbManager.getKey();
key.setAttributeValue("ID", lfb.getAttribute("ID").toString());
newlfb=lfbManager.getObject(key);
newlfb.setAttributeValue("OWN_ACCOUNT",params[i+1]);
newlfb.setAttributeValue("OWN_ACCOUNT_BALANCE",params[i+2]);
newlfb = this.initTabeUserInfo(newlfb);
lfbManager.saveObject(newlfb);
}
}
return "success";
}
/**
* չʾ½üÒ»ÖܵÄÕË»§Óà¶î
* @param tx
* @return
* @throws Exception
*/
public List<Map<String,String>> showFundBalanceForWeek(JBOTransaction tx) throws Exception{
Calendar calendar = Calendar.getInstance();
List<Map<String,String>> results = showFundBalanceByCalendar(calendar,tx);
return results;
}
/**
* ¸ù¾ÝÖ¸¶¨ÈÕÆÚ²éѯÕË»§Óà¶î
* @param tx
* @return
* @throws Exception
*/
public String queryDataByDate(JBOTransaction tx) throws Exception{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Calendar queryCalendar = Calendar.getInstance();
queryCalendar.setTime(sdf.parse(queryDate));
List<Map<String,String>> results = showFundBalanceByCalendar(queryCalendar,tx);
return JSONArray.fromObject(results).toString();
}
/**
* ¸ù¾Ýcalendar²éѯµ±ÖÜÕË»§Óà¶î
* @param calendar
* @param tx
* @return
* @throws Exception
*/
public List<Map<String,String>> showFundBalanceByCalendar(Calendar calendar,JBOTransaction tx) throws Exception{
Map<String,String> showDates = showDatesForWeek(calendar);
List<Map<String,String>> results = new ArrayList<Map<String,String>>();
Map<String,String> result = new HashMap<String,String>();
result.put("own_name","³ö×âÈË");
result.put("acc_number","±¾·½Õ˺Å");
result.put("acc_bank","±¾·½ÒøÐÐ");
for (String key : showDates.keySet()) {
result.put(key,showDates.get(key));
}
results.add(result);
String sql = "SELECT oa.ID,oa.ACC_NUMBER,oa.ACC_BANK,oi.OWN_NAME FROM own_account oa LEFT JOIN OWN_INFO oi ON oa.own_id=oi.own_number ORDER BY oa.acc_number ";
List<Map<String,String>> ownAccountList=DataOperatorUtil.getDataBySql(tx, sql, null);
if(ownAccountList.size()>0){
for(Map<String,String> ownAccount:ownAccountList){
result = new HashMap<String,String>();
result.put("own_name",ownAccount.get("OWN_NAME"));
result.put("acc_number",ownAccount.get("ACC_NUMBER"));
result.put("acc_bank",ownAccount.get("ACC_BANK"));
List<BizObject> lfbs = JBOFactory.createBizObjectQuery(LOAN_FUND_BALANCE.CLASS_NAME, "select O.OWN_ACCOUNT_BALANCE,O.INPUTDATE FROM O WHERE O.OWN_ACCOUNT_ID=:ownaccountid and O.INPUTDATE>='"+showDates.get("1day")+"' AND O.INPUTDATE<='"+showDates.get("7day")+"' order by O.INPUTDATE ").setParameter("ownaccountid",ownAccount.get("ID")).getResultList(false);
if(lfbs.size()>0){
Map<String,String> compareDate = new HashMap<String,String>();
for(BizObject lfb:lfbs){
String inputDate = lfb.getAttribute("INPUTDATE").getString();
for (String key : showDates.keySet()) {
if(showDates.get(key).equals(inputDate)){
result.put(key,lfb.getAttribute("OWN_ACCOUNT_BALANCE").getString());
compareDate.put(key,key);
}
}
}
if(compareDate.size()<showDates.size()){
for (String key : showDates.keySet()) {
if(!compareDate.containsKey(key)){
result.put(key,"0.00");
}
}
}
}else{
for (String key : showDates.keySet()) {
result.put(key,"0.00");
}
}
results.add(result);
}
}
return results;
}
/**
* ¸ù¾Ýcalendar²éѯ¸ÃÖÝÈÕÆÚ
* @param calendar
* @return
*/
public Map<String,String> showDatesForWeek(Calendar calendar){
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if(dayOfWeek==1){
dayOfWeek=8;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
String showDate="";
Map<String,String> showDates = new HashMap<String,String>();
for(int i=1;i<=7;i++){
Date date = new Date();
date.setTime(calendar.getTime().getTime()+(2-dayOfWeek+i-1)*24*3600000);
showDate = sdf.format(date);
showDates.put(i+"day",showDate);
}
return showDates;
}
}