小数点保留两位
This commit is contained in:
1 parent
9154a813df
commit
f868d94b08
2 files changed
+96
-3
No files matched your search
+42
-2
@@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -30,23 +32,61 @@ public class ProfitReportServiceImpl implements ProfitReportService {
|
||||
@Override
|
||||
public Page<ProfitReportVO> page(Page<?> page, ProfitReportQueryDTO queryDTO) {
|
||||
log.info("分页查询毛利报表,查询条件:{}", queryDTO);
|
||||
return profitReportMapper.selectProfitReportPage(page, queryDTO, DataScope.of());
|
||||
Page<ProfitReportVO> result = profitReportMapper.selectProfitReportPage(page, queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
result.getRecords().forEach(this::formatProfitReportVO);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfitReportVO> list(ProfitReportQueryDTO queryDTO) {
|
||||
log.info("列表查询毛利报表,查询条件:{}", queryDTO);
|
||||
return profitReportMapper.selectProfitReportList(queryDTO, DataScope.of());
|
||||
List<ProfitReportVO> result = profitReportMapper.selectProfitReportList(queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
result.forEach(this::formatProfitReportVO);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProfitReportExcelDTO> exportExcel(ProfitReportQueryDTO queryDTO) {
|
||||
log.info("导出毛利报表,查询条件:{}", queryDTO);
|
||||
List<ProfitReportVO> list = profitReportMapper.selectProfitReportList(queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
list.forEach(this::formatProfitReportVO);
|
||||
|
||||
List<ProfitReportExcelDTO> excelList = BeanUtils.toBean(list, ProfitReportExcelDTO.class);
|
||||
log.info("导出毛利报表成功,导出记录数:{}", excelList.size());
|
||||
return excelList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化毛利报表VO的所有BigDecimal字段,保留两位小数
|
||||
*/
|
||||
private void formatProfitReportVO(ProfitReportVO vo) {
|
||||
if (vo.getSalesPrice() != null) {
|
||||
vo.setSalesPrice(vo.getSalesPrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getCostPrice() != null) {
|
||||
vo.setCostPrice(vo.getCostPrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getSalesAmount() != null) {
|
||||
vo.setSalesAmount(vo.getSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getSalesCost() != null) {
|
||||
vo.setSalesCost(vo.getSalesCost().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getGrossProfit() != null) {
|
||||
vo.setGrossProfit(vo.getGrossProfit().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getProfitMargin() != null) {
|
||||
vo.setProfitMargin(vo.getProfitMargin().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+54
-1
@@ -12,6 +12,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -40,6 +42,22 @@ public class SalesReportServiceImpl implements SalesReportService {
|
||||
|
||||
Page<SalesReportVO> result = salesReportMapper.selectSalesReportPage(page, queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
result.getRecords().forEach(vo -> {
|
||||
if (vo.getSalesPrice() != null) {
|
||||
vo.setSalesPrice(vo.getSalesPrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getSalesAmount() != null) {
|
||||
vo.setSalesAmount(vo.getSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getReturnAmount() != null) {
|
||||
vo.setReturnAmount(vo.getReturnAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getActualSalesAmount() != null) {
|
||||
vo.setActualSalesAmount(vo.getActualSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
});
|
||||
|
||||
log.info("查询结果数量: {} / 总数: {}", result.getRecords().size(), result.getTotal());
|
||||
log.info("======================================");
|
||||
|
||||
@@ -49,13 +67,48 @@ public class SalesReportServiceImpl implements SalesReportService {
|
||||
@Override
|
||||
public List<SalesReportVO> list(SalesReportQueryDTO queryDTO) {
|
||||
log.info("列表查询销售报表,查询条件:{}", queryDTO);
|
||||
return salesReportMapper.selectSalesReportList(queryDTO, DataScope.of());
|
||||
List<SalesReportVO> result = salesReportMapper.selectSalesReportList(queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
result.forEach(vo -> {
|
||||
if (vo.getSalesPrice() != null) {
|
||||
vo.setSalesPrice(vo.getSalesPrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getSalesAmount() != null) {
|
||||
vo.setSalesAmount(vo.getSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getReturnAmount() != null) {
|
||||
vo.setReturnAmount(vo.getReturnAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getActualSalesAmount() != null) {
|
||||
vo.setActualSalesAmount(vo.getActualSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SalesReportExcelDTO> exportExcel(SalesReportQueryDTO queryDTO) {
|
||||
log.info("导出销售报表,查询条件:{}", queryDTO);
|
||||
List<SalesReportVO> list = salesReportMapper.selectSalesReportList(queryDTO, DataScope.of());
|
||||
|
||||
// 确保所有 BigDecimal 字段保留两位小数
|
||||
list.forEach(vo -> {
|
||||
if (vo.getSalesPrice() != null) {
|
||||
vo.setSalesPrice(vo.getSalesPrice().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getSalesAmount() != null) {
|
||||
vo.setSalesAmount(vo.getSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getReturnAmount() != null) {
|
||||
vo.setReturnAmount(vo.getReturnAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
if (vo.getActualSalesAmount() != null) {
|
||||
vo.setActualSalesAmount(vo.getActualSalesAmount().setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
});
|
||||
|
||||
List<SalesReportExcelDTO> excelList = BeanUtils.toBean(list, SalesReportExcelDTO.class);
|
||||
log.info("导出销售报表成功,导出记录数:{}", excelList.size());
|
||||
return excelList;
|
||||
|
||||
Reference in new issue
Block a user