feat(price-publish): 新增发布价格相关接口

This commit is contained in:
han0
2023-12-13 17:34:47 +08:00
parent f9dcbd62b0
commit b440dc604f
9 changed files with 409 additions and 0 deletions

View File

@@ -26,6 +26,9 @@ public enum HttpErrorResponseEnum implements NcHttpErrorResponseInterface {
PRICE_RESULT_YEAR_MONTH_NEEDED("缺少年份或月份", 1101, HttpStatus.SC_NOT_FOUND), PRICE_RESULT_YEAR_MONTH_NEEDED("缺少年份或月份", 1101, HttpStatus.SC_NOT_FOUND),
PRICE_RESULT_NOT_FOUND("未找到对应数据", 1102, HttpStatus.SC_NOT_FOUND), PRICE_RESULT_NOT_FOUND("未找到对应数据", 1102, HttpStatus.SC_NOT_FOUND),
PRICE_PUBLISH_YEAR_MONTH_NEEDED("缺少年份或月份", 1201, HttpStatus.SC_NOT_FOUND),
PRICE_PUBLISH_NOT_FOUND("未找到对应数据", 1202, HttpStatus.SC_NOT_FOUND),
; ;
private String message; private String message;

View File

@@ -0,0 +1,6 @@
package mjkf.xinke.main.constant;
public class PricePublishStatus {
public static final Integer WAITING = 0;
public static final Integer DONE = 2;
}

View File

@@ -0,0 +1,6 @@
package mjkf.xinke.main.constant;
public class PricePublishType {
public static final Integer CURRENT = 1; // 当月价
public static final Integer AVG = 2; // 近半年平均价
}

View File

@@ -129,6 +129,7 @@ public class MaterialController {
throw new NcHttpException(HttpErrorResponseEnum.MATERIAL_NOT_FOUND); throw new NcHttpException(HttpErrorResponseEnum.MATERIAL_NOT_FOUND);
} }
data.edit(params, user); data.edit(params, user);
materialService.updateById(data);
return FuHttpResponse.Builder().dataResponse(data).build(); return FuHttpResponse.Builder().dataResponse(data).build();
} }

View File

@@ -0,0 +1,92 @@
package mjkf.xinke.main.controller;
import com.jgy.xxs.core.http.exp.NcHttpException;
import com.jgy.xxs.core.http.resp.HttpResponse;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import mjkf.xinke.auth.core.util.StpLoginUserUtil;
import mjkf.xinke.main.common.http.FuHttpResponse;
import mjkf.xinke.main.constant.HttpErrorResponseEnum;
import mjkf.xinke.main.constant.PricePublishStatus;
import mjkf.xinke.main.model.db.PricePublish;
import mjkf.xinke.main.model.vo.PricePublishEditRequest;
import mjkf.xinke.main.service.PricePublishService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;
/**
* <p>
* 发布价格 前端控制器
* </p>
*
* @author han0
* @since 2023-11-09
*/
@RestController
@RequestMapping("/price-publish")
public class PricePublishController {
@Resource
PricePublishService pricePublishService;
@ApiOperation("获取发布价格数据列表")
@GetMapping("/")
public HttpResponse list(
@ApiParam("年份") @RequestParam("year") Integer year,
@ApiParam("月份") @RequestParam(value = "month") Integer month,
@ApiParam("材料编号") @RequestParam(value = "material_id", required = false) String materialId,
@ApiParam("名称") @RequestParam(value = "name", required = false) String name,
@ApiParam("规格") @RequestParam(value = "spec", required = false) String spec,
@ApiParam("类型") @RequestParam(value = "type") Integer type
) throws Exception {
if (year == null || month == null) {
throw new NcHttpException(HttpErrorResponseEnum.PRICE_PUBLISH_YEAR_MONTH_NEEDED);
}
var query = pricePublishService.getQuery(year, month, materialId, name, spec, type);
var result = pricePublishService.list(query);
return FuHttpResponse.Builder().dataResponse(result).build();
}
@ApiOperation("编辑发布价格数据")
@PutMapping("/{id}")
public HttpResponse edit(
@ApiParam("id") @PathParam("id") String id,
@ApiParam("参数") @RequestBody PricePublishEditRequest params
) throws Exception {
params.check();
var user = StpLoginUserUtil.getLoginUser();
var data = pricePublishService.getById(id);
if (data == null) {
throw new NcHttpException(HttpErrorResponseEnum.PRICE_PUBLISH_NOT_FOUND);
}
data.edit(params, user);
pricePublishService.updateById(data);
return FuHttpResponse.Builder().dataResponse(data).build();
}
@ApiOperation("发布价格")
@GetMapping("/")
public HttpResponse list(
@ApiParam("年份") @RequestParam("year") Integer year,
@ApiParam("月份") @RequestParam(value = "month") Integer month
) throws Exception {
if (year == null || month == null) {
throw new NcHttpException(HttpErrorResponseEnum.PRICE_PUBLISH_YEAR_MONTH_NEEDED);
}
var query = pricePublishService.getQuery(year, month, null, null, null, null);
List<PricePublish> result = pricePublishService.list(query);
for (PricePublish item: result) {
item.setStatus(PricePublishStatus.DONE);
pricePublishService.updateById(item);
}
return FuHttpResponse.Builder().dataResponse().build();
}
}

