|
@@ -0,0 +1,239 @@
|
|
|
|
+package com.txz.cif.web.mng;
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
|
+import cn.hutool.poi.excel.ExcelWriter;
|
|
|
|
+import com.txz.cif.core.Result;
|
|
|
|
+import com.txz.cif.model.DayCut;
|
|
|
|
+import com.txz.cif.model.Subject;
|
|
|
|
+import com.txz.cif.service.DayCutService;
|
|
|
|
+import com.txz.cif.service.SubjectService;
|
|
|
|
+import com.txz.cif.web.bo.AccountBO;
|
|
|
|
+import com.txz.cif.web.bo.SubjectBO;
|
|
|
|
+import com.txz.cif.web.para.AccountListParam;
|
|
|
|
+import com.txz.cif.web.para.InnerAccountParam;
|
|
|
|
+import com.txz.cif.web.para.RechargeForm;
|
|
|
|
+import com.txz.cif.web.para.SubjectListParam;
|
|
|
|
+import com.txz.cif.core.ResultGenerator;
|
|
|
|
+import com.txz.cif.model.Account;
|
|
|
|
+import com.txz.cif.service.AccountService;
|
|
|
|
+
|
|
|
|
+import com.txz.cif.core.ResultCode;
|
|
|
|
+
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import com.txz.core.ServiceException;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+
|
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
|
+import tk.mybatis.mapper.entity.Example.Criteria;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* Created by CodeGenerator on 2022/11/04.
|
|
|
|
+*/
|
|
|
|
+@Api(tags = "[后台]科目管理")
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/subject")
|
|
|
|
+public class SubjectController {
|
|
|
|
+
|
|
|
|
+ private static Logger log = LoggerFactory.getLogger(SubjectController.class);
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private SubjectService subjectService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private DayCutService dayCutService;
|
|
|
|
+
|
|
|
|
+ @PostMapping("/list")
|
|
|
|
+ @ApiOperation(value = "获取科目列表",httpMethod = "POST")
|
|
|
|
+ public Result<List<SubjectBO>> list(@Validated @RequestBody SubjectListParam param) {
|
|
|
|
+ if (param.getStartTime().length()>10){
|
|
|
|
+ param.setStartTime(param.getStartTime().substring(0,9));
|
|
|
|
+ }
|
|
|
|
+ if (param.getEndTime().length()>10){
|
|
|
|
+ param.setEndTime(param.getEndTime().substring(0,9));
|
|
|
|
+ }
|
|
|
|
+ Date endTime = DateUtil.parse(param.getEndTime(),"yyyy-MM-DD");
|
|
|
|
+ if (endTime.after(DateUtil.yesterday())){
|
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.ENDTIME_ERROR);
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ List<Subject> subjects = subjectService.findAll();
|
|
|
|
+ if (CollUtil.isEmpty(subjects)){
|
|
|
|
+ return ResultGenerator.genSuccessResult(CollUtil.newArrayList());
|
|
|
|
+ }
|
|
|
|
+ List<SubjectBO> list = new ArrayList<>();
|
|
|
|
+ for (Subject subject:subjects) {
|
|
|
|
+ SubjectBO bo = BeanUtil.toBean(subject,SubjectBO.class);
|
|
|
|
+ bo.setSubjectId(subject.getId());
|
|
|
|
+ if (subject.getLeaf() == 1){
|
|
|
|
+ //设置初始日余额、日余额、借方发生额、贷方发生额
|
|
|
|
+ DayCut startDayCut = dayCutService.findByDayAndSubjectId(param.getStartTime(),subject.getId());
|
|
|
|
+ if (startDayCut == null){
|
|
|
|
+ startDayCut = DayCut.builder().initAmount(BigDecimal.ZERO).build();
|
|
|
|
+ }
|
|
|
|
+ bo.setInitAmount(startDayCut.getInitAmount());
|
|
|
|
+ DayCut endDayCut = dayCutService.findByDayAndSubjectId(param.getEndTime(),subject.getId());
|
|
|
|
+ if (endDayCut == null){
|
|
|
|
+ endDayCut = DayCut.builder().initAmount(BigDecimal.ZERO).build();
|
|
|
|
+ }
|
|
|
|
+ bo.setEndAmount(endDayCut.getEndAmount());
|
|
|
|
+ bo.setDebitAmount(dayCutService.sumAmount(subject.getId(),"D",param.getStartTime(),param.getEndTime()));
|
|
|
|
+ bo.setCreditAmount(dayCutService.sumAmount(subject.getId(),"C",param.getStartTime(),param.getEndTime()));
|
|
|
|
+ }
|
|
|
|
+ list.add(bo);
|
|
|
|
+ }
|
|
|
|
+ Map<String, SubjectBO> map = assembling(list);
|
|
|
|
+ List<SubjectBO> ret = CollUtil.newArrayList(map.get("1"),map.get("2"),map.get("3"),map.get("4"));
|
|
|
|
+ return ResultGenerator.genSuccessResult(ret);
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("查询对象操作异常e:{}",e);
|
|
|
|
+ return ResultGenerator.genFailResult(ResultCode.INTERNAL_SERVER_ERROR);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 组装树结构
|
|
|
|
+ * @param list
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Map<String, SubjectBO> assembling(List<SubjectBO> list) {
|
|
|
|
+ Map<String, SubjectBO> temp = new HashMap(list.size());
|
|
|
|
+ for (SubjectBO subject:list) {
|
|
|
|
+ //存入自己
|
|
|
|
+ temp.put(subject.getSubjectId()+"",subject);
|
|
|
|
+ }
|
|
|
|
+ for (SubjectBO subject:list) {
|
|
|
|
+ //寻找父亲
|
|
|
|
+ SubjectBO parent = temp.get(subject.getParentId()+"");
|
|
|
|
+ if (parent == null){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (CollUtil.isEmpty(parent.getChildren())){
|
|
|
|
+ parent.setChildren(CollUtil.newArrayList(subject));
|
|
|
|
+ } else {
|
|
|
|
+ parent.getChildren().add(subject);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return temp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @GetMapping("/export")
|
|
|
|
+ @ApiOperation(value = "导出",httpMethod = "GET")
|
|
|
|
+ public void export( SubjectListParam param, HttpServletResponse response) {
|
|
|
|
+ ExcelWriter writer = ExcelUtil.getWriter();
|
|
|
|
+ try {
|
|
|
|
+ /**
|
|
|
|
+ */
|
|
|
|
+ String head = "账务数据";
|
|
|
|
+ List<List<Object>> rows = new LinkedList<>();
|
|
|
|
+ try {
|
|
|
|
+ if (param.getStartTime().length()>10){
|
|
|
|
+ param.setStartTime(param.getStartTime().substring(0,9));
|
|
|
|
+ }
|
|
|
|
+ if (param.getEndTime().length()>10){
|
|
|
|
+ param.setEndTime(param.getEndTime().substring(0,9));
|
|
|
|
+ }
|
|
|
|
+ Date endTime = DateUtil.parse(param.getEndTime(),"yyyy-MM-DD");
|
|
|
|
+ if (endTime.after(DateUtil.yesterday())){
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ head = param.getStartTime()+"-"+param.getEndTime()+head;
|
|
|
|
+ List<Subject> subjects = subjectService.findAll();
|
|
|
|
+ if (CollUtil.isEmpty(subjects)){
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ List<SubjectBO> list = new ArrayList<>();
|
|
|
|
+ for (Subject subject:subjects) {
|
|
|
|
+ SubjectBO bo = BeanUtil.toBean(subject,SubjectBO.class);
|
|
|
|
+ bo.setSubjectId(subject.getId());
|
|
|
|
+ if (subject.getLeaf() == 1){
|
|
|
|
+ //设置初始日余额、日余额、借方发生额、贷方发生额
|
|
|
|
+ DayCut startDayCut = dayCutService.findByDayAndSubjectId(param.getStartTime(),subject.getId());
|
|
|
|
+ if (startDayCut == null){
|
|
|
|
+ startDayCut = DayCut.builder().initAmount(BigDecimal.ZERO).build();
|
|
|
|
+ }
|
|
|
|
+ bo.setInitAmount(startDayCut.getInitAmount());
|
|
|
|
+ DayCut endDayCut = dayCutService.findByDayAndSubjectId(param.getEndTime(),subject.getId());
|
|
|
|
+ if (endDayCut == null){
|
|
|
|
+ endDayCut = DayCut.builder().endAmount(BigDecimal.ZERO).build();
|
|
|
|
+ }
|
|
|
|
+ bo.setEndAmount(endDayCut.getEndAmount());
|
|
|
|
+ bo.setDebitAmount(dayCutService.sumAmount(subject.getId(),"D",param.getStartTime(),param.getEndTime()));
|
|
|
|
+ bo.setCreditAmount(dayCutService.sumAmount(subject.getId(),"C",param.getStartTime(),param.getEndTime()));
|
|
|
|
+ }
|
|
|
|
+ list.add(bo);
|
|
|
|
+ }
|
|
|
|
+ Map<String, SubjectBO> map = assembling(list);
|
|
|
|
+ List<SubjectBO> ret = CollUtil.newArrayList(map.get("1"),map.get("2"),map.get("3"),map.get("4"));
|
|
|
|
+
|
|
|
|
+ for (SubjectBO temp:ret) {
|
|
|
|
+ List<Object> rowA = CollUtil.newArrayList(temp.getAliases()
|
|
|
|
+ , temp.getName()
|
|
|
|
+ , temp.getDirection()
|
|
|
|
+ , temp.getInitAmount().toPlainString()
|
|
|
|
+ , temp.getDebitAmount().toPlainString()
|
|
|
|
+ , temp.getCreditAmount().toPlainString()
|
|
|
|
+ , temp.getEndAmount().toPlainString()
|
|
|
|
+ );
|
|
|
|
+ rows.add(rowA);
|
|
|
|
+ if (CollUtil.isNotEmpty(temp.getChildren())){
|
|
|
|
+ for (SubjectBO temp2:temp.getChildren()) {
|
|
|
|
+ List<Object> rowA2 = CollUtil.newArrayList(temp2.getAliases()
|
|
|
|
+ , temp2.getName()
|
|
|
|
+ , temp2.getDirection()
|
|
|
|
+ , temp2.getInitAmount().toPlainString()
|
|
|
|
+ , temp2.getDebitAmount().toPlainString()
|
|
|
|
+ , temp2.getCreditAmount().toPlainString()
|
|
|
|
+ , temp2.getEndAmount().toPlainString()
|
|
|
|
+ );
|
|
|
|
+ rows.add(rowA2);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("查询对象操作异常e:{}",e);
|
|
|
|
+ return ;
|
|
|
|
+ }
|
|
|
|
+ List<String> rowHead = CollUtil.newArrayList("科目别名", "科目", "余额方向", "初始日余额",
|
|
|
|
+ "借方发生额","贷方发生额","日余额");
|
|
|
|
+ writer.writeHeadRow(rowHead);
|
|
|
|
+ writer.write(rows);
|
|
|
|
+ //设置宽度自适应
|
|
|
|
+ writer.setColumnWidth(-1, 22);
|
|
|
|
+ //response为HttpServletResponse对象
|
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
|
+ //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + new String((head).getBytes("UTF-8"), "ISO-8859-1") + ".xls");
|
|
|
|
+ ServletOutputStream out = response.getOutputStream();
|
|
|
|
+ //out为OutputStream,需要写出到的目标流
|
|
|
|
+ writer.flush(out);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("导出异常",e);
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ // 关闭writer,释放内存
|
|
|
|
+ writer.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|