feat: 新增材料管理排序字段
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -169,6 +169,11 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@@ -54,7 +54,6 @@ public class PricePublishController {
|
||||
}
|
||||
|
||||
var query = pricePublishService.getQuery(year, month, materialId, name, spec, type);
|
||||
query.orderByAsc(PricePublish::getMaterialId);
|
||||
var result = pricePublishService.list(query);
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
|
@@ -7,9 +7,6 @@ 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 lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mjkf.xinke.common.annotation.CommonLog;
|
||||
import mjkf.xinke.main.common.api.DataToolService;
|
||||
import mjkf.xinke.main.common.http.FuHttpResponse;
|
||||
@@ -52,7 +49,6 @@ public class PriceResultController {
|
||||
throw new NcHttpException(HttpErrorResponseEnum.PRICE_RESULT_YEAR_MONTH_NEEDED);
|
||||
}
|
||||
var query = priceResultService.getQuery(year, month, materialId, name);
|
||||
query.orderByAsc(PriceResult::getMaterialId);
|
||||
var result = priceResultService.list(query);
|
||||
|
||||
return FuHttpResponse.Builder().dataResponse(result).build();
|
||||
|
@@ -7,6 +7,7 @@ import com.alibaba.excel.EasyExcel;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.jgy.xxs.core.http.resp.HttpResponse;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@@ -66,7 +67,7 @@ public class PublicController {
|
||||
@ApiParam(value = "规格") @RequestParam(value="spec", required = false) String spec,
|
||||
@ApiParam(value = "父id") @RequestParam(value="parent_id", required = false) String parentId
|
||||
) throws Exception {
|
||||
LambdaQueryWrapper<PricePublish> query = pricePublishService.getQuery(year, month, null, name, spec, PricePublishType.CURRENT);
|
||||
MPJLambdaWrapper<PricePublish> query = pricePublishService.getQuery(year, month, null, name, spec, PricePublishType.CURRENT);
|
||||
query.eq(PricePublish::getStatus, PricePublishStatus.DONE);
|
||||
query.isNotNull(PricePublish::getMaterialId); // 材料编号禁止为空
|
||||
if (keyword != null && ObjectUtil.isNotEmpty(keyword)) {
|
||||
@@ -103,7 +104,7 @@ public class PublicController {
|
||||
@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);
|
||||
MPJLambdaWrapper<PricePublish> query = pricePublishService.getQuery(null, null, materialId, null, null, PricePublishType.CURRENT);
|
||||
var data = pricePublishService.list(query);
|
||||
|
||||
var result = PublicTrendResponse.list(data, region);
|
||||
|
@@ -123,11 +123,33 @@ public class Material extends Model<Material> {
|
||||
@TableField("`IS_TREE`")
|
||||
private Integer isTree;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
@TableField("SORT")
|
||||
private Integer sort;
|
||||
|
||||
@ApiModelProperty("材料编码")
|
||||
@TableField("CODE")
|
||||
private String code;
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
private String buildCode(String category1, String category2, String category3, String category4) {
|
||||
if (category1 == null || category2 == null || category3 == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder code = new StringBuilder();
|
||||
code.append(category1)
|
||||
.append(category2)
|
||||
.append(category3);
|
||||
if (category4 != null) {
|
||||
code.append(category4);
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
|
||||
public boolean isBuiltin() {
|
||||
if (this.isBuiltin == null) {
|
||||
return false;
|
||||
@@ -149,6 +171,8 @@ public class Material extends Model<Material> {
|
||||
this.spec = params.getSpec();
|
||||
this.tax = params.getTax();
|
||||
this.type = params.getType();
|
||||
this.sort = params.getSort();
|
||||
this.code = buildCode(category1, category2, category3, category4);
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.createTime = LocalDateTime.now();
|
||||
this.createUserName = user.getName();
|
||||
@@ -165,6 +189,8 @@ public class Material extends Model<Material> {
|
||||
this.spec = params.getSpec();
|
||||
this.tax = params.getTax();
|
||||
this.type = params.getType();
|
||||
this.sort = params.getSort();
|
||||
this.code = buildCode(category1, category2, category3, category4);
|
||||
this.updateTime = LocalDateTime.now();
|
||||
this.updateUserName = user.getName();
|
||||
this.updateUserId = user.getId();
|
||||
|
@@ -36,6 +36,9 @@ public class MaterialCreateRequest {
|
||||
@ApiModelProperty("类型")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
public void check() throws Exception {
|
||||
if (ObjectUtil.isEmpty(category1) || category1.chars().count() != 2) {
|
||||
throw new NcHttpException(HttpErrorResponseEnum.MATERIAL_CATEGORY_INVALID);
|
||||
|
@@ -33,6 +33,8 @@ public class MaterialEditRequest {
|
||||
@ApiModelProperty("类型")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty("排序")
|
||||
private Integer sort;
|
||||
|
||||
public void check() throws Exception{
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
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 com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import mjkf.xinke.main.model.db.Material;
|
||||
import mjkf.xinke.main.model.db.PricePublish;
|
||||
import mjkf.xinke.main.model.vo.BudgetCreateRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -16,13 +18,16 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, PricePublish> {
|
||||
|
||||
public LambdaQueryWrapper<PricePublish> getQuery(Integer year, Integer month, String materialId, String name, String spec, Integer type) {
|
||||
var query = new LambdaQueryWrapper<PricePublish>();
|
||||
public MPJLambdaWrapper<PricePublish> getQuery(Integer year, Integer month, String materialId, String name, String spec, Integer type) {
|
||||
var query = new MPJLambdaWrapper<PricePublish>()
|
||||
.selectAll(PricePublish.class)
|
||||
.leftJoin(Material.class, Material::getId, PricePublish::getMaterialId);
|
||||
|
||||
if (year != null) {
|
||||
query = query.eq(PricePublish::getYear, year);
|
||||
query.eq(PricePublish::getYear, year);
|
||||
}
|
||||
if (month != null) {
|
||||
query = query.eq(PricePublish::getMonth, month);
|
||||
query.eq(PricePublish::getMonth, month);
|
||||
}
|
||||
if (materialId != null) {
|
||||
query.eq(PricePublish::getMaterialId, materialId);
|
||||
@@ -36,19 +41,21 @@ public class PricePublishService extends ServiceImpl<BaseMapper<PricePublish>, P
|
||||
if (spec != null) {
|
||||
query.eq(PricePublish::getSpec, spec);
|
||||
}
|
||||
|
||||
query.orderByDesc(Material::getSort);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper getQuery(BudgetCreateRequest params) {
|
||||
var query = new LambdaQueryWrapper<PricePublish>();
|
||||
public MPJLambdaWrapper<PricePublish> getQuery(BudgetCreateRequest params) {
|
||||
var query = new MPJLambdaWrapper<PricePublish>();
|
||||
query.eq(PricePublish::getYear, params.getYear());
|
||||
query.in(PricePublish::getMonth, List.of(params.getMonth(), params.getBaseMonth()));
|
||||
query.in(PricePublish::getName, params.getItems().stream().map(item -> item.getName()).collect(Collectors.toList()));
|
||||
// query.in(PricePublish::getMaterialId, params.getItems().stream().map(item -> item.getId()).collect(Collectors.toList()));
|
||||
return query;
|
||||
}
|
||||
|
||||
public Map<String, Double> getPriceMapEntryByMaterialIdAndMonth(LambdaQueryWrapper<PricePublish> query) {
|
||||
public Map<String, Double> getPriceMapEntryByMaterialIdAndMonth(MPJLambdaWrapper<PricePublish> query) {
|
||||
var result = new HashMap<String, Double>();
|
||||
var items = this.list(query);
|
||||
for (PricePublish item: items) {
|
||||
|
@@ -1,43 +1,49 @@
|
||||
package mjkf.xinke.main.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import mjkf.xinke.main.model.db.Material;
|
||||
import mjkf.xinke.main.model.db.PriceResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
@Service
|
||||
public class PriceResultService extends ServiceImpl<BaseMapper<PriceResult>, PriceResult> {
|
||||
public LambdaQueryWrapper<PriceResult> getQuery(Integer year, Integer month, String materialId, String name) {
|
||||
var query = new LambdaQueryWrapper<PriceResult>();
|
||||
if (ObjectUtil.isNotEmpty(year)) {
|
||||
query = query.eq(PriceResult::getYear, year);
|
||||
|
||||
public MPJLambdaWrapper<PriceResult> getQuery(Integer year, Integer month, String materialId, String name) {
|
||||
var query = new MPJLambdaWrapper<PriceResult>()
|
||||
.selectAll(PriceResult.class)
|
||||
.leftJoin(Material.class, Material::getId, PriceResult::getMaterialId);
|
||||
|
||||
if (year != null) {
|
||||
query.eq(PriceResult::getYear, year);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(month)) {
|
||||
query = query.eq(PriceResult::getMonth, month);
|
||||
if (month != null) {
|
||||
query.eq(PriceResult::getMonth, month);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(materialId)) {
|
||||
if (materialId != null) {
|
||||
query.eq(PriceResult::getMaterialId, materialId);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(name)) {
|
||||
if (name != null) {
|
||||
query.like(PriceResult::getName, name);
|
||||
}
|
||||
|
||||
query.orderByDesc(Material::getSort);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper<PriceResult> getQueryByName(String name) {
|
||||
public MPJLambdaWrapper<PriceResult> getQueryByName(String name) {
|
||||
return this.getQuery(null, null, null, name);
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper<PriceResult> getQueryByMaterialId(String materialId) {
|
||||
public MPJLambdaWrapper<PriceResult> getQueryByMaterialId(String materialId) {
|
||||
return this.getQuery(null, null, materialId, null);
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper<PriceResult> queryLastYear (LambdaQueryWrapper<PriceResult> query, PriceResult data) {
|
||||
public MPJLambdaWrapper<PriceResult> queryLastYear(MPJLambdaWrapper<PriceResult> query, PriceResult data) {
|
||||
var endDate = LocalDate.of(data.getYear(), data.getMonth(), 1);
|
||||
var startDate = endDate.minusYears(1);
|
||||
// 过去一年
|
||||
@@ -51,7 +57,7 @@ public class PriceResultService extends ServiceImpl<BaseMapper<PriceResult>, Pri
|
||||
return query;
|
||||
}
|
||||
|
||||
public LambdaQueryWrapper<PriceResult> queryLastYear (LambdaQueryWrapper<PriceResult> query) {
|
||||
public MPJLambdaWrapper<PriceResult> queryLastYear(MPJLambdaWrapper<PriceResult> query) {
|
||||
var endDate = LocalDate.now().minusMonths(1);
|
||||
var startDate = endDate.minusYears(1);
|
||||
// 过去一年
|
||||
|
Reference in New Issue
Block a user