فهرست منبع

往来明细账

jz.kai 1 سال پیش
والد
کامیت
f5c1ae0cfe

+ 2 - 1
common/src/main/java/com/jpsoft/printing/modules/base/dao/AccountDAO.java

@@ -20,5 +20,6 @@ public interface AccountDAO {
 	List<Account> search(Map<String,Object> searchParams,List<Sort> sortList);
 	BigDecimal getBalance(String customerId, String deadline);
 	Account getByWorkId(String workId);
-	List<Account> findTransactionList(Integer type, String startDay, String endDay, String order, Integer limit);
+	List<Account> findTransactionList(String customerId, Integer type, String startDay, String endDay, String order, Integer limit);
+	List<Account> findList(String customerId, Integer type, String startDay, String endDay, String order);
 }

+ 24 - 0
common/src/main/java/com/jpsoft/printing/modules/base/dto/YearSoaDTO.java

@@ -0,0 +1,24 @@
+package com.jpsoft.printing.modules.base.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class YearSoaDTO {
+    @ApiModelProperty(value = "月")
+    private String month;
+    @ApiModelProperty(value = "日")
+    private String day;
+    @ApiModelProperty(value = "计划单号")
+    private String planNumber;
+    @ApiModelProperty(value = "摘要")
+    private String summary;
+    @ApiModelProperty(value = "借方")
+    private BigDecimal debit;
+    @ApiModelProperty(value = "贷方")
+    private BigDecimal credit;
+    @ApiModelProperty(value = "余额")
+    private BigDecimal balance;
+}

+ 2 - 1
common/src/main/java/com/jpsoft/printing/modules/base/service/AccountService.java

@@ -19,5 +19,6 @@ public interface AccountService {
 	Page<Account> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 	BigDecimal getBalance(String customerId, String deadline);
 	Account getByWorkId(String workId);
-	List<Account> findTransactionList(Integer type, String startDay, String endDay, String order, Integer limit);
+	List<Account> findTransactionList(String customerId, Integer type, String startDay, String endDay, String order, Integer limit);
+	List<Account> findList(String customerId, Integer type, String startDay, String endDay, String order);
 }

+ 7 - 2
common/src/main/java/com/jpsoft/printing/modules/base/service/impl/AccountServiceImpl.java

@@ -82,7 +82,12 @@ public class AccountServiceImpl implements AccountService {
 	}
 
 	@Override
-	public List<Account> findTransactionList(Integer type, String startDay, String endDay, String order, Integer limit) {
-		return accountDAO.findTransactionList(type, startDay, endDay, order, limit);
+	public List<Account> findTransactionList(String customerId, Integer type, String startDay, String endDay, String order, Integer limit) {
+		return accountDAO.findTransactionList(customerId, type, startDay, endDay, order, limit);
+	}
+
+	@Override
+	public List<Account> findList(String customerId, Integer type, String startDay, String endDay, String order) {
+		return accountDAO.findList(customerId, type, startDay, endDay, order);
 	}
 }

+ 29 - 3
common/src/main/resources/mapper/base/Account.xml

@@ -127,10 +127,10 @@ id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount
 	</select>
 	<select id="getBalance" parameterType="string" resultType="decimal">
 		<![CDATA[
-			SELECT SUM(amount_) FROM base_account
+			SELECT IFNULL(SUM(total_amount),0) FROM base_account
 			WHERE del_flag = 0
 			AND customer_id = #{customerId}
-			AND create_time <= CONCAT(#{deadline},' 23:59:59')
+			AND create_time < #{deadline}
 		]]>
 	</select>
 	<select id="getByWorkId" parameterType="string" resultMap="AccountMap">
@@ -138,13 +138,16 @@ id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount
 		where work_id = #{0}
 	</select>
 	<select id="findTransactionList" parameterType="string" resultMap="AccountMap">
-		SELECT a.customer_id, a.type_, SUM(actual_amount) AS actual_amount, SUM(cloth_amount) AS cloth_amount, SUM(roll_amount) AS roll_amount, SUM(total_amount) AS total_amount FROM base_account a
+		SELECT a.customer_id, a.type_, a.create_time, SUM(actual_amount) AS actual_amount, SUM(cloth_amount) AS cloth_amount, SUM(roll_amount) AS roll_amount, SUM(total_amount) AS total_amount FROM base_account a
 		LEFT JOIN base_customer b ON a.customer_id = b.id_
 		<where>
 			a.del_flag = 0
 			<if test="type != null">
 				AND a.type_ = ${type}
 			</if>
+			<if test="customerId != null">
+				AND a.customer_id = #{customerId}
+			</if>
 			<if test="startDay != null">
 				AND a.create_time >= #{startDay}
 			</if>
@@ -162,6 +165,29 @@ id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount
 			LIMIT ${limit}
 		</if>
 	</select>
+	<select id="findList" parameterType="string" resultMap="AccountMap">
+		SELECT id_,customer_id,work_id,type_,plan_number,IFNULL(actual_amount,0) as actual_amount,IFNULL(cloth_amount,0) AS cloth_amount,IFNULL(roll_amount,0) AS roll_amount,IFNULL(total_amount,0) AS total_amount,del_flag,create_by,create_time,update_by,update_time FROM base_account
+		<where>
+			del_flag = 0
+			<if test="type != null">
+				AND type_ = ${type}
+			</if>
+			<if test="customerId != null">
+				AND customer_id = #{customerId}
+			</if>
+			<if test="startDay != null">
+				AND create_time >= #{startDay}
+			</if>
+			<if test="endDay != null">
+				<![CDATA[
+				AND create_time < #{endDay}
+				]]>
+			</if>
+		</where>
+		<if test="order != null">
+			ORDER BY ${order}
+		</if>
+	</select>
 <!--	<resultMap id="NameValueDTOMap" type="com.jpsoft.printing.modules.base.dto.NameValueDTO">-->
 <!--		<result property="name" column="name_" />-->
 <!--		<result property="value" column="value_" />-->

+ 205 - 9
web/src/main/java/com/jpsoft/printing/modules/ReportController.java

@@ -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;
+    }
 }

+ 2 - 2
web/src/main/resources/application-dev.yml

@@ -5,9 +5,9 @@ server:
 
 spring:
   datasource:
-    url: jdbc:log4jdbc:mysql://47.92.161.104:3336/printing?useSSL=false&autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    url: jdbc:log4jdbc:mysql://192.168.77.177:3306/printing?useSSL=false&autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
     username: root
-    password: jpsoft8121234
+    password: jpsoft2023
 
 logger:
   level: WARN

+ 2 - 2
web/src/main/resources/application-test.yml

@@ -5,9 +5,9 @@ server:
 
 spring:
   datasource:
-    url: jdbc:log4jdbc:mysql://47.92.161.104:3336/printing?autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
+    url: jdbc:log4jdbc:mysql://47.92.161.104:3336/printing?useSSL=false&autoReconnect=true&characterEncoding=utf8&serverTimezone=GMT%2B8
     username: root
-    password: jpsoft2016
+    password: jpsoft8121234
   devtools:
     restart:
       enabled: true

BIN
web/src/main/resources/static/yearSOA.xls