View File

@@ -0,0 +1,16 @@
package mjkf.xinke.main.dao;
import mjkf.xinke.main.model.db.PricePublish;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 发布价格 Mapper 接口
* </p>
*
* @author han0
* @since 2023-11-10
*/
public interface PricePublishMapper extends BaseMapper<PricePublish> {
}

View File

@@ -0,0 +1,202 @@
package mjkf.xinke.main.model.db;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import mjkf.xinke.auth.core.pojo.SaBaseLoginUser;
import mjkf.xinke.main.model.vo.PricePublishEditRequest;
/**
* <p>
* 发布价格
* </p>
*
* @author han0
* @since 2023-11-10
*/
@Getter
@Setter
@TableName("PRICE_PUBLISH")
@ApiModel(value = "PricePublish对象", description = "发布价格")
public class PricePublish extends Model<PricePublish> {
private static final long serialVersionUID = 1L;
@ApiModelProperty("最后更新人id")
@TableField("UPDATE_USER_ID")
private String updateUserId;
@ApiModelProperty("最后更新人名称")
@TableField("UPDATE_USER_NAME")
private String updateUserName;
@ApiModelProperty("最后更新时间")
@TableField("UPDATE_TIME")
private LocalDateTime updateTime;
@ApiModelProperty("创建人id")
@TableField("CREATE_USER_ID")
private String createUserId;
@ApiModelProperty("创建人名称")
@TableField("CREATE_USER_NAME")
private String createUserName;
@ApiModelProperty("创建时间")
@TableField("CREATE_TIME")
private LocalDateTime createTime;
@ApiModelProperty("删除人id")
@TableField("DELETE_USER_ID")
private String deleteUserId;
@ApiModelProperty("删除人名称")
@TableField("DELETE_USER_NAME")
private String deleteUserName;
@ApiModelProperty("删除时间")
@TableField("DELETE_TIME")
private LocalDateTime deleteTime;
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("编号")
@TableField("MATERIAL_ID")
private String materialId;
@ApiModelProperty("年份")
@TableField("YEAR")
private Integer year;
@ApiModelProperty("月份")
@TableField("MONTH")
private Integer month;
@ApiModelProperty("材料名称")
@TableField("`NAME`")
private String name;
@ApiModelProperty("规格")
@TableField("`SPEC`")
private String spec;
@ApiModelProperty("价格")
@TableField("PRICE")
private BigDecimal price;
@ApiModelProperty("福州价格")
@TableField("PRICE_FUZHOU")
private BigDecimal priceFuzhou;
@ApiModelProperty("厦门价格")
@TableField("PRICE_XIAMEN")
private BigDecimal priceXiamen;
@ApiModelProperty("莆田价格")
@TableField("PRICE_PUTIAN")
private BigDecimal pricePutian;
@ApiModelProperty("三明价格")
@TableField("PRICE_SANMING")
private BigDecimal priceSanming;
@ApiModelProperty("泉州价格")
@TableField("PRICE_QUANZHOU")
private BigDecimal priceQuanzhou;
@ApiModelProperty("漳州价格")
@TableField("PRICE_ZHANGZHOU")
private BigDecimal priceZhangzhou;
@ApiModelProperty("南平价格")
@TableField("PRICE_NANPIN")
private BigDecimal priceNanpin;
@ApiModelProperty("龙岩价格")
@TableField("PRICE_LONGYAN")
private BigDecimal priceLongyan;
@ApiModelProperty("宁德价格")
@TableField("PRICE_NINGDE")
private BigDecimal priceNingde;
@ApiModelProperty("平潭价格")
@TableField("PRICE_PINTAN")
private BigDecimal pricePintan;
@ApiModelProperty("税率")
@TableField("TAX")
private BigDecimal tax;
@ApiModelProperty("状态")
@TableField("STATUS")
private Integer status;
@ApiModelProperty("类型")
@TableField("TYPE")
private Integer type;
@Override
public Serializable pkVal() {
return this.id;
}
public void edit(PricePublishEditRequest params, SaBaseLoginUser user) {
if (params.getName() != null) {
this.setName(params.getName());
}
if (params.getSpec() != null) {
this.setSpec(params.getSpec());
}
if (params.getPrice() != null) {
this.setPrice(params.getPrice());
}
if (params.getPriceFuzhou() != null) {
this.setPriceFuzhou(params.getPriceFuzhou());
}
if (params.getPriceXiamen() != null) {
this.setPriceXiamen(params.getPriceXiamen());
}
if (params.getPricePutian() != null) {
this.setPricePutian(params.getPricePutian());
}
if (params.getPriceSanming() != null) {
this.setPriceSanming(params.getPriceSanming());
}
if (params.getPriceQuanzhou() != null) {
this.setPriceQuanzhou(params.getPriceQuanzhou());
}
if (params.getPriceZhangzhou() != null) {
this.setPriceZhangzhou(params.getPriceZhangzhou());
}
if (params.getPriceNanpin() != null) {
this.setPriceNanpin(params.getPriceNanpin());
}
if (params.getPriceLongyan() != null) {
this.setPriceLongyan(params.getPriceLongyan());
}
if (params.getPriceNingde() != null) {
this.setPriceNingde(params.getPriceNingde());
}
if (params.getPricePintan() != null) {
this.setPricePintan(params.getPricePintan());
}
if (params.getTax() != null) {
this.setTax(params.getTax());
}
this.updateTime = LocalDateTime.now();
this.updateUserName = user.getName();
this.updateUserId = user.getId();
}
}

