feat: 新增指定月份无数据时选用最新数据
This commit is contained in:
@@ -48,7 +48,10 @@ public class LocalMaterialController {
|
||||
@ApiParam(value = "规格") @RequestParam(value="spec", required=false) String spec,
|
||||
@ApiParam(value = "名称") @RequestParam(value="name", required=false) String name
|
||||
) {
|
||||
var query = localMaterialService.getQuery(year, month, city, county, spec, name, null);
|
||||
// 指定月份无数据时选用最新数据
|
||||
var date = localMaterialService.checkDate(year, month);
|
||||
|
||||
var query = localMaterialService.getQuery(date.getYear(), date.getMonth().getValue(), city, county, spec, name, null);
|
||||
query.orderByDesc(LocalMaterial::getName);
|
||||
List<LocalMaterial> data = localMaterialService.list(query);
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
package mjkf.xinke.main.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import mjkf.xinke.main.model.db.LocalMaterial;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
@@ -10,6 +11,27 @@ import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LocalMaterialService extends DataService<BaseMapper<LocalMaterial>, LocalMaterial> {
|
||||
/**
|
||||
* 获取指定月份前含数据的最新日期
|
||||
* @param year
|
||||
* @param month
|
||||
* @return
|
||||
*/
|
||||
public LocalDate checkDate(Integer year, Integer month) {
|
||||
LambdaQueryWrapper<LocalMaterial> query = new LambdaQueryWrapper<>();
|
||||
var startDate = LocalDate.of(year, month, 1);
|
||||
var endDate = startDate.plusMonths(1);
|
||||
query.lt(LocalMaterial::getDate, endDate);
|
||||
query.orderByDesc(LocalMaterial::getDate);
|
||||
var result = (LocalMaterial)this.getOne(query, false);
|
||||
if (ObjectUtil.isEmpty(result)) {
|
||||
return LocalDate.of(year, month, 1);
|
||||
} else {
|
||||
return result.getDate();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public LambdaQueryWrapper<LocalMaterial> indexQuery(LocalMaterial data) {
|
||||
LambdaQueryWrapper<LocalMaterial> query = new LambdaQueryWrapper<>();
|
||||
query.eq(LocalMaterial::getName, data.getName());
|
||||
|
Reference in New Issue
Block a user