Commit 854e002211fd2a3e9bc4bb4244df0776c4a61033
1 parent
2b13fb7f
Exists in
master
资金日报,导出功能
Showing
7 changed files
with
201 additions
and
43 deletions
Show diff stats
backend/chkpower/src/main/java/com/hotent/chkpower/controller/WDailyFundsController.java
1 | 1 | package com.hotent.chkpower.controller; |
2 | 2 | |
3 | 3 | |
4 | +import cn.afterturn.easypoi.excel.ExcelExportUtil; | |
5 | +import cn.afterturn.easypoi.excel.entity.TemplateExportParams; | |
4 | 6 | import com.hotent.chkpower.dto.WDailyFundsInspDto; |
7 | +import com.hotent.chkpower.manager.WCurrentManager; | |
8 | +import jodd.util.ObjectUtil; | |
9 | +import org.apache.poi.ss.usermodel.Workbook; | |
5 | 10 | import org.springframework.web.bind.annotation.GetMapping; |
6 | 11 | import org.springframework.web.bind.annotation.PostMapping; |
7 | 12 | import org.springframework.web.bind.annotation.RequestBody; |
... | ... | @@ -16,54 +21,165 @@ import com.hotent.base.controller.BaseController; |
16 | 21 | import com.hotent.chkpower.model.WDailyFunds; |
17 | 22 | import com.hotent.chkpower.manager.WDailyFundsManager; |
18 | 23 | |
24 | +import javax.annotation.Resource; | |
25 | +import javax.servlet.http.HttpServletResponse; | |
26 | +import java.io.OutputStream; | |
27 | +import java.math.BigDecimal; | |
28 | +import java.math.RoundingMode; | |
29 | +import java.net.URLEncoder; | |
30 | +import java.util.*; | |
31 | +import java.util.stream.Collectors; | |
32 | + | |
19 | 33 | /** |
20 | 34 | * 每日资金 前端控制器 |
21 | 35 | * |
22 | - * @company 广州宏天软件股份有限公司 | |
23 | 36 | * @author cw |
37 | + * @company 广州宏天软件股份有限公司 | |
24 | 38 | * @since 2024-07-08 |
25 | 39 | */ |
26 | 40 | @RestController |
27 | 41 | @RequestMapping("/wDailyFunds/v1/") |
28 | 42 | public class WDailyFundsController extends BaseController<WDailyFundsManager, WDailyFunds> { |
29 | 43 | |
30 | - /** | |
31 | - * 根据id获取每日资金数据详情 | |
32 | - * @param id | |
33 | - * @return | |
34 | - * @throws Exception | |
35 | - * ModelAndView | |
36 | - */ | |
37 | - @GetMapping(value="/getDetail") | |
38 | - @ApiOperation(value="根据id获取每日资金数据详情",httpMethod = "GET",notes = "根据id获取每日资金数据详情") | |
39 | - public CommonResult<WDailyFunds> getDetail(@ApiParam(name="id",value="业务对象主键", required = true)@RequestParam(required=true) String id) throws Exception{ | |
40 | - return CommonResult.<WDailyFunds>ok().value(baseService.getDetail(id)); | |
41 | - } | |
44 | + @Resource | |
45 | + private WCurrentManager wCurrentManager; | |
46 | + | |
47 | + /** | |
48 | + * 根据id获取每日资金数据详情 | |
49 | + * | |
50 | + * @param id | |
51 | + * @return | |
52 | + * @throws Exception ModelAndView | |
53 | + */ | |
54 | + @GetMapping(value = "/getDetail") | |
55 | + @ApiOperation(value = "根据id获取每日资金数据详情", httpMethod = "GET", notes = "根据id获取每日资金数据详情") | |
56 | + public CommonResult<WDailyFunds> getDetail(@ApiParam(name = "id", value = "业务对象主键", required = true) @RequestParam(required = true) String id) throws Exception { | |
57 | + return CommonResult.<WDailyFunds>ok().value(baseService.getDetail(id)); | |
58 | + } | |
59 | + | |
42 | 60 | /** |
43 | - * 新增,更新每日资金 | |
44 | - * @param wDailyFunds | |
45 | - * @throws Exception | |
46 | - * @return | |
47 | - * @exception | |
48 | - */ | |
61 | + * 新增,更新每日资金 | |
62 | + * | |
63 | + * @param wDailyFunds | |
64 | + * @return | |
65 | + * @throws Exception | |
66 | + * @throws | |
67 | + */ | |
68 | + | |
69 | + | |
70 | + @PostMapping(value = "/save") | |
71 | + @ApiOperation(value = "新增,更新每日资金数据", httpMethod = "POST", notes = "新增,更新每日资金数据") | |
72 | + public CommonResult<String> save(@ApiParam(name = "WDailyFunds", value = "每日资金对象", required = true) @RequestBody WDailyFunds wDailyFunds) throws Exception { | |
73 | + String msg = StringUtil.isEmpty(wDailyFunds.getId()) ? "添加每日资金成功" : "更新每日资金成功"; | |
74 | + baseService.createOrUpdate(wDailyFunds); | |
75 | + return CommonResult.<String>ok().message(msg); | |
76 | + } | |
49 | 77 | |
78 | + @PostMapping(value = "/updateInsp") | |
79 | + public CommonResult<String> updateInsp(@RequestBody WDailyFundsInspDto wDailyFundsInspDto) throws Exception { | |
80 | + baseService.updateInsp(wDailyFundsInspDto); | |
81 | + return CommonResult.<String>ok().message("成功"); | |
82 | + } | |
50 | 83 | |
51 | 84 | |
85 | + private BigDecimal aggregateBalance(HashMap<String, String> data, String key, BigDecimal aggregate) { | |
86 | + // 直接检查值是否存在并为非空,避免了额外的containsKey调用 | |
87 | + Object value = data.get(key); | |
88 | + if (value != null && !value.equals("")) { | |
89 | + return aggregate.add(new BigDecimal(((Number) value).doubleValue())); | |
90 | + } else { | |
91 | + return BigDecimal.ZERO; | |
92 | + } | |
93 | + } | |
94 | + | |
95 | + /** | |
96 | + * 资金日报导出 | |
97 | + * | |
98 | + * @param response | |
99 | + * @param date | |
100 | + * @throws Exception | |
101 | + */ | |
102 | + @GetMapping("dailyFundsByDateExport") | |
103 | + public void DailyFundsByDateExport(HttpServletResponse response, String date) throws Exception { | |
104 | + HashMap map = new HashMap(); | |
105 | + map.put("date", date); | |
106 | + List<String> gslxList = wCurrentManager.getCurrentOrgTypeList(); | |
52 | 107 | |
53 | 108 | |
54 | - @PostMapping(value="/save") | |
55 | - @ApiOperation(value = "新增,更新每日资金数据", httpMethod = "POST", notes = "新增,更新每日资金数据") | |
56 | - public CommonResult<String> save(@ApiParam(name="WDailyFunds",value="每日资金对象", required = true)@RequestBody WDailyFunds wDailyFunds) throws Exception{ | |
57 | - String msg = StringUtil.isEmpty(wDailyFunds.getId()) ? "添加每日资金成功" : "更新每日资金成功"; | |
58 | - baseService.createOrUpdate(wDailyFunds); | |
59 | - return CommonResult.<String>ok().message(msg); | |
60 | - } | |
109 | + BigDecimal F_yesterday_account_balance_zs = BigDecimal.ZERO; | |
110 | + BigDecimal F_today_account_balance_zs = BigDecimal.ZERO; | |
111 | + BigDecimal F_account_balance_difference_zs = BigDecimal.ZERO; | |
112 | + BigDecimal F_today_net_cash_flow_zs = BigDecimal.ZERO; | |
113 | + BigDecimal F_today_freeze_amount_zs = BigDecimal.ZERO; | |
114 | + BigDecimal F_today_freezing_zs = BigDecimal.ZERO; | |
61 | 115 | |
62 | - @PostMapping(value="/updateInsp") | |
63 | - public CommonResult<String> updateInsp(@RequestBody WDailyFundsInspDto wDailyFundsInspDto) throws Exception{ | |
64 | - baseService.updateInsp(wDailyFundsInspDto); | |
65 | - return CommonResult.<String>ok().message("成功"); | |
66 | - } | |
116 | + List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); | |
117 | + for (String orgType : gslxList) { | |
118 | + List<HashMap<String, String>> listData = baseService.getDailyFundsByDateList(orgType, date); | |
119 | + if (listData == null || listData.size() == 0) { | |
120 | + break; | |
121 | + } | |
122 | + BigDecimal F_yesterday_account_balance = BigDecimal.ZERO; | |
123 | + BigDecimal F_today_account_balance = BigDecimal.ZERO; | |
124 | + BigDecimal F_account_balance_difference = BigDecimal.ZERO; | |
125 | + BigDecimal F_today_net_cash_flow = BigDecimal.ZERO; | |
126 | + BigDecimal F_today_freeze_amount = BigDecimal.ZERO; | |
127 | + BigDecimal F_today_freezing = BigDecimal.ZERO; | |
128 | + for (HashMap<String, String> data : listData) { | |
129 | + F_yesterday_account_balance = aggregateBalance(data, "F_yesterday_account_balance", F_yesterday_account_balance); | |
130 | + F_today_account_balance = aggregateBalance(data, "F_today_account_balance", F_today_account_balance); | |
131 | + F_account_balance_difference = aggregateBalance(data, "F_account_balance_difference", F_account_balance_difference); | |
132 | + F_today_net_cash_flow = aggregateBalance(data, "F_today_net_cash_flow", F_today_net_cash_flow); | |
133 | + F_today_freeze_amount = aggregateBalance(data, "F_today_freeze_amount", F_today_freeze_amount); | |
134 | + F_today_freezing = aggregateBalance(data, "F_today_freezing", F_today_freezing); | |
135 | + } | |
136 | + HashMap<String, String> xjMap = new HashMap<>(); | |
137 | + xjMap.put("F_org_type", "小计(" + orgType + ")"); | |
138 | + xjMap.put("F_yesterday_account_balance", F_yesterday_account_balance.setScale(2, RoundingMode.HALF_UP).toString()); | |
139 | + xjMap.put("F_today_account_balance", F_today_account_balance.setScale(2, RoundingMode.HALF_UP).toString()); | |
140 | + xjMap.put("F_account_balance_difference", F_account_balance_difference.setScale(2, RoundingMode.HALF_UP).toString()); | |
141 | + xjMap.put("F_today_net_cash_flow", F_today_net_cash_flow.setScale(2, RoundingMode.HALF_UP).toString()); | |
142 | + xjMap.put("F_today_freeze_amount", F_today_freeze_amount.setScale(2, RoundingMode.HALF_UP).toString()); | |
143 | + xjMap.put("F_today_freezing", F_today_freezing.setScale(2, RoundingMode.HALF_UP).toString()); | |
144 | + listData.add(xjMap); | |
145 | + list.addAll(listData); | |
146 | + F_yesterday_account_balance_zs = F_yesterday_account_balance_zs.add(F_yesterday_account_balance); | |
147 | + F_today_account_balance_zs= F_today_account_balance_zs.add(F_today_account_balance); | |
148 | + F_account_balance_difference_zs=F_account_balance_difference_zs.add(F_account_balance_difference); | |
149 | + F_today_net_cash_flow_zs=F_today_net_cash_flow_zs.add(F_today_net_cash_flow); | |
150 | + F_today_freeze_amount_zs=F_today_freeze_amount_zs.add(F_today_freeze_amount); | |
151 | + F_today_freezing_zs=F_today_freezing_zs.add(F_today_freezing); | |
152 | + } | |
153 | + HashMap<String, String> hzMap = new HashMap<>(); | |
154 | + hzMap.put("F_org_type", "汇总"); | |
155 | + hzMap.put("F_yesterday_account_balance", F_yesterday_account_balance_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
156 | + hzMap.put("F_today_account_balance", F_today_account_balance_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
157 | + hzMap.put("F_account_balance_difference", F_account_balance_difference_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
158 | + hzMap.put("F_today_net_cash_flow", F_today_net_cash_flow_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
159 | + hzMap.put("F_today_freeze_amount", F_today_freeze_amount_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
160 | + hzMap.put("F_today_freezing", F_today_freezing_zs.setScale(2, RoundingMode.HALF_UP).toString()); | |
161 | + list.add(hzMap); | |
162 | + map.put("list", list); | |
163 | + TemplateExportParams params = new TemplateExportParams("doc/dailyFundsByDateExport.xls"); | |
164 | + params.setColForEach(true); | |
165 | + Workbook workbook = ExcelExportUtil.exportExcel(params, map); | |
166 | + String filedisplay = "资金日报.xls"; | |
167 | + response.setContentType("APPLICATION/OCTET-STREAM"); | |
168 | + response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); | |
169 | + response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filedisplay, "utf-8")); | |
170 | + OutputStream os = null; | |
171 | + try { | |
172 | + os = response.getOutputStream(); | |
173 | + workbook.write(os); | |
174 | + os.flush(); | |
175 | + os.close(); | |
176 | + } catch (Exception e) { | |
177 | + e.printStackTrace(); | |
178 | + } finally { | |
179 | + if (os != null) | |
180 | + os.close(); | |
181 | + } | |
182 | + } | |
67 | 183 | |
68 | 184 | |
69 | 185 | } | ... | ... |
backend/chkpower/src/main/java/com/hotent/chkpower/dao/WDailyFundsDao.java
... | ... | @@ -27,4 +27,6 @@ public interface WDailyFundsDao extends BaseMapper<WDailyFunds> { |
27 | 27 | |
28 | 28 | List<WDailyFunds> selectWDailyFundsNews(@Param("wCurrentList") List<HashMap<String,String>> wCurrentList, @Param("fDate") LocalDateTime fDate); |
29 | 29 | |
30 | + List<HashMap<String, String>> getDailyFundsByDateList(@Param("fOrgType") String fOrgType, @Param("fDate") String fDate); | |
31 | + | |
30 | 32 | } | ... | ... |
backend/chkpower/src/main/java/com/hotent/chkpower/manager/WDailyFundsManager.java
backend/chkpower/src/main/java/com/hotent/chkpower/manager/impl/WDailyFundsManagerImpl.java
... | ... | @@ -17,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional; |
17 | 17 | |
18 | 18 | import javax.annotation.Resource; |
19 | 19 | import java.time.LocalDateTime; |
20 | +import java.util.Collections; | |
20 | 21 | import java.util.HashMap; |
21 | 22 | import java.util.List; |
22 | 23 | |
... | ... | @@ -126,6 +127,11 @@ public class WDailyFundsManagerImpl extends BaseManagerImpl<WDailyFundsDao, WDai |
126 | 127 | } |
127 | 128 | } |
128 | 129 | |
130 | + @Override | |
131 | + public List<HashMap<String, String>> getDailyFundsByDateList(String orgType, String date) { | |
132 | + return baseMapper.getDailyFundsByDateList(orgType,date); | |
133 | + } | |
134 | + | |
129 | 135 | private void verifyInitWDailyFunds(LocalDateTime fDate) { |
130 | 136 | Integer count = baseMapper.selectWDailyFundsCount(fDate); |
131 | 137 | if (count == null || count == 0) { | ... | ... |
No preview for this file type
backend/chkpower/src/main/resources/mapper/WDailyFundsMapper.xml
... | ... | @@ -102,4 +102,10 @@ |
102 | 102 | </foreach> |
103 | 103 | </if> |
104 | 104 | </select> |
105 | + | |
106 | + <select id="getDailyFundsByDateList" resultType="java.util.HashMap"> | |
107 | + SELECT * FROM w_daily_funds | |
108 | + WHERE F_org_type =#{fOrgType} and DATE(F_date) =DATE(#{fDate}) | |
109 | + ORDER BY F_order_no asc | |
110 | + </select> | |
105 | 111 | </mapper> | ... | ... |
frontend/front/src/components/tableSlot/dailyFunds/updateInspBtn.vue
1 | 1 | <template> |
2 | 2 | <div> |
3 | 3 | <el-button @click="dialogVisible = !dialogVisible">批量复核</el-button> |
4 | + <el-button @click="dcVisible = !dcVisible" style="margin-left: 10px">资金日报导出</el-button> | |
4 | 5 | <el-dialog title="批量复核" :visible.sync="dialogVisible" width="30%"> |
5 | 6 | <el-form ref="form" label-width="120px"> |
6 | 7 | <el-form-item label="复核状态"> |
... | ... | @@ -18,10 +19,22 @@ |
18 | 19 | <el-button type="primary" @click="onSubmit">确 认</el-button> |
19 | 20 | </span> |
20 | 21 | </el-dialog> |
22 | + <el-dialog title="资金日报导出" :visible.sync="dcVisible" width="30%"> | |
23 | + <el-form> | |
24 | + <el-form-item label="日期"> | |
25 | + <el-date-picker v-model="date" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" | |
26 | + style="width: calc(100% - 80px);"></el-date-picker> | |
27 | + </el-form-item> | |
28 | + </el-form> | |
29 | + <span slot="footer"> | |
30 | + <el-button @click="dcVisible = false">取 消</el-button> | |
31 | + <el-button type="primary" @click="onSubmitDc">导 出</el-button> | |
32 | + </span> | |
33 | + </el-dialog> | |
21 | 34 | </div> |
22 | 35 | </template> |
23 | 36 | <script> |
24 | -import {updateInsp} from '@/api/service/dailyFunds' | |
37 | +import {updateInsp, dailyFundsByDateExport} from '@/api/service/dailyFunds' | |
25 | 38 | import moment from 'moment' |
26 | 39 | |
27 | 40 | export default { |
... | ... | @@ -42,22 +55,25 @@ export default { |
42 | 55 | type: Object |
43 | 56 | } |
44 | 57 | }, |
45 | - | |
46 | 58 | data() { |
47 | 59 | return { |
48 | 60 | dialogVisible: false, |
49 | 61 | fInspStatusName: null, |
50 | 62 | fInspNotes: null, |
63 | + date: null, | |
64 | + dcVisible: false | |
51 | 65 | }; |
52 | 66 | }, |
53 | - | |
54 | 67 | created() { |
55 | - | |
68 | + let today = new Date(); | |
69 | + today.setDate(today.getDate() - 1); | |
70 | + let year = today.getFullYear(); | |
71 | + let month = ("0" + (today.getMonth() + 1)).slice(-2); | |
72 | + let day = ("0" + today.getDate()).slice(-2); | |
73 | + this.date = year + '-' + month + '-' + day; | |
56 | 74 | }, |
57 | 75 | methods: { |
58 | 76 | onSubmit() { |
59 | - | |
60 | - console.log('selectRows', this.selectRows); | |
61 | 77 | if (!this.selectRows || this.selectRows.length == 0) { |
62 | 78 | this.$message.error('请选择数据!'); |
63 | 79 | return false; |
... | ... | @@ -95,12 +111,21 @@ export default { |
95 | 111 | }); |
96 | 112 | } |
97 | 113 | }, |
98 | - onClick() { | |
99 | - // console.log('selectRows',this.selectRows); | |
100 | - // console.log('row',this.row); | |
101 | - // console.log('column',this.column); | |
102 | - // console.log('index',this.index); | |
103 | - // console.log('desc',this.desc); | |
114 | + onSubmitDc() { | |
115 | + if (!this.date) { | |
116 | + this.$message.error('请选择日期!'); | |
117 | + return false; | |
118 | + } | |
119 | + dailyFundsByDateExport(this.date).then(_ref => { | |
120 | + let {data, headers} = _ref; | |
121 | + // 附件下载 | |
122 | + const blob = new Blob([data]); | |
123 | + // 附件下载 | |
124 | + const fileName = decodeURIComponent(headers['content-disposition'].split(';')[1].split('filename=')[1]); | |
125 | + saveAs(blob, fileName); | |
126 | + }).catch(err => { | |
127 | + this.$message.error(`模板下载失败:${err}`); | |
128 | + }); | |
104 | 129 | } |
105 | 130 | } |
106 | 131 | } | ... | ... |