View File

@@ -0,0 +1,51 @@
package mjkf.xinke.main.model.vo;
import lombok.Getter;
import lombok.Setter;
import java.math.BigDecimal;
@Getter
@Setter
public class PricePublishEditRequest {
// private String materialId;
// private String name;
// private Integer year;
// private Integer month;
private String name;
private String spec;
private BigDecimal price;
private BigDecimal priceFuzhou;
private BigDecimal priceXiamen;
private BigDecimal pricePutian;
private BigDecimal priceSanming;
private BigDecimal priceQuanzhou;
private BigDecimal priceZhangzhou;
private BigDecimal priceNanpin;
private BigDecimal priceLongyan;
private BigDecimal priceNingde;
private BigDecimal pricePintan;
private BigDecimal tax;
public void check() {
}
}

View File

@@ -0,0 +1,32 @@
package mjkf.xinke.main.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import mjkf.xinke.main.model.db.PricePublish;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
@Service
public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, PricePublish> {
public LambdaQueryWrapper getQuery(Integer year, Integer month, String materialId, String name, String spec, Integer type) {
var query = new LambdaQueryWrapper<PricePublish>();
if (year != null) {
query = query.eq(PricePublish::getYear, year);
}
if (month != null) {
query = query.eq(PricePublish::getMonth, month);
}
if (materialId != null) {
query.eq(PricePublish::getMaterialId, materialId);
}
if (name != null) {
query.like(PricePublish::getName, name);
}
if (type != null) {
query.eq(PricePublish::getType, type);
}
return query;
}
}