cloudroam
2025-03-10 c306cba52bcc3e2c423f77d4a52c35ad04c52038
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
package com.jsh.erp.service.account;
 
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.*;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.datasource.vo.AccountVo4List;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.exception.JshException;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.systemConfig.SystemConfigService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
 
@Service
public class AccountService {
    private Logger logger = LoggerFactory.getLogger(AccountService.class);
 
    @Resource
    private AccountMapper accountMapper;
 
    @Resource
    private AccountMapperEx accountMapperEx;
 
    @Resource
    private DepotHeadMapper depotHeadMapper;
    @Resource
    private DepotHeadMapperEx depotHeadMapperEx;
 
    @Resource
    private AccountHeadMapper accountHeadMapper;
    @Resource
    private AccountHeadMapperEx accountHeadMapperEx;
 
    @Resource
    private AccountItemMapper accountItemMapper;
    @Resource
    private AccountItemMapperEx accountItemMapperEx;
    @Resource
    private LogService logService;
    @Resource
    private UserService userService;
    @Resource
    private SystemConfigService systemConfigService;
 
    public Account getAccount(long id) throws Exception{
        return accountMapper.selectByPrimaryKey(id);
    }
 
    public List<Account> getAccountListByIds(String ids)throws Exception {
        List<Long> idList = StringUtil.strToLongList(ids);
        List<Account> list = new ArrayList<>();
        try{
            AccountExample example = new AccountExample();
            example.createCriteria().andIdIn(idList);
            list = accountMapper.selectByExample(example);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list;
    }
 
    public List<Account> getAccount() throws Exception{
        List<Account> list=null;
        try{
            AccountExample example = new AccountExample();
            example.createCriteria().andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
            example.setOrderByClause("sort asc, id desc");
            list=accountMapper.selectByExample(example);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list;
    }
 
    public List<Account> getAccountByParam(String name, String serialNo) throws Exception{
        List<Account> list=null;
        try{
            list=accountMapperEx.getAccountByParam(name, serialNo);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list;
    }
 
    public List<AccountVo4List> select(String name, String serialNo, String remark, int offset, int rows) throws Exception{
        List<AccountVo4List> resList = new ArrayList<>();
        try{
            List<AccountVo4List> list = accountMapperEx.selectByConditionAccount(name, serialNo, remark, offset, rows);
            String timeStr = Tools.getCurrentMonth();
            String bTime = Tools.firstDayOfMonth(timeStr) + BusinessConstants.DAY_FIRST_TIME;
            String eTime = Tools.lastDayOfMonth(timeStr) + BusinessConstants.DAY_LAST_TIME;
            Boolean forceFlag = systemConfigService.getForceApprovalFlag();
            Map<Long, BigDecimal> thisMonthAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByDetailMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByDetailMap = new HashMap<>();
            List<AccountVo4Sum> thisMonthAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, bTime, eTime, forceFlag, offset, rows);
            List<AccountVo4Sum> currentAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, null, null, forceFlag, offset, rows);
            List<DepotHead> thisMonthManyAmountList = accountMapperEx.getManyAccountSumByParam(bTime, eTime, forceFlag);
            List<DepotHead> currentManyAmountList = accountMapperEx.getManyAccountSumByParam(null, null, forceFlag);
            for (AccountVo4Sum thisMonthAmount: thisMonthAmountList) {
                thisMonthAccountSumMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSum());
                thisMonthAccountSumByHeadMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByHead());
                thisMonthAccountSumByDetailMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByDetail());
            }
            for (AccountVo4Sum currentAmount: currentAmountList) {
                currentAccountSumMap.put(currentAmount.getId(), currentAmount.getAccountSum());
                currentAccountSumByHeadMap.put(currentAmount.getId(), currentAmount.getAccountSumByHead());
                currentAccountSumByDetailMap.put(currentAmount.getId(), currentAmount.getAccountSumByDetail());
            }
            if (null != list) {
                for (AccountVo4List al : list) {
                    DecimalFormat df = new DecimalFormat(".##");
                    BigDecimal thisMonthAmount = thisMonthAccountSumMap.get(al.getId())
                            .add(thisMonthAccountSumByHeadMap.get(al.getId()))
                            .add(thisMonthAccountSumByDetailMap.get(al.getId()))
                            .add(getManyAccountSumParse(al.getId(), thisMonthManyAmountList));
                    String thisMonthAmountFmt = "0";
                    if ((thisMonthAmount.compareTo(BigDecimal.ZERO))!=0) {
                        thisMonthAmountFmt = df.format(thisMonthAmount);
                    }
                    al.setThisMonthAmount(thisMonthAmountFmt);  //本月发生额
                    BigDecimal currentAmount = currentAccountSumMap.get(al.getId())
                            .add(currentAccountSumByHeadMap.get(al.getId()))
                            .add(currentAccountSumByDetailMap.get(al.getId()))
                            .add(getManyAccountSumParse(al.getId(), currentManyAmountList))
                            .add(al.getInitialAmount()) ;
                    al.setCurrentAmount(currentAmount);
                    resList.add(al);
                }
            }
        } catch(Exception e){
            JshException.readFail(logger, e);
        }
        return resList;
    }
 
    public Long countAccount(String name, String serialNo, String remark)throws Exception {
        Long result = null;
        try{
            result = accountMapperEx.countsByAccount(name, serialNo, remark);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return result;
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int insertAccount(JSONObject obj, HttpServletRequest request)throws Exception {
        Account account = JSONObject.parseObject(obj.toJSONString(), Account.class);
        if(account.getInitialAmount() == null) {
            account.setInitialAmount(BigDecimal.ZERO);
        }
        List<Account> accountList = getAccountByParam(null, null);
        if(accountList.size() == 0) {
            account.setIsDefault(true);
        } else {
            account.setIsDefault(false);
        }
        account.setEnabled(true);
        int result=0;
        try{
            result = accountMapper.insertSelective(account);
            logService.insertLog("账户",
                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(account.getName()).toString(), request);
        }catch(Exception e){
            JshException.writeFail(logger, e);
        }
        return result;
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int updateAccount(JSONObject obj, HttpServletRequest request)throws Exception {
        Account account = JSONObject.parseObject(obj.toJSONString(), Account.class);
        int result=0;
        try{
            result = accountMapper.updateByPrimaryKeySelective(account);
            logService.insertLog("账户",
                    new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(account.getName()).toString(), request);
        }catch(Exception e){
            JshException.writeFail(logger, e);
        }
        return result;
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int deleteAccount(Long id, HttpServletRequest request) throws Exception{
        return batchDeleteAccountByIds(id.toString());
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int batchDeleteAccount(String ids, HttpServletRequest request)throws Exception {
        return batchDeleteAccountByIds(ids);
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int batchDeleteAccountByIds(String ids) throws Exception{
        int result=0;
        String [] idArray=ids.split(",");
        //校验财务主表    jsh_accounthead
        List<AccountHead> accountHeadList=null;
        try{
            accountHeadList = accountHeadMapperEx.getAccountHeadListByAccountIds(idArray);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        if(accountHeadList!=null&&accountHeadList.size()>0){
            logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
        }
        //校验财务子表    jsh_accountitem
        List<AccountItem> accountItemList=null;
        try{
            accountItemList = accountItemMapperEx.getAccountItemListByAccountIds(idArray);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        if(accountItemList!=null&&accountItemList.size()>0){
            logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
        }
        //校验单据主表    jsh_depot_head
        List<DepotHead> depotHeadList =null;
        try{
            depotHeadList = depotHeadMapperEx.getDepotHeadListByAccountIds(idArray);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        if(depotHeadList!=null&&depotHeadList.size()>0){
            logger.error("异常码[{}],异常提示[{}],参数,AccountIds[{}]",
                    ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,ExceptionConstants.DELETE_FORCE_CONFIRM_MSG,ids);
            throw new BusinessRunTimeException(ExceptionConstants.DELETE_FORCE_CONFIRM_CODE,
                    ExceptionConstants.DELETE_FORCE_CONFIRM_MSG);
        }
        //记录日志
        StringBuffer sb = new StringBuffer();
        sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE);
        List<Account> list = getAccountListByIds(ids);
        for(Account account: list){
            sb.append("[").append(account.getName()).append("]");
        }
        logService.insertLog("账户", sb.toString(),
                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
        User userInfo=userService.getCurrentUser();
        //校验通过执行删除操作
        try{
            result = accountMapperEx.batchDeleteAccountByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
        }catch(Exception e){
            JshException.writeFail(logger, e);
        }
        return result;
    }
 
    public int checkIsNameExist(Long id, String name)throws Exception {
        AccountExample example = new AccountExample();
        example.createCriteria().andIdNotEqualTo(id).andNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        List<Account> list=null;
        try{
            list = accountMapper.selectByExample(example);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list==null?0:list.size();
    }
 
    public List<Account> findBySelect()throws Exception {
        AccountExample example = new AccountExample();
        example.createCriteria().andEnabledEqualTo(true).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
        example.setOrderByClause("sort asc, id desc");
        List<Account> list=null;
        try{
            list = accountMapper.selectByExample(example);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list;
    }
 
    /**
     * 单个账户的金额求和-入库和出库
     * @return
     */
    public BigDecimal getAccountSum(Long accountId, String beginTime, String endTime, Boolean forceFlag) {
        return accountMapperEx.getAccountSum(accountId, beginTime, endTime, forceFlag);
    }
 
    /**
     * 单个账户的金额求和-收入、支出、转账的单据表头的合计
     * @return
     */
    public BigDecimal getAccountSumByHead(Long accountId, String beginTime, String endTime, Boolean forceFlag) {
        return accountMapperEx.getAccountSumByHead(accountId, beginTime, endTime, forceFlag);
    }
 
    /**
     * 单个账户的金额求和-收款、付款、转账、收预付款的单据明细的合计
     * @return
     */
    public BigDecimal getAccountSumByDetail(Long accountId, String beginTime, String endTime, Boolean forceFlag) {
        return accountMapperEx.getAccountSumByDetail(accountId, beginTime, endTime, forceFlag);
    }
 
    /**
     * 单个账户的金额求和-多账户的明细合计
     * @return
     */
    public BigDecimal getManyAccountSum(Long accountId, String beginTime, String endTime, Boolean forceFlag) {
        BigDecimal accountSum = BigDecimal.ZERO;
        List<DepotHead> dataList = accountMapperEx.getManyAccountSum(accountId, beginTime, endTime, forceFlag);
        if (dataList != null) {
            for (DepotHead depotHead : dataList) {
                if(depotHead != null) {
                    String accountIdList = depotHead.getAccountIdList();
                    String accountMoneyList = depotHead.getAccountMoneyList();
                    if(StringUtil.isNotEmpty(accountIdList) && StringUtil.isNotEmpty(accountMoneyList)) {
                        String[] aList = accountIdList.split(",");
                        String[] amList = accountMoneyList.split(",");
                        for (int i = 0; i < aList.length; i++) {
                            if (aList[i].equals(accountId.toString())) {
                                if(amList.length>0) {
                                    accountSum = accountSum.add(new BigDecimal(amList[i]));
                                }
                            }
                        }
                    }
                }
            }
        }
        return accountSum;
    }
 
    /**
     * 单个账户的金额求和-多账户的明细合计(格式化)
     * @return
     */
    public BigDecimal getManyAccountSumParse(Long accountId, List<DepotHead> manyAmountList) {
        BigDecimal accountSum = BigDecimal.ZERO;
        if (manyAmountList != null) {
            for (DepotHead depotHead : manyAmountList) {
                String accountIdList = depotHead.getAccountIdList();
                String accountMoneyList = depotHead.getAccountMoneyList();
                if(StringUtil.isNotEmpty(accountIdList) && StringUtil.isNotEmpty(accountMoneyList)) {
                    String[] aList = accountIdList.split(",");
                    String[] amList = accountMoneyList.split(",");
                    for (int i = 0; i < aList.length; i++) {
                        if (aList[i].equals(accountId.toString())) {
                            if(amList.length>0) {
                                accountSum = accountSum.add(new BigDecimal(amList[i]));
                            }
                        }
                    }
                }
            }
        }
        return accountSum;
    }
 
    public List<AccountVo4InOutList> findAccountInOutList(Long accountId, String number, String beginTime, String endTime,
                                                          Boolean forceFlag, Integer offset, Integer rows) throws Exception{
        List<AccountVo4InOutList> list=null;
        try{
            list = accountMapperEx.findAccountInOutList(accountId, number, beginTime, endTime, forceFlag, offset, rows);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return list;
    }
 
    public int findAccountInOutListCount(Long accountId, String number, String beginTime, String endTime, Boolean forceFlag) throws Exception{
        int result=0;
        try{
            result = accountMapperEx.findAccountInOutListCount(accountId, number, beginTime, endTime, forceFlag);
        }catch(Exception e){
            JshException.readFail(logger, e);
        }
        return result;
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int updateIsDefault(Long accountId) throws Exception{
        int result=0;
        try{
            //全部取消默认
            Account allAccount = new Account();
            allAccount.setIsDefault(false);
            AccountExample allExample = new AccountExample();
            allExample.createCriteria();
            accountMapper.updateByExampleSelective(allAccount, allExample);
            //给指定账户设为默认
            Account account = new Account();
            account.setIsDefault(true);
            AccountExample example = new AccountExample();
            example.createCriteria().andIdEqualTo(accountId);
            accountMapper.updateByExampleSelective(account, example);
            logService.insertLog("账户",BusinessConstants.LOG_OPERATION_TYPE_EDIT+accountId,
                    ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
            result = 1;
        }catch(Exception e){
            JshException.writeFail(logger, e);
        }
        return result;
    }
 
    public Map<Long,String> getAccountMap() throws Exception {
        List<Account> accountList = getAccount();
        Map<Long,String> accountMap = new HashMap<>();
        for(Account account : accountList){
            accountMap.put(account.getId(), account.getName());
        }
        return accountMap;
    }
 
    public String getAccountStrByIdAndMoney(Map<Long,String> accountMap, String accountIdList, String accountMoneyList){
        StringBuffer sb = new StringBuffer();
        List<Long> idList = StringUtil.strToLongList(accountIdList);
        List<BigDecimal> moneyList = StringUtil.strToBigDecimalList(accountMoneyList);
        for (int i = 0; i < idList.size(); i++) {
            Long id = idList.get(i);
            BigDecimal money =  moneyList.get(i).abs();
            sb.append(accountMap.get(id) + "(" + money + "元) ");
        }
        return sb.toString();
    }
 
    public List<AccountVo4List> listWithBalance(String name, String serialNo, Integer offset, Integer rows) throws Exception {
        List<AccountVo4List> resList = new ArrayList<>();
        try{
            List<AccountVo4List> list = accountMapperEx.selectByConditionAccount(name, serialNo, null, offset, rows);
            String timeStr = Tools.getCurrentMonth();
            String bTime = Tools.firstDayOfMonth(timeStr) + BusinessConstants.DAY_FIRST_TIME;
            String eTime = Tools.lastDayOfMonth(timeStr) + BusinessConstants.DAY_LAST_TIME;
            Boolean forceFlag = systemConfigService.getForceApprovalFlag();
            Map<Long, BigDecimal> thisMonthAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByDetailMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByDetailMap = new HashMap<>();
            List<AccountVo4Sum> thisMonthAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, bTime, eTime, forceFlag, offset, rows);
            List<AccountVo4Sum> currentAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, null, null, forceFlag, offset, rows);
            List<DepotHead> thisMonthManyAmountList = accountMapperEx.getManyAccountSumByParam(bTime, eTime, forceFlag);
            List<DepotHead> currentManyAmountList = accountMapperEx.getManyAccountSumByParam(null, null, forceFlag);
            for (AccountVo4Sum thisMonthAmount: thisMonthAmountList) {
                thisMonthAccountSumMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSum());
                thisMonthAccountSumByHeadMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByHead());
                thisMonthAccountSumByDetailMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByDetail());
            }
            for (AccountVo4Sum currentAmount: currentAmountList) {
                currentAccountSumMap.put(currentAmount.getId(), currentAmount.getAccountSum());
                currentAccountSumByHeadMap.put(currentAmount.getId(), currentAmount.getAccountSumByHead());
                currentAccountSumByDetailMap.put(currentAmount.getId(), currentAmount.getAccountSumByDetail());
            }
            if (null != list) {
                for (AccountVo4List al : list) {
                    DecimalFormat df = new DecimalFormat(".##");
                    BigDecimal thisMonthAmount = thisMonthAccountSumMap.get(al.getId())
                            .add(thisMonthAccountSumByHeadMap.get(al.getId()))
                            .add(thisMonthAccountSumByDetailMap.get(al.getId()))
                            .add(getManyAccountSumParse(al.getId(), thisMonthManyAmountList));
                    String thisMonthAmountFmt = "0";
                    if ((thisMonthAmount.compareTo(BigDecimal.ZERO))!=0) {
                        thisMonthAmountFmt = df.format(thisMonthAmount);
                    }
                    al.setThisMonthAmount(thisMonthAmountFmt);  //本月发生额
                    BigDecimal currentAmount = currentAccountSumMap.get(al.getId())
                            .add(currentAccountSumByHeadMap.get(al.getId()))
                            .add(currentAccountSumByDetailMap.get(al.getId()))
                            .add(getManyAccountSumParse(al.getId(), currentManyAmountList))
                            .add(al.getInitialAmount());
                    al.setCurrentAmount(currentAmount);
                    resList.add(al);
                }
            }
        } catch(Exception e){
            JshException.readFail(logger, e);
        }
        return resList;
    }
 
    public Long listWithBalanceCount(String name, String serialNo) {
        Long result = null;
        try{
            result = accountMapperEx.countsByAccount(name, serialNo, null);
        } catch(Exception e){
            JshException.readFail(logger, e);
        }
        return result;
    }
 
    public Map<String, Object> getStatistics(String name, String serialNo) {
        Map<String, Object> map = new HashMap<>();
        try {
            List<Account> list = getAccountByParam(name, serialNo);
            String timeStr = Tools.getCurrentMonth();
            String bTime = Tools.firstDayOfMonth(timeStr) + BusinessConstants.DAY_FIRST_TIME;
            String eTime = Tools.lastDayOfMonth(timeStr) + BusinessConstants.DAY_LAST_TIME;
            BigDecimal allMonthAmount = BigDecimal.ZERO;
            BigDecimal allCurrentAmount = BigDecimal.ZERO;
            Boolean forceFlag = systemConfigService.getForceApprovalFlag();
            Map<Long, BigDecimal> thisMonthAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> thisMonthAccountSumByDetailMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByHeadMap = new HashMap<>();
            Map<Long, BigDecimal> currentAccountSumByDetailMap = new HashMap<>();
            List<AccountVo4Sum> thisMonthAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, bTime, eTime, forceFlag, null, null);
            List<AccountVo4Sum> currentAmountList = accountMapperEx.getAccountSumByParam(name, serialNo, null, null, forceFlag, null, null);
            List<DepotHead> thisMonthManyAmountList = accountMapperEx.getManyAccountSumByParam(bTime, eTime, forceFlag);
            List<DepotHead> currentManyAmountList = accountMapperEx.getManyAccountSumByParam(null, null, forceFlag);
            for (AccountVo4Sum thisMonthAmount: thisMonthAmountList) {
                thisMonthAccountSumMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSum());
                thisMonthAccountSumByHeadMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByHead());
                thisMonthAccountSumByDetailMap.put(thisMonthAmount.getId(), thisMonthAmount.getAccountSumByDetail());
            }
            for (AccountVo4Sum currentAmount: currentAmountList) {
                currentAccountSumMap.put(currentAmount.getId(), currentAmount.getAccountSum());
                currentAccountSumByHeadMap.put(currentAmount.getId(), currentAmount.getAccountSumByHead());
                currentAccountSumByDetailMap.put(currentAmount.getId(), currentAmount.getAccountSumByDetail());
            }
            if (null != list) {
                for (Account a : list) {
                    BigDecimal monthAmount = thisMonthAccountSumMap.get(a.getId())
                            .add(thisMonthAccountSumByHeadMap.get(a.getId()))
                            .add(thisMonthAccountSumByDetailMap.get(a.getId()))
                            .add(getManyAccountSumParse(a.getId(), thisMonthManyAmountList));
                    BigDecimal currentAmount = currentAccountSumMap.get(a.getId())
                            .add(currentAccountSumByHeadMap.get(a.getId()))
                            .add(currentAccountSumByDetailMap.get(a.getId()))
                            .add(getManyAccountSumParse(a.getId(), currentManyAmountList))
                            .add(a.getInitialAmount());
                    allMonthAmount = allMonthAmount.add(monthAmount);
                    allCurrentAmount = allCurrentAmount.add(currentAmount);
                }
            }
            map.put("allMonthAmount", priceFormat(allMonthAmount));  //本月发生额
            map.put("allCurrentAmount", priceFormat(allCurrentAmount));  //当前总金额
        } catch (Exception e) {
            JshException.readFail(logger, e);
        }
        return map;
    }
 
    /**
     * 价格格式化
     * @param price
     * @return
     */
    private String priceFormat(BigDecimal price) {
        String priceFmt = "0";
        DecimalFormat df = new DecimalFormat(".##");
        if ((price.compareTo(BigDecimal.ZERO))!=0) {
            priceFmt = df.format(price);
        }
        return priceFmt;
    }
 
    @Transactional(value = "transactionManager", rollbackFor = Exception.class)
    public int batchSetStatus(Boolean status, String ids)throws Exception {
        logService.insertLog("账户",
                new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ENABLED).toString(),
                ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
        List<Long> accountIds = StringUtil.strToLongList(ids);
        Account account = new Account();
        account.setEnabled(status);
        AccountExample example = new AccountExample();
        example.createCriteria().andIdIn(accountIds);
        int result=0;
        try{
            result = accountMapper.updateByExampleSelective(account, example);
        }catch(Exception e){
            JshException.writeFail(logger, e);
        }
        return result;
    }
}