AccountItemController.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.jsh.erp.controller;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.jsh.erp.constants.BusinessConstants;
  5. import com.jsh.erp.datasource.vo.AccountItemVo4List;
  6. import com.jsh.erp.service.AccountHeadService;
  7. import com.jsh.erp.service.AccountItemService;
  8. import com.jsh.erp.utils.BaseResponseInfo;
  9. import com.jsh.erp.utils.StringUtil;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import javax.annotation.Resource;
  19. import javax.servlet.http.HttpServletRequest;
  20. import java.math.BigDecimal;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * @author ji sheng hua 752*718*920
  25. */
  26. @RestController
  27. @RequestMapping(value = "/accountItem")
  28. @Api(tags = {"财务明细"})
  29. public class AccountItemController {
  30. private Logger logger = LoggerFactory.getLogger(AccountItemController.class);
  31. @Resource
  32. private AccountItemService accountItemService;
  33. @Resource
  34. private AccountHeadService accountHeadService;
  35. @GetMapping(value = "/getDetailList")
  36. @ApiOperation(value = "明细列表")
  37. public BaseResponseInfo getDetailList(@RequestParam("headerId") Long headerId,
  38. HttpServletRequest request)throws Exception {
  39. BaseResponseInfo res = new BaseResponseInfo();
  40. try {
  41. String type = null;
  42. List<AccountItemVo4List> dataList = new ArrayList<>();
  43. if(headerId != 0) {
  44. dataList = accountItemService.getDetailList(headerId);
  45. type = accountHeadService.getAccountHead(headerId).getType();
  46. }
  47. JSONObject outer = new JSONObject();
  48. outer.put("total", dataList.size());
  49. //存放数据json数组
  50. JSONArray dataArray = new JSONArray();
  51. if (null != dataList) {
  52. for (AccountItemVo4List ai : dataList) {
  53. JSONObject item = new JSONObject();
  54. item.put("accountId", ai.getAccountId());
  55. item.put("accountName", ai.getAccountName());
  56. item.put("inOutItemId", ai.getInOutItemId());
  57. item.put("inOutItemName", ai.getInOutItemName());
  58. if(StringUtil.isNotEmpty(ai.getBillNumber())) {
  59. item.put("billNumber", ai.getBillNumber());
  60. } else {
  61. item.put("billNumber", "QiChu");
  62. }
  63. item.put("needDebt", ai.getNeedDebt());
  64. item.put("finishDebt", ai.getFinishDebt());
  65. BigDecimal eachAmount = ai.getEachAmount();
  66. if(BusinessConstants.TYPE_MONEY_IN.equals(type)) {
  67. item.put("eachAmount", eachAmount);
  68. } else if(BusinessConstants.TYPE_MONEY_OUT.equals(type)) {
  69. item.put("eachAmount", BigDecimal.ZERO.subtract(eachAmount));
  70. } else {
  71. item.put("eachAmount", (eachAmount.compareTo(BigDecimal.ZERO))==-1 ? BigDecimal.ZERO.subtract(eachAmount): eachAmount);
  72. }
  73. item.put("remark", ai.getRemark());
  74. dataArray.add(item);
  75. }
  76. }
  77. outer.put("rows", dataArray);
  78. res.code = 200;
  79. res.data = outer;
  80. } catch (Exception e) {
  81. logger.error(e.getMessage(), e);
  82. res.code = 500;
  83. res.data = "获取数据失败";
  84. }
  85. return res;
  86. }
  87. }