优化账户流水(涉及多账户)

This commit is contained in:
季圣华
2017-11-05 23:37:32 +08:00
parent 6d7aa039af
commit 790fae847e
4 changed files with 111 additions and 13 deletions

View File

@@ -305,13 +305,13 @@ public class AccountAction extends BaseAction<AccountModel>
item.put("serialNo", account.getSerialNo()); item.put("serialNo", account.getSerialNo());
item.put("initialAmount", account.getInitialAmount()); item.put("initialAmount", account.getInitialAmount());
String monthTime = Tools.getCurrentMonth(); 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"; String thisMonthAmountFmt = "0";
if(thisMonthAmount!=0){ if(thisMonthAmount!=0){
thisMonthAmountFmt = df.format(thisMonthAmount); thisMonthAmountFmt = df.format(thisMonthAmount);
} }
item.put("thisMonthAmount", thisMonthAmountFmt); //本月发生额 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); String currentAmountFmt=df.format(currentAmount);
item.put("currentAmount", currentAmountFmt); //当前余额 item.put("currentAmount", currentAmountFmt); //当前余额
item.put("remark", account.getRemark()); item.put("remark", account.getRemark());
@@ -405,8 +405,6 @@ public class AccountAction extends BaseAction<AccountModel>
} }
ids = ids.substring(0,ids.length() -1); ids = ids.substring(0,ids.length() -1);
System.out.println(">>>>>>>>>>>>>>>>>" + ids);
PageUtil<AccountItem> pageUtilOne = new PageUtil<AccountItem>(); PageUtil<AccountItem> pageUtilOne = new PageUtil<AccountItem>();
pageUtilOne.setPageSize(0); pageUtilOne.setPageSize(0);
pageUtilOne.setCurPage(0); pageUtilOne.setCurPage(0);
@@ -418,8 +416,6 @@ public class AccountAction extends BaseAction<AccountModel>
accountSum = accountSum + accountItem.getEachAmount(); accountSum = accountSum + accountItem.getEachAmount();
} }
} }
System.out.println(">>>>>>>>>>>>>>>>>accountSum" + accountSum);
} }
} }
catch (DataAccessException e){ catch (DataAccessException e){
@@ -431,6 +427,42 @@ public class AccountAction extends BaseAction<AccountModel>
return accountSum; 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 * @return
@@ -496,6 +528,8 @@ public class AccountAction extends BaseAction<AccountModel>
item.put("supplierName", arr[2]); //单位信息 item.put("supplierName", arr[2]); //单位信息
item.put("changeAmount", arr[3]); //金额 item.put("changeAmount", arr[3]); //金额
item.put("operTime", arr[4]); //入库出库日期 item.put("operTime", arr[4]); //入库出库日期
item.put("aList", arr[5]); //多账户的id列表
item.put("amList", arr[6]); //多账户的金额列表
dataArray.add(item); dataArray.add(item);
} }
} }
@@ -561,6 +595,24 @@ public class AccountAction extends BaseAction<AccountModel>
return condition; 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 * @return

View File

@@ -22,39 +22,51 @@ public class AccountDAO extends BaseDAO<Account> implements AccountIDAO
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void findAccountInOutList(PageUtil<Account> pageUtil, Long accountId) throws JshException { public void findAccountInOutList(PageUtil<Account> pageUtil, Long accountId) throws JshException {
StringBuffer queryString = new StringBuffer(); 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 "); " from jsh_depothead dh inner join jsh_supplier s on dh.OrganId = s.id where 1=1 ");
if(accountId!=null && !accountId.equals("")) { if(accountId!=null && !accountId.equals("")) {
queryString.append(" and dh.AccountId='"+ accountId +"' "); queryString.append(" and dh.AccountId='"+ accountId +"' ");
} }
//主表收入和支出涉及的账户
queryString.append("UNION ALL " + 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 "); " from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id where 1=1 ");
if(accountId!=null && !accountId.equals("")) { if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='"+ accountId +"' "); queryString.append(" and ah.AccountId='"+ accountId +"' ");
} }
//明细中涉及的账户(收款,付款,收预付款)
queryString.append("UNION ALL " + 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 " + " from jsh_accounthead ah inner join jsh_supplier s on ah.OrganId=s.id " +
" inner join jsh_accountitem ai on ai.HeaderId=ah.Id " + " inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type in ('收款','付款','收预付款') "); " where ah.Type in ('收款','付款','收预付款') ");
if(accountId!=null && !accountId.equals("")) { if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='"+ accountId +"' "); queryString.append(" and ai.AccountId='"+ accountId +"' ");
} }
//主表中转出的账户
queryString.append("UNION ALL " + 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 " + " from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type='转账' "); " where ah.Type='转账' ");
if(accountId!=null && !accountId.equals("")) { if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ah.AccountId='"+ accountId +"' "); queryString.append(" and ah.AccountId='"+ accountId +"' ");
} }
//明细中被转入的账户
queryString.append("UNION ALL " + 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 " + " from jsh_accounthead ah inner join jsh_accountitem ai on ai.HeaderId=ah.Id " +
" where ah.Type='转账' "); " where ah.Type='转账' ");
if(accountId!=null && !accountId.equals("")) { if(accountId!=null && !accountId.equals("")) {
queryString.append(" and ai.AccountId='"+ accountId +"' "); 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"); queryString.append(" ORDER BY oTime desc");
Query query; Query query;
query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch())); query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery(queryString + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));

View File

@@ -504,7 +504,24 @@
{ title: '单据编号',field: 'number',width:150}, { title: '单据编号',field: 'number',width:150},
{ title: '类型', field: 'type',width:100}, { title: '类型', field: 'type',width:100},
{ title: '单位信息', field: 'supplierName',width:150}, { title: '单位信息', field: 'supplierName',width:150},
{ title: '金额', field: 'changeAmount',width:80}, { title: '金额', field: 'changeAmount',width:80,
formatter: function (value, row) {
if(row.aList && row.amList) {
var aListArr = row.aList.toString().split(",");
var amListArr = row.amList.toString().split(",");
var res = "";
for(var i=0; i<aListArr.length; i++) {
if(aListArr[i] == accountId) {
res = amListArr[i];
}
}
return res + "[多账户]";
}
else {
return row.changeAmount;
}
}
},
{ title: '入库出库日期',field: 'operTime',width:180} { title: '入库出库日期',field: 'operTime',width:180}
]], ]],
onLoadError:function() { onLoadError:function() {

View File

@@ -229,7 +229,24 @@
{ title: '单据编号',field: 'number',width:150}, { title: '单据编号',field: 'number',width:150},
{ title: '类型', field: 'type',width:100}, { title: '类型', field: 'type',width:100},
{ title: '单位信息', field: 'supplierName',width:150}, { title: '单位信息', field: 'supplierName',width:150},
{ title: '金额', field: 'changeAmount',width:80}, { title: '金额', field: 'changeAmount',width:80,
formatter: function (value, row) {
if(row.aList && row.amList) {
var aListArr = row.aList.toString().split(",");
var amListArr = row.amList.toString().split(",");
var res = "";
for(var i=0; i<aListArr.length; i++) {
if(aListArr[i] == accountId) {
res = amListArr[i];
}
}
return res + "[多账户]";
}
else {
return row.changeAmount;
}
}
},
{ title: '入库出库日期',field: 'operTime',width:180} { title: '入库出库日期',field: 'operTime',width:180}
]], ]],
onLoadError:function() { onLoadError:function() {