|
@@ -1,16 +1,14 @@
|
|
|
package com.jpsoft.printing.modules;
|
|
|
|
|
|
-import com.github.pagehelper.Page;
|
|
|
import com.jpsoft.printing.config.OSSConfig;
|
|
|
-import com.jpsoft.printing.modules.base.dto.NameValueDTO;
|
|
|
+import com.jpsoft.printing.modules.base.dto.YearSoaDTO;
|
|
|
import com.jpsoft.printing.modules.base.entity.Account;
|
|
|
import com.jpsoft.printing.modules.base.entity.Customer;
|
|
|
import com.jpsoft.printing.modules.base.service.AccountService;
|
|
|
import com.jpsoft.printing.modules.base.service.CustomerService;
|
|
|
-import com.jpsoft.printing.modules.base.service.WorkService;
|
|
|
import com.jpsoft.printing.modules.common.dto.MessageResult;
|
|
|
-import com.jpsoft.printing.modules.common.utils.OSSUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiModelProperty;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
@@ -23,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.io.*;
|
|
@@ -49,7 +46,7 @@ public class ReportController {
|
|
|
public MessageResult transactionRanking(String startDay, String endDay, Integer limit){
|
|
|
MessageResult msgResult = new MessageResult<>();
|
|
|
|
|
|
- List<Account> list = accountService.findTransactionList(0, startDay, endDay, "total_amount ASC", limit);
|
|
|
+ List<Account> list = accountService.findTransactionList(null,0, startDay, endDay, "total_amount ASC", limit);
|
|
|
for(Account account : list){
|
|
|
account.setTotalAmount(account.getTotalAmount().negate());
|
|
|
|
|
@@ -79,7 +76,7 @@ public class ReportController {
|
|
|
public MessageResult transactionRankingXls(String startDay, String endDay, Integer limit, String title) throws Exception {
|
|
|
MessageResult msgResult = new MessageResult<>();
|
|
|
|
|
|
- List<Account> list = accountService.findTransactionList(0, startDay, endDay, "total_amount ASC", limit);
|
|
|
+ List<Account> list = accountService.findTransactionList(null, 0, startDay, endDay, "total_amount ASC", limit);
|
|
|
for(Account account : list){
|
|
|
account.setTotalAmount(account.getTotalAmount().negate());
|
|
|
|
|
@@ -144,7 +141,7 @@ public class ReportController {
|
|
|
public MessageResult transactionReportBoss(String startDay, String endDay){
|
|
|
MessageResult msgResult = new MessageResult<>();
|
|
|
|
|
|
- List<Account> list = accountService.findTransactionList(0, startDay, endDay, "b.name_ ASC", null);
|
|
|
+ List<Account> list = accountService.findTransactionList(null, 0, startDay, endDay, "b.name_ ASC", null);
|
|
|
for(Account account : list){
|
|
|
account.setTotalAmount(account.getTotalAmount().negate());
|
|
|
|
|
@@ -174,7 +171,7 @@ public class ReportController {
|
|
|
public MessageResult transactionReportBossXls(String startDay, String endDay, String title) throws Exception {
|
|
|
MessageResult msgResult = new MessageResult<>();
|
|
|
|
|
|
- List<Account> list = accountService.findTransactionList(0, startDay, endDay, "b.name_ ASC", null);
|
|
|
+ List<Account> list = accountService.findTransactionList(null, 0, startDay, endDay, "b.name_ ASC", null);
|
|
|
for(Account account : list){
|
|
|
account.setTotalAmount(account.getTotalAmount().negate());
|
|
|
|
|
@@ -236,4 +233,203 @@ public class ReportController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="年度对账单")
|
|
|
+ @RequestMapping(value = "yearSOA",method = RequestMethod.POST)
|
|
|
+ public MessageResult yearSOA(String customerId, Date selectDate){
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat sdfEx = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ Customer customer = customerService.get(customerId);
|
|
|
+ if (StringUtils.isNotEmpty(customer.getCompany())) {
|
|
|
+ map.put("name", customer.getName() + "(" + customer.getCompany() + ")");
|
|
|
+ } else {
|
|
|
+ map.put("name", customer.getName());
|
|
|
+ }
|
|
|
+ map.put("year", sdf.format(selectDate).substring(0,4));
|
|
|
+
|
|
|
+ List<YearSoaDTO> list = new ArrayList<>();
|
|
|
+
|
|
|
+ BigDecimal debitAmount = new BigDecimal(0);
|
|
|
+ BigDecimal creditAmount = new BigDecimal(0);
|
|
|
+ for(int i=0; i<12; i++) {
|
|
|
+ Calendar calendarStart = Calendar.getInstance();
|
|
|
+ calendarStart.setTime(selectDate);
|
|
|
+ calendarStart.add(Calendar.MONTH, i);
|
|
|
+ String dateStart = sdf.format(calendarStart.getTime());
|
|
|
+
|
|
|
+ Calendar calendarEnd = Calendar.getInstance();
|
|
|
+ calendarEnd.setTime(selectDate);
|
|
|
+ calendarEnd.add(Calendar.MONTH, i+1);
|
|
|
+ String dateEnd = sdf.format(calendarEnd.getTime());
|
|
|
+
|
|
|
+ if(i == 0) {
|
|
|
+ YearSoaDTO dtoStart = new YearSoaDTO();
|
|
|
+ dtoStart.setSummary("承上页");
|
|
|
+ dtoStart.setBalance(accountService.getBalance(customerId, dateStart));
|
|
|
+ list.add(dtoStart);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Account> accountList = accountService.findList(customerId, null, dateStart, dateEnd, "create_time ASC");
|
|
|
+ if(accountList.size() > 0) {
|
|
|
+ String month = "";
|
|
|
+ String day = "";
|
|
|
+ String planNumber = "";
|
|
|
+ BigDecimal actualAmount = new BigDecimal(0);
|
|
|
+ BigDecimal clothAmount = new BigDecimal(0);
|
|
|
+ BigDecimal rollAmount = new BigDecimal(0);
|
|
|
+ BigDecimal totalAmount = new BigDecimal(0);
|
|
|
+ Integer temp = -1;
|
|
|
+ for (int j = 0; j < accountList.size(); j++) {
|
|
|
+ Account account = accountList.get(j);
|
|
|
+ if (account.getType() != temp) {
|
|
|
+ month = sdf.format(account.getCreateTime()).substring(5, 7);
|
|
|
+ day = sdf.format(account.getCreateTime()).substring(8, 10);
|
|
|
+ planNumber += account.getPlanNumber() + " ";
|
|
|
+ actualAmount = actualAmount.add(account.getActualAmount());
|
|
|
+ clothAmount = clothAmount.add(account.getClothAmount());
|
|
|
+ rollAmount = rollAmount.add(account.getRollAmount());
|
|
|
+ totalAmount = totalAmount.add(account.getTotalAmount());
|
|
|
+
|
|
|
+ temp = account.getType();
|
|
|
+ } else {
|
|
|
+ planNumber += account.getPlanNumber() + " ";
|
|
|
+ actualAmount = actualAmount.add(account.getActualAmount());
|
|
|
+ clothAmount = clothAmount.add(account.getClothAmount());
|
|
|
+ rollAmount = rollAmount.add(account.getRollAmount());
|
|
|
+ totalAmount = totalAmount.add(account.getTotalAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (j + 1 == accountList.size() || account.getType() != accountList.get(j + 1).getType()) {
|
|
|
+ Calendar calendarNow = Calendar.getInstance();
|
|
|
+ calendarNow.setTime(account.getCreateTime());
|
|
|
+ calendarNow.add(Calendar.SECOND, 1);
|
|
|
+
|
|
|
+ YearSoaDTO dto = new YearSoaDTO();
|
|
|
+ dto.setMonth(month);
|
|
|
+ dto.setDay(day);
|
|
|
+ switch (account.getType()) {
|
|
|
+ case 0:
|
|
|
+ debitAmount = debitAmount.add(totalAmount);
|
|
|
+ dto.setPlanNumber(planNumber);
|
|
|
+ dto.setSummary(String.format("加工金额:%s 坯布金额:%s 力工金额:%s", actualAmount, clothAmount, rollAmount));
|
|
|
+ dto.setDebit(totalAmount);
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ creditAmount = creditAmount.add(totalAmount);
|
|
|
+ dto.setPlanNumber("收款");
|
|
|
+ dto.setSummary("收款");
|
|
|
+ dto.setCredit(totalAmount);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ debitAmount = debitAmount.add(totalAmount);
|
|
|
+ dto.setPlanNumber("冲账");
|
|
|
+ dto.setSummary("平账");
|
|
|
+ dto.setDebit(totalAmount);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String str = sdfEx.format(calendarNow.getTime());
|
|
|
+
|
|
|
+ dto.setBalance(accountService.getBalance(customerId, sdfEx.format(calendarNow.getTime())));
|
|
|
+ list.add(dto);
|
|
|
+
|
|
|
+ month = "";
|
|
|
+ day = "";
|
|
|
+ planNumber = "";
|
|
|
+ actualAmount = new BigDecimal(0);
|
|
|
+ clothAmount = new BigDecimal(0);
|
|
|
+ rollAmount = new BigDecimal(0);
|
|
|
+ totalAmount = new BigDecimal(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(i == 11) {
|
|
|
+ YearSoaDTO dtoEnd = new YearSoaDTO();
|
|
|
+ dtoEnd.setMonth("合计");
|
|
|
+ dtoEnd.setSummary("启下页");
|
|
|
+ dtoEnd.setDebit(debitAmount);
|
|
|
+ dtoEnd.setCredit(creditAmount);
|
|
|
+ dtoEnd.setBalance(accountService.getBalance(customerId, dateEnd));
|
|
|
+ list.add(dtoEnd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("list", list);
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(map);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="年度对账单报表")
|
|
|
+ @RequestMapping(value = "yearSOAXls",method = RequestMethod.POST)
|
|
|
+ public MessageResult yearSOAXls(String customerId, Date selectDate) throws Exception {
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ Map<String, Object> map = (Map<String, Object>)yearSOA(customerId, selectDate).getData();
|
|
|
+
|
|
|
+ String xlsPath = "static/yearSOA.xls";
|
|
|
+ ClassPathResource resource = new ClassPathResource(xlsPath);
|
|
|
+ Workbook wb = WorkbookFactory.create(resource.getInputStream());
|
|
|
+
|
|
|
+ //写入数据
|
|
|
+ Sheet sheet = wb.getSheetAt(0);
|
|
|
+ Row rowTitle1 = sheet.getRow(0);
|
|
|
+ rowTitle1.getCell(0).setCellValue("往来明细账--" + map.get("name"));
|
|
|
+ Row rowTitle2 = sheet.getRow(1);
|
|
|
+ rowTitle2.getCell(0).setCellValue(map.get("year") + "年");
|
|
|
+ int rowNum = 3;
|
|
|
+
|
|
|
+ BigDecimal debit = new BigDecimal(0);
|
|
|
+ BigDecimal credit = new BigDecimal(0);
|
|
|
+ BigDecimal balance = new BigDecimal(0);
|
|
|
+ List<YearSoaDTO> list = (List<YearSoaDTO>)map.get("list");
|
|
|
+ for(int i=0; i<list.size(); i++) {
|
|
|
+ YearSoaDTO yearSoaDTO = list.get(i);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
+ row.createCell(0).setCellValue(yearSoaDTO.getMonth());
|
|
|
+ row.createCell(1).setCellValue(yearSoaDTO.getDay());
|
|
|
+ row.createCell(2).setCellValue(yearSoaDTO.getPlanNumber());
|
|
|
+ row.createCell(3).setCellValue(yearSoaDTO.getSummary());
|
|
|
+ if(yearSoaDTO.getDebit() != null) {
|
|
|
+ debit = debit.add(yearSoaDTO.getDebit());
|
|
|
+ row.createCell(4).setCellValue(yearSoaDTO.getDebit().doubleValue());
|
|
|
+ }
|
|
|
+ if(yearSoaDTO.getCredit() != null) {
|
|
|
+ credit = credit.add(yearSoaDTO.getCredit());
|
|
|
+ row.createCell(6).setCellValue(yearSoaDTO.getCredit().doubleValue());
|
|
|
+ }
|
|
|
+ if(yearSoaDTO.getBalance() != null) {
|
|
|
+ balance = balance.add(yearSoaDTO.getBalance());
|
|
|
+ row.createCell(8).setCellValue(yearSoaDTO.getBalance().doubleValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ rowNum++;
|
|
|
+ }
|
|
|
+// Row rowTitle1 = sheet.createRow(rowNum);
|
|
|
+// rowTitle1.createCell(0).setCellValue("合计");
|
|
|
+
|
|
|
+ //保存到服务器,返回文件名
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+ String fileName = "往来明细账(" + sdf.format(new Date()) + ").xls";
|
|
|
+ String name = "D:\\JpSoft\\Tomcat 8.5\\webapps\\printing-portal\\xls\\" + fileName;
|
|
|
+ File file = new File(name);
|
|
|
+ FileOutputStream file1 = new FileOutputStream(file);
|
|
|
+ wb.write(file1);
|
|
|
+ file1.close();
|
|
|
+ wb.close();
|
|
|
+ output.close();
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("报表生成完成。");
|
|
|
+ msgResult.setData("/printing-portal/xls/" + fileName);
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|