优化账户流水(涉及多账户)
This commit is contained in:
@@ -305,13 +305,13 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
item.put("serialNo", account.getSerialNo());
|
||||
item.put("initialAmount", account.getInitialAmount());
|
||||
String monthTime = Tools.getCurrentMonth();
|
||||
Double thisMonthAmount = getAccountSum(account.getId(), monthTime) + getAccountSumByHead(account.getId(), monthTime) +getAccountSumByDetail(account.getId(), monthTime);
|
||||
Double thisMonthAmount = getAccountSum(account.getId(), monthTime) + getAccountSumByHead(account.getId(), monthTime) +getAccountSumByDetail(account.getId(), monthTime) + getManyAccountSum(account.getId(), monthTime);
|
||||
String thisMonthAmountFmt = "0";
|
||||
if(thisMonthAmount!=0){
|
||||
thisMonthAmountFmt = df.format(thisMonthAmount);
|
||||
}
|
||||
item.put("thisMonthAmount", thisMonthAmountFmt); //本月发生额
|
||||
Double currentAmount = getAccountSum(account.getId(),"") + getAccountSumByHead(account.getId(), "") + getAccountSumByDetail(account.getId(), "") + account.getInitialAmount();
|
||||
Double currentAmount = getAccountSum(account.getId(),"") + getAccountSumByHead(account.getId(), "") + getAccountSumByDetail(account.getId(), "") + getManyAccountSum(account.getId(), "") + account.getInitialAmount();
|
||||
String currentAmountFmt=df.format(currentAmount);
|
||||
item.put("currentAmount", currentAmountFmt); //当前余额
|
||||
item.put("remark", account.getRemark());
|
||||
@@ -405,8 +405,6 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
}
|
||||
ids = ids.substring(0,ids.length() -1);
|
||||
|
||||
System.out.println(">>>>>>>>>>>>>>>>>" + ids);
|
||||
|
||||
PageUtil<AccountItem> pageUtilOne = new PageUtil<AccountItem>();
|
||||
pageUtilOne.setPageSize(0);
|
||||
pageUtilOne.setCurPage(0);
|
||||
@@ -418,8 +416,6 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
accountSum = accountSum + accountItem.getEachAmount();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(">>>>>>>>>>>>>>>>>accountSum:" + accountSum);
|
||||
}
|
||||
}
|
||||
catch (DataAccessException e){
|
||||
@@ -431,6 +427,42 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
return accountSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个账户的金额求和-多账户的明细合计
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Double getManyAccountSum(Long id,String monthTime){
|
||||
Double accountSum = 0.0;
|
||||
try{
|
||||
PageUtil<DepotHead> pageUtil = new PageUtil<DepotHead>();
|
||||
pageUtil.setPageSize(0);
|
||||
pageUtil.setCurPage(0);
|
||||
pageUtil.setAdvSearch(getCondition_getManyAccountSum(id,monthTime));
|
||||
depotHeadService.find(pageUtil);
|
||||
List<DepotHead> dataList = pageUtil.getPageList();
|
||||
if(dataList!= null){
|
||||
for(DepotHead depotHead:dataList){
|
||||
String accountIdList = depotHead.getAccountIdList();
|
||||
String accountMoneyList = depotHead.getAccountMoneyList();
|
||||
accountIdList = accountIdList.replace("[","").replace("]", "").replace("\"","");
|
||||
accountMoneyList = accountMoneyList.replace("[","").replace("]", "").replace("\"","");
|
||||
String[] aList = accountIdList.split(",");
|
||||
String[] amList = accountMoneyList.split(",");
|
||||
for(int i=0; i<aList.length; i++){
|
||||
if(aList[i].toString().equals(id.toString())){
|
||||
accountSum = accountSum + Integer.parseInt(amList[i].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (DataAccessException e){
|
||||
Log.errorFileSync(">>>>>>>>>查找信息异常", e);
|
||||
}
|
||||
return accountSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找结算账户信息-下拉框
|
||||
* @return
|
||||
@@ -496,6 +528,8 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
item.put("supplierName", arr[2]); //单位信息
|
||||
item.put("changeAmount", arr[3]); //金额
|
||||
item.put("operTime", arr[4]); //入库出库日期
|
||||
item.put("aList", arr[5]); //多账户的id列表
|
||||
item.put("amList", arr[6]); //多账户的金额列表
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
@@ -561,6 +595,24 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> getCondition_getManyAccountSum(Long id,String monthTime)
|
||||
{
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
*/
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put("AccountIdList_s_like", "\"" + id.toString() + "\"");
|
||||
if(!monthTime.equals("")){
|
||||
condition.put("OperTime_s_gteq", monthTime + "-01 00:00:00");
|
||||
condition.put("OperTime_s_lteq", monthTime + "-31 00:00:00");
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
|
||||
@@ -22,39 +22,51 @@ public class AccountDAO extends BaseDAO<Account> implements AccountIDAO
|
||||
@SuppressWarnings("unchecked")
|
||||
public void findAccountInOutList(PageUtil<Account> pageUtil, Long accountId) throws JshException {
|
||||
StringBuffer queryString = new StringBuffer();
|
||||
queryString.append("select dh.Number,concat(dh.SubType,dh.Type) as newType,s.supplier,dh.ChangeAmount,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime " +
|
||||
//主表出入库涉及的账户
|
||||
queryString.append("select dh.Number,concat(dh.SubType,dh.Type) as newType,s.supplier,dh.ChangeAmount,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
|
||||
" from jsh_depothead dh inner join jsh_supplier s on dh.OrganId = s.id where 1=1 ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and dh.AccountId='"+ accountId +"' ");
|
||||
}
|
||||
//主表收入和支出涉及的账户
|
||||
queryString.append("UNION ALL " +
|
||||
"select ah.BillNo,ah.Type as newType,s.supplier,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime " +
|
||||
"select ah.BillNo,ah.Type as newType,s.supplier,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
|
||||
" from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id where 1=1 ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and ah.AccountId='"+ accountId +"' ");
|
||||
}
|
||||
//明细中涉及的账户(收款,付款,收预付款)
|
||||
queryString.append("UNION ALL " +
|
||||
"select ah.BillNo,ah.Type as newType,s.supplier,ai.EachAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime " +
|
||||
"select ah.BillNo,ah.Type as newType,s.supplier,ai.EachAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
|
||||
" from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id " +
|
||||
" inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
|
||||
" where ah.Type in ('收款','付款','收预付款') ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and ai.AccountId='"+ accountId +"' ");
|
||||
}
|
||||
//主表中转出的账户
|
||||
queryString.append("UNION ALL " +
|
||||
"select ah.BillNo,ah.Type as newType, '' as sName,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime " +
|
||||
"select ah.BillNo,ah.Type as newType, '' as sName,ah.ChangeAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
|
||||
" from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
|
||||
" where ah.Type='转账' ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and ah.AccountId='"+ accountId +"' ");
|
||||
}
|
||||
//明细中被转入的账户
|
||||
queryString.append("UNION ALL " +
|
||||
"select ah.BillNo,ah.Type as newType, '' as sName,ai.EachAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime " +
|
||||
"select ah.BillNo,ah.Type as newType, '' as sName,ai.EachAmount,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime,'' as AList,'' as AMList " +
|
||||
" from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
|
||||
" where ah.Type='转账' ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and ai.AccountId='"+ accountId +"' ");
|
||||
}
|
||||
//多账户的情况
|
||||
queryString.append("UNION ALL " +
|
||||
"select dh.Number,concat(dh.SubType,dh.Type) as newType,s.supplier,dh.ChangeAmount,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime,dh.AccountIdList,dh.AccountMoneyList" +
|
||||
" from jsh_depothead dh inner join jsh_supplier s on dh.OrganId = s.id where 1=1 ");
|
||||
if(accountId!=null && !accountId.equals("")) {
|
||||
queryString.append(" and dh.AccountIdList like '%\""+ accountId +"\"%' ");
|
||||
}
|
||||
queryString.append(" ORDER BY oTime desc");
|
||||
Query query;
|
||||
query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
|
||||
|
||||
Reference in New Issue
Block a user