feat: 新增导出历史数据

This commit is contained in:
han0
2024-09-12 16:12:00 +08:00
parent 59347898b8
commit 0a0a31bed2
2 changed files with 80 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
package mjkf.xinke.main.controller; package mjkf.xinke.main.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.URLUtil;
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jgy.xxs.core.http.resp.HttpResponse; import com.jgy.xxs.core.http.resp.HttpResponse;
@@ -23,8 +25,13 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable; import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.stream.Collectors;
/** /**
* <p> * <p>
@@ -52,6 +59,7 @@ public class PublicController {
@ApiParam(value = "父id") @RequestParam(value="parent_id", required = false) String parentId @ApiParam(value = "父id") @RequestParam(value="parent_id", required = false) String parentId
) throws Exception { ) throws Exception {
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(year, month, null, name, spec, PricePublishType.CURRENT); LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(year, month, null, name, spec, PricePublishType.CURRENT);
query.eq(PricePublish::getStatus, PricePublishStatus.DONE);
query.isNotNull(PricePublish::getMaterialId); // 材料编号禁止为空 query.isNotNull(PricePublish::getMaterialId); // 材料编号禁止为空
if (keyword != null && ObjectUtil.isNotEmpty(keyword)) { if (keyword != null && ObjectUtil.isNotEmpty(keyword)) {
query.and(e -> e query.and(e -> e
@@ -93,9 +101,9 @@ public class PublicController {
@Resource @Resource
DevFileService devFileService; DevFileService devFileService;
@ApiOperation("历史文件") @ApiOperation("历史文件列表")
@GetMapping("/history-file") @GetMapping("/history")
public HttpResponse historyFile () throws Exception { public HttpResponse listHistoryFile () throws Exception {
var query = new LambdaQueryWrapper<DevFile>(); var query = new LambdaQueryWrapper<DevFile>();
query.like(DevFile::getExtJson, "is_history_file"); query.like(DevFile::getExtJson, "is_history_file");
query.orderByDesc(DevFile::getName); query.orderByDesc(DevFile::getName);
@@ -103,6 +111,38 @@ public class PublicController {
return FuHttpResponse.Builder().dataResponse(result.getRecords()).build(); return FuHttpResponse.Builder().dataResponse(result.getRecords()).build();
} }
@Data
class HistoryFileParam {
@ApiModelProperty(value = "")
@NotEmpty(message="年不能为空")
private String year;
@ApiModelProperty(value = "")
@NotEmpty(message="月不能为空")
private String month;
}
@ApiOperation("历史文件")
@GetMapping("/history/file")
public void getHistoryFile (
@Valid HistoryFileParam param,
HttpServletResponse response
) throws Exception {
var query = new LambdaQueryWrapper<PricePublish>();
query.eq(PricePublish::getYear, param.getYear());
query.eq(PricePublish::getMonth, param.getMonth());
query.eq(PricePublish::getType, PricePublishType.CURRENT);
query.eq(PricePublish::getStatus, PricePublishStatus.DONE);
query.orderByAsc(PricePublish::getMaterialId);
var result = pricePublishService.list(query);
result = result.stream().filter(i->ObjectUtil.isNotEmpty(i.getMaterialId())).collect(Collectors.toList());
String filename = URLUtil.encode("历史文件", StandardCharsets.UTF_8) + ".xlsx";
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + filename);
response.setHeader("filename", filename);
EasyExcel.write(response.getOutputStream(), PricePublish.class).sheet("sheet1").doWrite(result);
}
@Data @Data
static public class PublicUpdateInfo implements Serializable { static public class PublicUpdateInfo implements Serializable {
@ApiModelProperty("日期") @ApiModelProperty("日期")

View File

@@ -1,5 +1,8 @@
package mjkf.xinke.main.model.db; package mjkf.xinke.main.model.db;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
@@ -33,125 +36,159 @@ public class PricePublish extends Model<PricePublish> {
@ApiModelProperty("最后更新人id") @ApiModelProperty("最后更新人id")
@TableField("UPDATE_USER_ID") @TableField("UPDATE_USER_ID")
@ExcelIgnore
private String updateUserId; private String updateUserId;
@ApiModelProperty("最后更新人名称") @ApiModelProperty("最后更新人名称")
@TableField("UPDATE_USER_NAME") @TableField("UPDATE_USER_NAME")
@ExcelIgnore
private String updateUserName; private String updateUserName;
@ApiModelProperty("最后更新时间") @ApiModelProperty("最后更新时间")
@TableField("UPDATE_TIME") @TableField("UPDATE_TIME")
@ExcelIgnore
private LocalDateTime updateTime; private LocalDateTime updateTime;
@ApiModelProperty("创建人id") @ApiModelProperty("创建人id")
@TableField("CREATE_USER_ID") @TableField("CREATE_USER_ID")
@ExcelIgnore
private String createUserId; private String createUserId;
@ApiModelProperty("创建人名称") @ApiModelProperty("创建人名称")
@TableField("CREATE_USER_NAME") @TableField("CREATE_USER_NAME")
@ExcelIgnore
private String createUserName; private String createUserName;
@ApiModelProperty("创建时间") @ApiModelProperty("创建时间")
@TableField("CREATE_TIME") @TableField("CREATE_TIME")
@ExcelIgnore
private LocalDateTime createTime; private LocalDateTime createTime;
@ApiModelProperty("删除人id") @ApiModelProperty("删除人id")
@TableField("DELETE_USER_ID") @TableField("DELETE_USER_ID")
@ExcelIgnore
private String deleteUserId; private String deleteUserId;
@ApiModelProperty("删除人名称") @ApiModelProperty("删除人名称")
@TableField("DELETE_USER_NAME") @TableField("DELETE_USER_NAME")
@ExcelIgnore
private String deleteUserName; private String deleteUserName;
@ApiModelProperty("删除时间") @ApiModelProperty("删除时间")
@TableField("DELETE_TIME") @TableField("DELETE_TIME")
@ExcelIgnore
private LocalDateTime deleteTime; private LocalDateTime deleteTime;
@TableId(value = "ID", type = IdType.AUTO) @TableId(value = "ID", type = IdType.AUTO)
@ExcelIgnore
private Integer id; private Integer id;
@ApiModelProperty("编号") @ApiModelProperty("编号")
@TableField("MATERIAL_ID") @TableField("MATERIAL_ID")
@ExcelProperty({"材料代码"})
@ColumnWidth(15)
private String materialId; private String materialId;
@ApiModelProperty("年份") @ApiModelProperty("年份")
@TableField("YEAR") @TableField("YEAR")
@ExcelIgnore
private Integer year; private Integer year;
@ApiModelProperty("月份") @ApiModelProperty("月份")
@TableField("MONTH") @TableField("MONTH")
@ExcelIgnore
private Integer month; private Integer month;
@ApiModelProperty("材料名称") @ApiModelProperty("材料名称")
@TableField("`NAME`") @TableField("`NAME`")
@ExcelProperty({"材料名称"})
@ColumnWidth(20)
private String name; private String name;
@ApiModelProperty("规格") @ApiModelProperty("规格")
@TableField("`SPEC`") @TableField("`SPEC`")
@ExcelProperty({"规格"})
@ColumnWidth(35)
private String spec; private String spec;
@ApiModelProperty("价格") @ApiModelProperty("价格")
@TableField("PRICE") @TableField("PRICE")
@ExcelIgnore
private BigDecimal price; private BigDecimal price;
@ApiModelProperty("福州价格") @ApiModelProperty("福州价格")
@TableField("PRICE_FUZHOU") @TableField("PRICE_FUZHOU")
@ExcelProperty({"福州"})
private BigDecimal priceFuzhou; private BigDecimal priceFuzhou;
@ApiModelProperty("厦门价格") @ApiModelProperty("厦门价格")
@TableField("PRICE_XIAMEN") @TableField("PRICE_XIAMEN")
@ExcelProperty({"厦门"})
private BigDecimal priceXiamen; private BigDecimal priceXiamen;
@ApiModelProperty("莆田价格") @ApiModelProperty("莆田价格")
@TableField("PRICE_PUTIAN") @TableField("PRICE_PUTIAN")
@ExcelProperty({"莆田"})
private BigDecimal pricePutian; private BigDecimal pricePutian;
@ApiModelProperty("三明价格") @ApiModelProperty("三明价格")
@TableField("PRICE_SANMING") @TableField("PRICE_SANMING")
@ExcelProperty({"三明"})
private BigDecimal priceSanming; private BigDecimal priceSanming;
@ApiModelProperty("泉州价格") @ApiModelProperty("泉州价格")
@TableField("PRICE_QUANZHOU") @TableField("PRICE_QUANZHOU")
@ExcelProperty({"泉州"})
private BigDecimal priceQuanzhou; private BigDecimal priceQuanzhou;
@ApiModelProperty("漳州价格") @ApiModelProperty("漳州价格")
@TableField("PRICE_ZHANGZHOU") @TableField("PRICE_ZHANGZHOU")
@ExcelProperty({"漳州"})
private BigDecimal priceZhangzhou; private BigDecimal priceZhangzhou;
@ApiModelProperty("南平价格") @ApiModelProperty("南平价格")
@TableField("PRICE_NANPIN") @TableField("PRICE_NANPIN")
@ExcelProperty({"南平"})
private BigDecimal priceNanpin; private BigDecimal priceNanpin;
@ApiModelProperty("龙岩价格") @ApiModelProperty("龙岩价格")
@TableField("PRICE_LONGYAN") @TableField("PRICE_LONGYAN")
@ExcelProperty({"龙岩"})
private BigDecimal priceLongyan; private BigDecimal priceLongyan;
@ApiModelProperty("宁德价格") @ApiModelProperty("宁德价格")
@TableField("PRICE_NINGDE") @TableField("PRICE_NINGDE")
@ExcelProperty({"宁德"})
private BigDecimal priceNingde; private BigDecimal priceNingde;
@ApiModelProperty("平潭价格") @ApiModelProperty("平潭价格")
@TableField("PRICE_PINTAN") @TableField("PRICE_PINTAN")
@ExcelProperty({"平潭"})
private BigDecimal pricePintan; private BigDecimal pricePintan;
@ApiModelProperty("漳州开发区价格") @ApiModelProperty("漳州开发区价格")
@TableField("PRICE_ZHANGZHOUKFQ") @TableField("PRICE_ZHANGZHOUKFQ")
@ExcelProperty({"漳州开发区"})
private BigDecimal priceZhangzhouKfq; private BigDecimal priceZhangzhouKfq;
@ApiModelProperty("税率") @ApiModelProperty("税率")
@TableField("TAX") @TableField("TAX")
@ExcelIgnore
private BigDecimal tax; private BigDecimal tax;
@ApiModelProperty("状态") @ApiModelProperty("状态")
@TableField("STATUS") @TableField("STATUS")
@ExcelIgnore
private Integer status; private Integer status;
@ApiModelProperty("类型") @ApiModelProperty("类型")
@TableField("TYPE") @TableField("TYPE")
@ExcelIgnore
private Integer type; private Integer type;
@ApiModelProperty("单位") @ApiModelProperty("单位")
@TableField("UNIT") @TableField("UNIT")
@ExcelProperty(value={"单位"}, index=3)
private String unit; private String unit;
@Override @Override