feat(public): 新增公众网站相关接口
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package mjkf.xinke.main.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jgy.xxs.core.http.resp.HttpResponse;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import mjkf.xinke.main.common.http.FuHttpResponse;
|
||||
import mjkf.xinke.main.constant.PricePublishType;
|
||||
import mjkf.xinke.main.model.db.PricePublish;
|
||||
import mjkf.xinke.main.model.vo.PublicResponse;
|
||||
import mjkf.xinke.main.model.vo.PublicTrendResponse;
|
||||
import mjkf.xinke.main.service.PricePublishService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 公众网站 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author han0
|
||||
* @since 2023-12-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/public")
|
||||
public class PublicController {
|
||||
@Resource
|
||||
PricePublishService pricePublishService;
|
||||
|
||||
@ApiOperation("查询")
|
||||
@GetMapping("/")
|
||||
public HttpResponse list (
|
||||
@ApiParam(value = "地区") @RequestParam(value="region") String region,
|
||||
@ApiParam(value = "年份") @RequestParam(value="year") Integer year,
|
||||
@ApiParam(value = "月份") @RequestParam(value="month") Integer month,
|
||||
@ApiParam(value = "关键字") @RequestParam(value="keyword", required = false) String keyword,
|
||||
@ApiParam(value = "名称") @RequestParam(value="name", required = false) String name,
|
||||
@ApiParam(value = "规格") @RequestParam(value="spec", required = false) String spec
|
||||
) throws Exception {
|
||||
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(year, month, null, name, spec, PricePublishType.CURRENT);
|
||||
if (keyword != null && ObjectUtil.isNotEmpty(keyword)) {
|
||||
query.and(e -> e
|
||||
.like(PricePublish::getName, keyword).or()
|
||||
.like(PricePublish::getSpec, keyword)
|
||||
);
|
||||
}
|
||||
var currentData = pricePublishService.list(query);
|
||||
|
||||
LambdaQueryWrapper<PricePublish> queryPrevious = pricePublishService.getQuery(year - 1, month, null, name, spec, PricePublishType.CURRENT);
|
||||
var previousData = pricePublishService.list(queryPrevious);
|
||||
|
||||
// 计算同比, 组合
|
||||
var result = PublicResponse.list(currentData, previousData, region);
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
}
|
||||
|
||||
@ApiOperation("走势")
|
||||
@GetMapping("/{materialId}/trend")
|
||||
public HttpResponse trend (
|
||||
@ApiParam(value = "地区") @RequestParam(value="region") String region,
|
||||
@ApiParam(value = "材料id") @RequestParam(value="materialId") String materialId
|
||||
) throws Exception {
|
||||
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(null, null, materialId, null, null, PricePublishType.CURRENT);
|
||||
var data = pricePublishService.list(query);
|
||||
|
||||
var result = PublicTrendResponse.list(data, region);
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
}
|
||||
}
|
@@ -199,4 +199,29 @@ public class PricePublish extends Model<PricePublish> {
|
||||
this.updateUserName = user.getName();
|
||||
this.updateUserId = user.getId();
|
||||
}
|
||||
|
||||
public BigDecimal getRegionPrice(String region) {
|
||||
if (region.contains("福州")) {
|
||||
return this.priceFuzhou;
|
||||
} else if (region.contains("厦门")) {
|
||||
return this.priceXiamen;
|
||||
} else if (region.contains("莆田")) {
|
||||
return this.pricePutian;
|
||||
} else if (region.contains("三明")) {
|
||||
return this.priceSanming;
|
||||
} else if (region.contains("泉州")) {
|
||||
return this.priceQuanzhou;
|
||||
} else if (region.contains("漳州")) {
|
||||
return this.priceZhangzhou;
|
||||
} else if (region.contains("南平")) {
|
||||
return this.priceNanpin;
|
||||
} else if (region.contains("龙岩")) {
|
||||
return this.priceLongyan;
|
||||
} else if (region.contains("宁德")) {
|
||||
return this.priceNingde;
|
||||
} else if (region.contains("平潭")) {
|
||||
return this.pricePintan;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
105
src/main/java/mjkf/xinke/main/model/vo/PublicResponse.java
Normal file
105
src/main/java/mjkf/xinke/main/model/vo/PublicResponse.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package mjkf.xinke.main.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mjkf.xinke.main.model.db.PricePublish;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 计算结果
|
||||
* </p>
|
||||
*
|
||||
* @author han0
|
||||
* @since 2023-11-10
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ApiModel(value = "PublicResponse对象", description = "计算结果")
|
||||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
|
||||
public class PublicResponse {
|
||||
private String updateUserId;
|
||||
|
||||
private String updateUserName;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String createUserName;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String deleteUserId;
|
||||
|
||||
private String deleteUserName;
|
||||
|
||||
private LocalDateTime deleteTime;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String materialId;
|
||||
|
||||
private Integer year;
|
||||
|
||||
private Integer month;
|
||||
|
||||
private String name;
|
||||
|
||||
private String spec;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private BigDecimal tax;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Float yoy;
|
||||
|
||||
static public List<PublicResponse> list(List<PricePublish> currentData, List<PricePublish> previousData, String region) {
|
||||
var previousPriceMap = previousData.stream().collect(Collectors.toMap(PricePublish::getMaterialId, item -> item.getRegionPrice(region)));
|
||||
var result = currentData.stream().map(item -> new PublicResponse(item, previousPriceMap, region)).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
public PublicResponse(PricePublish item, Map<String, BigDecimal> previousPriceMap, String region) {
|
||||
this.updateUserId = item.getUpdateUserId();
|
||||
this.updateUserName = item.getUpdateUserName();
|
||||
this.updateTime = item.getUpdateTime();
|
||||
this.createUserId = item.getCreateUserId();
|
||||
this.createUserName = item.getCreateUserName();
|
||||
this.createTime = item.getCreateTime();
|
||||
this.deleteUserId = item.getDeleteUserId();
|
||||
this.deleteUserName = item.getDeleteUserName();
|
||||
this.deleteTime = item.getDeleteTime();
|
||||
this.id = item.getId();
|
||||
this.materialId = item.getMaterialId();
|
||||
this.year = item.getYear();
|
||||
this.month = item.getMonth();
|
||||
this.name = item.getName();
|
||||
this.spec = item.getSpec();
|
||||
this.tax = item.getTax();
|
||||
this.status = item.getStatus();
|
||||
this.type = item.getType();
|
||||
|
||||
this.price = item.getRegionPrice(region);
|
||||
|
||||
var previousPrice = previousPriceMap.getOrDefault(this.materialId, BigDecimal.valueOf(0));
|
||||
if (previousPrice.intValue() == 0) {
|
||||
this.yoy = 0f;
|
||||
} else {
|
||||
this.yoy = (this.price.floatValue() - previousPrice.floatValue()) / previousPrice.floatValue();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
package mjkf.xinke.main.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonNaming;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mjkf.xinke.main.model.db.PricePublish;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 计算结果
|
||||
* </p>
|
||||
*
|
||||
* @author han0
|
||||
* @since 2023-11-10
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ApiModel(value = "PublicResponse对象", description = "计算结果")
|
||||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
|
||||
public class PublicTrendResponse {
|
||||
private String updateUserId;
|
||||
|
||||
private String updateUserName;
|
||||
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
private String createUserId;
|
||||
|
||||
private String createUserName;
|
||||
|
||||
private LocalDateTime createTime;
|
||||
|
||||
private String deleteUserId;
|
||||
|
||||
private String deleteUserName;
|
||||
|
||||
private LocalDateTime deleteTime;
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String materialId;
|
||||
|
||||
private Integer year;
|
||||
|
||||
private Integer month;
|
||||
|
||||
private String name;
|
||||
|
||||
private String spec;
|
||||
|
||||
private BigDecimal price;
|
||||
|
||||
private BigDecimal tax;
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Integer type;
|
||||
|
||||
static public List<PublicTrendResponse> list(List<PricePublish> data, String region) {
|
||||
var result = data.stream().map(item -> new PublicTrendResponse(item, region)).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
public PublicTrendResponse(PricePublish item, String region) {
|
||||
this.updateUserId = item.getUpdateUserId();
|
||||
this.updateUserName = item.getUpdateUserName();
|
||||
this.updateTime = item.getUpdateTime();
|
||||
this.createUserId = item.getCreateUserId();
|
||||
this.createUserName = item.getCreateUserName();
|
||||
this.createTime = item.getCreateTime();
|
||||
this.deleteUserId = item.getDeleteUserId();
|
||||
this.deleteUserName = item.getDeleteUserName();
|
||||
this.deleteTime = item.getDeleteTime();
|
||||
this.id = item.getId();
|
||||
this.materialId = item.getMaterialId();
|
||||
this.year = item.getYear();
|
||||
this.month = item.getMonth();
|
||||
this.name = item.getName();
|
||||
this.spec = item.getSpec();
|
||||
this.tax = item.getTax();
|
||||
this.status = item.getStatus();
|
||||
this.type = item.getType();
|
||||
|
||||
this.price = item.getRegionPrice(region);
|
||||
}
|
||||
}
|
@@ -31,6 +31,9 @@ public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, P
|
||||
if (type != null) {
|
||||
query.eq(PricePublish::getType, type);
|
||||
}
|
||||
if (spec != null) {
|
||||
query.eq(PricePublish::getSpec, spec);
|
||||
}
|
||||
return query;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user