Merge branch 'test' of https://git.lionquexpress.com/wuweihua/BMS into test
This commit is contained in:
+7
-1
@@ -173,10 +173,16 @@ public class ArBillController extends BaseController {
|
||||
AjaxResult result = success();
|
||||
result.put("rows", pageData.getRows());
|
||||
result.put("total", pageData.getTotal());
|
||||
result.put("totalAmount", billService.sumPreviewBill(query));
|
||||
return result;
|
||||
}
|
||||
|
||||
/** 按需汇总生成预览范围内的应收金额。 */
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:generate')")
|
||||
@PostMapping("/generate/preview/amount")
|
||||
public AjaxResult previewAmount(@RequestBody ArBillGenerateQuery query) {
|
||||
return success(billService.sumPreviewBill(query));
|
||||
}
|
||||
|
||||
/** 按生成预览使用的相同筛选条件提交异步导出任务。 */
|
||||
@Log(title = "应收账单生成订单", businessType = BusinessType.EXPORT)
|
||||
@PreAuthorize("@ss.hasPermi('ar:bill:generate')")
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package com.bms.receivable;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.bms.common.config.BmsConfig;
|
||||
import com.bms.common.core.domain.AjaxResult;
|
||||
import com.bms.common.core.redis.RedisCache;
|
||||
import com.bms.price.domain.PrcOrderBill;
|
||||
import com.bms.receivable.domain.vo.ArBillGenerateQuery;
|
||||
import com.bms.receivable.security.ArBillScopeResolver;
|
||||
import com.bms.receivable.service.IArBillService;
|
||||
import com.bms.receivable.task.ArBillGeneratePreviewExportRunner;
|
||||
import com.bms.web.controller.receivable.ArBillController;
|
||||
|
||||
class ArBillGeneratePreviewTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void previewDoesNotCalculateAmountUntilAmountEndpointIsCalled() {
|
||||
IArBillService service = mock(IArBillService.class);
|
||||
ArBillController controller = new ArBillController();
|
||||
ReflectionTestUtils.setField(controller, "billService", service);
|
||||
ArBillGenerateQuery query = new ArBillGenerateQuery();
|
||||
when(service.previewBill(query)).thenReturn(List.of(new PrcOrderBill()));
|
||||
when(service.sumPreviewBill(query)).thenReturn(new BigDecimal("12.34"));
|
||||
|
||||
try {
|
||||
AjaxResult preview = controller.preview(query);
|
||||
assertFalse(preview.containsKey("totalAmount"));
|
||||
verify(service, never()).sumPreviewBill(query);
|
||||
} finally {
|
||||
PageHelper.clearPage();
|
||||
}
|
||||
|
||||
assertEquals(new BigDecimal("12.34"), controller.previewAmount(query).get("data"));
|
||||
verify(service).sumPreviewBill(query);
|
||||
}
|
||||
|
||||
@Test
|
||||
void exportEndsWithTheSumOfTheExportedAmounts() throws Exception {
|
||||
String previousProfile = BmsConfig.getProfile();
|
||||
try {
|
||||
new BmsConfig().setProfile(tempDir.toString());
|
||||
IArBillService service = mock(IArBillService.class);
|
||||
ArBillGenerateQuery query = new ArBillGenerateQuery();
|
||||
when(service.previewBill(same(query), isNull())).thenReturn(List.of(
|
||||
bill("A", "0.10"), bill("B", "0.20"), bill("C", "-0.05"), bill("D", null)));
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor() {
|
||||
@Override
|
||||
public void execute(Runnable task) {
|
||||
task.run();
|
||||
}
|
||||
};
|
||||
ArBillGeneratePreviewExportRunner runner = new ArBillGeneratePreviewExportRunner(
|
||||
service, mock(RedisCache.class), mock(ArBillScopeResolver.class), executor);
|
||||
for (String dateType : List.of("BIZ_DATE", "PICKUP_DATE")) {
|
||||
query.setDateType(dateType);
|
||||
String taskId = runner.submit(query, 1L);
|
||||
Path file = tempDir.resolve("download/arBillGeneratePreviewExport/" + taskId + ".xlsx");
|
||||
|
||||
try (InputStream in = Files.newInputStream(file); Workbook workbook = WorkbookFactory.create(in)) {
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
Row header = sheet.getRow(0);
|
||||
Row lastRow = sheet.getRow(sheet.getLastRowNum());
|
||||
assertEquals("合计", lastRow.getCell(column(header, "订单号")).getStringCellValue());
|
||||
assertEquals(0.25, lastRow.getCell(column(header, "应收金额")).getNumericCellValue(), 0.000001);
|
||||
assertEquals(5, sheet.getLastRowNum());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
new BmsConfig().setProfile(previousProfile);
|
||||
}
|
||||
}
|
||||
|
||||
private static PrcOrderBill bill(String orderNo, String amount) {
|
||||
PrcOrderBill bill = new PrcOrderBill();
|
||||
bill.setOrderNo(orderNo);
|
||||
bill.setIncomeTotal(amount == null ? null : new BigDecimal(amount));
|
||||
return bill;
|
||||
}
|
||||
|
||||
private static int column(Row header, String name) {
|
||||
for (int i = 0; i < header.getLastCellNum(); i++) {
|
||||
if (name.equals(header.getCell(i).getStringCellValue())) return i;
|
||||
}
|
||||
throw new AssertionError("缺少导出列: " + name);
|
||||
}
|
||||
}
|
||||
+10
-1
@@ -1,6 +1,7 @@
|
||||
package com.bms.receivable.task;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.LinkOption;
|
||||
import java.nio.file.Path;
|
||||
@@ -75,10 +76,18 @@ public class ArBillGeneratePreviewExportRunner {
|
||||
put(taskId, userId, "RUNNING", 5, "正在查询订单", null, 0, fileName, null);
|
||||
List<PrcOrderBill> bills = billService.previewBill(query, scope);
|
||||
put(taskId, userId, "RUNNING", 40, "正在生成 Excel", null, bills.size(), fileName, null);
|
||||
List<ArBillGeneratePreviewExportRow> rows = new ArrayList<>(bills.size());
|
||||
List<ArBillGeneratePreviewExportRow> rows = new ArrayList<>(bills.size() + 1);
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
for (PrcOrderBill bill : bills) {
|
||||
rows.add(ArBillGeneratePreviewExportRow.from(bill));
|
||||
if (bill.getIncomeTotal() != null) {
|
||||
totalAmount = totalAmount.add(bill.getIncomeTotal());
|
||||
}
|
||||
}
|
||||
ArBillGeneratePreviewExportRow totalRow = new ArBillGeneratePreviewExportRow();
|
||||
totalRow.setOrderNo("合计");
|
||||
totalRow.setIncomeTotal(totalAmount);
|
||||
rows.add(totalRow);
|
||||
ExcelUtil<ArBillGeneratePreviewExportRow> util = new ExcelUtil<>(ArBillGeneratePreviewExportRow.class);
|
||||
if (ArBillDateType.PICKUP_DATE == ArBillDateType.of(query.getDateType())) {
|
||||
util.hideColumn("bizDate");
|
||||
|
||||
@@ -694,14 +694,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{excludedBillId}
|
||||
</foreach>
|
||||
</if>
|
||||
<choose>
|
||||
<when test="dateType != null and dateType == 'PICKUP_DATE'">
|
||||
order by p.pickup_date, p.order_no, p.bill_id
|
||||
</when>
|
||||
<otherwise>
|
||||
order by p.biz_date, p.order_no, p.bill_id
|
||||
</otherwise>
|
||||
</choose>
|
||||
order by p.bill_id
|
||||
</select>
|
||||
|
||||
<select id="sumPrcOrderBillIncomeByCustomerPeriod" resultType="java.math.BigDecimal">
|
||||
|
||||
@@ -11,20 +11,27 @@
|
||||
AND bill_id IN
|
||||
<foreach collection="sourceIds" item="sourceId" open="(" separator="," close=")">#{sourceId}</foreach>
|
||||
</select>
|
||||
<!-- c 固定为客户表别名;无部门层级扩展,不按角色管理 data_scope 过滤。 -->
|
||||
<!-- c 固定为客户表别名;销售经理可见本部门及下级部门,不按角色管理 data_scope 过滤。 -->
|
||||
<sql id="customerScope">
|
||||
<choose>
|
||||
<when test="scope != null and scope.all"/>
|
||||
<when test="scope != null and (scope.self or scope.department)">
|
||||
AND c.del_flag = '0'
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM sys_user su
|
||||
WHERE CAST(su.user_id AS CHAR) = c.sales_user_id AND su.del_flag = '0'
|
||||
AND (1 = 0
|
||||
<if test="scope.self">OR su.user_id = #{scope.userId}</if>
|
||||
<if test="scope.department">OR su.dept_id = #{scope.deptId}</if>
|
||||
SELECT 1 FROM sys_user su
|
||||
WHERE CAST(su.user_id AS CHAR) = c.sales_user_id AND su.del_flag = '0'
|
||||
AND (1 = 0
|
||||
<if test="scope.self">OR su.user_id = #{scope.userId}</if>
|
||||
<if test="scope.department">
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM sys_dept dept
|
||||
WHERE dept.dept_id = su.dept_id
|
||||
AND (dept.dept_id = #{scope.deptId}
|
||||
OR find_in_set(#{scope.deptId}, dept.ancestors))
|
||||
)
|
||||
</if>
|
||||
)
|
||||
)
|
||||
)
|
||||
</when>
|
||||
<otherwise>AND 1 = 0</otherwise>
|
||||
</choose>
|
||||
|
||||
Reference in New Issue
Block a user