fix: 新增按显示位数导出数据

This commit is contained in:
han0
2025-01-21 15:37:35 +08:00
parent bf9ba7ccca
commit 9f2f24fcb9
7 changed files with 158 additions and 28 deletions

View File

@@ -18,6 +18,7 @@ import mjkf.xinke.main.constant.PricePublishStatus;
import mjkf.xinke.main.constant.PricePublishType; import mjkf.xinke.main.constant.PricePublishType;
import mjkf.xinke.main.handler.CustomSheetWriteHandler; import mjkf.xinke.main.handler.CustomSheetWriteHandler;
import mjkf.xinke.main.model.db.PricePublish; import mjkf.xinke.main.model.db.PricePublish;
import mjkf.xinke.main.model.vo.PricePublishExport;
import mjkf.xinke.main.model.vo.PublicResponse; import mjkf.xinke.main.model.vo.PublicResponse;
import mjkf.xinke.main.model.vo.PublicTrendResponse; import mjkf.xinke.main.model.vo.PublicTrendResponse;
import mjkf.xinke.main.service.PdfService; import mjkf.xinke.main.service.PdfService;
@@ -145,11 +146,12 @@ public class PublicController {
query.eq(PricePublish::getType, PricePublishType.CURRENT); query.eq(PricePublish::getType, PricePublishType.CURRENT);
query.eq(PricePublish::getStatus, PricePublishStatus.DONE); query.eq(PricePublish::getStatus, PricePublishStatus.DONE);
query.orderByAsc(PricePublish::getMaterialId); query.orderByAsc(PricePublish::getMaterialId);
var result = pricePublishService.list(query); var result = pricePublishService.list(query).stream().filter(i->ObjectUtil.isNotEmpty(i.getMaterialId()))
result = result.stream().filter(i->ObjectUtil.isNotEmpty(i.getMaterialId())).collect(Collectors.toList()); .map(item -> new PricePublishExport(item))
.collect(Collectors.toList());
// excel // excel
var tempFile = File.createTempFile("temp_history_file", ".xlsx"); var tempFile = File.createTempFile("temp_history_file", ".xlsx");
EasyExcel.write(tempFile, PricePublish.class) EasyExcel.write(tempFile, PricePublishExport.class)
.registerWriteHandler(new CustomSheetWriteHandler()) .registerWriteHandler(new CustomSheetWriteHandler())
.sheet("sheet1").doWrite(result); .sheet("sheet1").doWrite(result);
// to pdf // to pdf

View File

@@ -89,7 +89,6 @@ public class PricePublish extends Model<PricePublish> {
@TableField("MATERIAL_ID") @TableField("MATERIAL_ID")
@ExcelProperty({"材料代码"}) @ExcelProperty({"材料代码"})
@ColumnWidth(15) @ColumnWidth(15)
// @ContentStyle(borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
private String materialId; private String materialId;
@ApiModelProperty("年份") @ApiModelProperty("年份")
@@ -104,14 +103,12 @@ public class PricePublish extends Model<PricePublish> {
@TableField("`NAME`") @TableField("`NAME`")
@ExcelProperty({"材料名称"}) @ExcelProperty({"材料名称"})
@ColumnWidth(20) @ColumnWidth(20)
// @ContentStyle(borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
private String name; private String name;
@ApiModelProperty("规格") @ApiModelProperty("规格")
@TableField("`SPEC`") @TableField("`SPEC`")
@ExcelProperty({"规格"}) @ExcelProperty({"规格"})
@ColumnWidth(34) @ColumnWidth(34)
// @ContentStyle(borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
private String spec; private String spec;
@ApiModelProperty("价格") @ApiModelProperty("价格")
@@ -171,7 +168,6 @@ public class PricePublish extends Model<PricePublish> {
@ApiModelProperty("漳州开发区价格") @ApiModelProperty("漳州开发区价格")
@TableField("PRICE_ZHANGZHOUKFQ") @TableField("PRICE_ZHANGZHOUKFQ")
@ExcelProperty({"漳州开发区"}) @ExcelProperty({"漳州开发区"})
// @ContentStyle(borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
private BigDecimal priceZhangzhouKfq; private BigDecimal priceZhangzhouKfq;
@ApiModelProperty("税率") @ApiModelProperty("税率")
@@ -189,7 +185,6 @@ public class PricePublish extends Model<PricePublish> {
@ApiModelProperty("单位") @ApiModelProperty("单位")
@TableField("UNIT") @TableField("UNIT")
@ColumnWidth(5) @ColumnWidth(5)
// @ContentStyle(borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
@ExcelProperty(value={"单位"}, index=3) @ExcelProperty(value={"单位"}, index=3)
private String unit; private String unit;
@@ -199,7 +194,7 @@ public class PricePublish extends Model<PricePublish> {
@ApiModelProperty("显示小数位数") @ApiModelProperty("显示小数位数")
@TableField("DISPLAY_DIGIT") @TableField("DISPLAY_DIGIT")
private Float displayDigit; private Integer displayDigit;
@Override @Override
public Serializable pkVal() { public Serializable pkVal() {

View File

@@ -151,7 +151,7 @@ public class PriceResult extends Model<PriceResult> {
@ApiModelProperty("显示小数位数") @ApiModelProperty("显示小数位数")
@TableField("DISPLAY_DIGIT") @TableField("DISPLAY_DIGIT")
private Float displayDigit; private Integer displayDigit;
private Float weightFtb; private Float weightFtb;
private Float weightSs; private Float weightSs;

View File

@@ -0,0 +1,120 @@
package mjkf.xinke.main.model.vo;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import mjkf.xinke.main.model.db.PricePublish;
/**
* <p>
* 计算结果
* </p>
*
* @author han0
* @since 2023-11-10
*/
@Getter
@Setter
@ApiModel(value = "PriceResultExport对象", description = "计算结果")
public class PricePublishExport {
@ApiModelProperty("编号")
@ExcelProperty({"材料代码"})
@ColumnWidth(15)
private String materialId;
@ApiModelProperty("材料名称")
@ExcelProperty({"材料名称"})
@ColumnWidth(20)
private String name;
@ApiModelProperty("规格")
@ExcelProperty({"规格"})
@ColumnWidth(34)
private String spec;
@ApiModelProperty("福州价格")
@ExcelProperty({"福州"})
private String priceFuzhou;
@ApiModelProperty("厦门价格")
@ExcelProperty({"厦门"})
private String priceXiamen;
@ApiModelProperty("莆田价格")
@ExcelProperty({"莆田"})
private String pricePutian;
@ApiModelProperty("三明价格")
@ExcelProperty({"三明"})
private String priceSanming;
@ApiModelProperty("泉州价格")
@ExcelProperty({"泉州"})
private String priceQuanzhou;
@ApiModelProperty("漳州价格")
@ExcelProperty({"漳州"})
private String priceZhangzhou;
@ApiModelProperty("南平价格")
@ExcelProperty({"南平"})
private String priceNanpin;
@ApiModelProperty("龙岩价格")
@ExcelProperty({"龙岩"})
private String priceLongyan;
@ApiModelProperty("宁德价格")
@ExcelProperty({"宁德"})
private String priceNingde;
@ApiModelProperty("平潭价格")
@ExcelProperty({"平潭"})
private String pricePintan;
@ApiModelProperty("漳州开发区价格")
@ExcelProperty({"漳州开发区"})
private String priceZhangzhouKfq;
@ApiModelProperty("单位")
@ColumnWidth(5)
@ExcelProperty(value = {"单位"}, index = 3)
private String unit;
public PricePublishExport() {
}
public PricePublishExport(PricePublish data) {
var digit = data.getDisplayDigit();
if (ObjectUtil.isEmpty(digit)) {
digit = 1;
}
var digitFormat = StrUtil.format("%.{}f", digit);
this.setMaterialId(data.getMaterialId());
this.setName(data.getName());
this.setSpec(data.getSpec());
this.setUnit(data.getUnit());
this.setMaterialId(data.getMaterialId());
this.setName(data.getName());
this.setPriceFuzhou(String.format(digitFormat, data.getPriceFuzhou()));
this.setPriceXiamen(String.format(digitFormat, data.getPriceXiamen()));
this.setPricePutian(String.format(digitFormat, data.getPricePutian()));
this.setPriceSanming(String.format(digitFormat, data.getPriceSanming()));
this.setPriceQuanzhou(String.format(digitFormat, data.getPriceQuanzhou()));
this.setPriceZhangzhou(String.format(digitFormat, data.getPriceZhangzhou()));
this.setPriceNanpin(String.format(digitFormat, data.getPriceNanpin()));
this.setPriceLongyan(String.format(digitFormat, data.getPriceLongyan()));
this.setPriceNingde(String.format(digitFormat, data.getPriceNingde()));
this.setPricePintan(String.format(digitFormat, data.getPricePintan()));
this.setPriceZhangzhouKfq(String.format(digitFormat, data.getPriceZhangzhouKfq()));
}
}

View File

@@ -1,5 +1,7 @@
package mjkf.xinke.main.model.vo; package mjkf.xinke.main.model.vo;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import lombok.Getter; import lombok.Getter;
@@ -76,23 +78,31 @@ public class PriceResultExport {
public PriceResultExport() {} public PriceResultExport() {}
public PriceResultExport(PriceResult data) { public PriceResultExport(PriceResult data) {
var digit = data.getDisplayDigit();
if (ObjectUtil.isEmpty(digit)) {
digit = 1;
}
var digitFormat = StrUtil.format("%.{}f", digit);
this.setPriceFtb(String.format(digitFormat, data.getPriceFtb()));
this.setFluctuatingFtb(String.format(digitFormat, data.getFluctuatingFtb()));
this.setPriceSs(String.format(digitFormat, data.getPriceSs()));
this.setFluctuatingSs(String.format(digitFormat, data.getFluctuatingSs()));
this.setPriceFhb(String.format(digitFormat, data.getPriceFhb()));
this.setFluctuatingFhb(String.format(digitFormat, data.getFluctuatingFhb()));
this.setPriceNetwork(String.format(digitFormat, data.getPriceNetwork()));
this.setFluctuatingNetwork(String.format(digitFormat, data.getFluctuatingNetwork()));
this.setPriceSurvey(String.format(digitFormat, data.getPriceSurvey()));
this.setFluctuatingSurvey(String.format(digitFormat, data.getFluctuatingSurvey()));
this.setPriceLastMonth(String.format(digitFormat, data.getPriceLastMonth()));
this.setPriceCalculate(String.format(digitFormat, data.getPriceCalculate()));
this.setPriceRecommend(String.format(digitFormat, data.getPriceRecommend()));
this.setFluctuatingRecommend(String.format(digitFormat, data.getFluctuatingRecommend()));
this.setMaterialId(data.getMaterialId()); this.setMaterialId(data.getMaterialId());
this.setName(data.getName()); this.setName(data.getName());
this.setYear(data.getYear()); this.setYear(data.getYear());
this.setMonth(data.getMonth()); this.setMonth(data.getMonth());
this.setPriceFtb(data.getPriceFtb().toString());
this.setFluctuatingFtb(data.getFluctuatingFtb().toString());
this.setPriceSs(data.getPriceSs().toString());
this.setFluctuatingSs(data.getFluctuatingSs().toString());
this.setPriceFhb(data.getPriceFhb().toString());
this.setFluctuatingFhb(data.getFluctuatingFhb().toString());
this.setPriceNetwork(data.getPriceNetwork().toString());
this.setFluctuatingNetwork(data.getFluctuatingNetwork().toString());
this.setPriceSurvey(data.getPriceSurvey().toString());
this.setFluctuatingSurvey(data.getFluctuatingSurvey().toString());
this.setPriceLastMonth(data.getPriceLastMonth().toString());
this.setPriceCalculate(data.getPriceCalculate().toString());
this.setPriceRecommend(data.getPriceRecommend().toString());
this.setFluctuatingRecommend(data.getFluctuatingRecommend().toString());
} }
} }

View File

@@ -1,5 +1,6 @@
package mjkf.xinke.main.service; package mjkf.xinke.main.service;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -13,16 +14,16 @@ import java.time.LocalDate;
public class PriceResultService extends ServiceImpl<BaseMapper<PriceResult>, PriceResult> { public class PriceResultService extends ServiceImpl<BaseMapper<PriceResult>, PriceResult> {
public LambdaQueryWrapper<PriceResult> getQuery(Integer year, Integer month, String materialId, String name) { public LambdaQueryWrapper<PriceResult> getQuery(Integer year, Integer month, String materialId, String name) {
var query = new LambdaQueryWrapper<PriceResult>(); var query = new LambdaQueryWrapper<PriceResult>();
if (year != null) { if (ObjectUtil.isNotEmpty(year)) {
query = query.eq(PriceResult::getYear, year); query = query.eq(PriceResult::getYear, year);
} }
if (month != null) { if (ObjectUtil.isNotEmpty(month)) {
query = query.eq(PriceResult::getMonth, month); query = query.eq(PriceResult::getMonth, month);
} }
if (materialId != null) { if (ObjectUtil.isNotEmpty(materialId)) {
query.eq(PriceResult::getMaterialId, materialId); query.eq(PriceResult::getMaterialId, materialId);
} }
if (name != null) { if (ObjectUtil.isNotEmpty(name)) {
query.like(PriceResult::getName, name); query.like(PriceResult::getName, name);
} }
return query; return query;

View File

@@ -0,0 +1,2 @@
ALTER TABLE PRICE_RESULT ADD DISPLAY_DIGIT int default 1 comment '显示小数位数';
ALTER TABLE PRICE_PUBLISH ADD DISPLAY_DIGIT int default 1 comment '显示小数位数';