接口优化

This commit is contained in:
dzl 2025-05-06 17:09:36 +08:00
parent a1b78c0aeb
commit 78507c428e
2 changed files with 33 additions and 33 deletions

View File

@ -1,20 +1,20 @@
package com.cdzy.ebikeoperate.service.impl;
import com.cdzy.ebikeoperate.mapper.EbikeComponentEnterRecordsMapper;
import com.cdzy.ebikeoperate.model.dto.request.ReqEbikeComponentEnterRecordsDto;
import com.cdzy.ebikeoperate.model.dto.response.EbikeComponentEnterRecordsDto;
import com.cdzy.ebikeoperate.model.pojo.EbikeComponentEnterRecords;
import com.cdzy.ebikeoperate.service.EbikeComponentEnterRecordsService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cdzy.ebikeoperate.model.pojo.EbikeComponentEnterRecords;
import com.cdzy.ebikeoperate.mapper.EbikeComponentEnterRecordsMapper;
import com.cdzy.ebikeoperate.service.EbikeComponentEnterRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeComponentEnterRecordsTableDef.EBIKE_COMPONENT_ENTER_RECORDS;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeComponentTypeInfoTableDef.EBIKE_COMPONENT_TYPE_INFO;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeRegionTableDef.EBIKE_REGION;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeOperationRegionTableDef.EBIKE_OPERATION_REGION;
/**
* 部件入库记录 服务层实现
@ -23,7 +23,7 @@ import static com.cdzy.ebikeoperate.model.pojo.table.EbikeRegionTableDef.EBIKE_R
* @since 2025-03-25
*/
@Service
public class EbikeComponentEnterRecordsServiceImpl extends ServiceImpl<EbikeComponentEnterRecordsMapper, EbikeComponentEnterRecords> implements EbikeComponentEnterRecordsService{
public class EbikeComponentEnterRecordsServiceImpl extends ServiceImpl<EbikeComponentEnterRecordsMapper, EbikeComponentEnterRecords> implements EbikeComponentEnterRecordsService {
@Autowired
private EbikeComponentEnterRecordsMapper ebikeComponentEnterRecordsMapper;
@ -35,31 +35,31 @@ public class EbikeComponentEnterRecordsServiceImpl extends ServiceImpl<EbikeComp
, EBIKE_COMPONENT_ENTER_RECORDS.COMPONENT_PRICE, EBIKE_COMPONENT_ENTER_RECORDS.STATE, EBIKE_COMPONENT_ENTER_RECORDS.CREATED_USER
, EBIKE_COMPONENT_ENTER_RECORDS.CREATED_AT, EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_USER, EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_AT);
// 翻译所属区域
query.select(EBIKE_REGION.REGION_NAME.as("owning_region"));
query.select(EBIKE_OPERATION_REGION.OPERATION_REGION_NAME.as("owning_region"));
// 翻译部件类型
query.select(EBIKE_COMPONENT_TYPE_INFO.NAME.as("type_name"),
EBIKE_COMPONENT_TYPE_INFO.BRAND.as("type_brand"),
EBIKE_COMPONENT_TYPE_INFO.COVER.as("type_cover"));
query.leftJoin(EBIKE_REGION).on(EBIKE_COMPONENT_ENTER_RECORDS.OWNING_REGION.eq(EBIKE_REGION.REGION_ID));
query.leftJoin(EBIKE_OPERATION_REGION).on(EBIKE_COMPONENT_ENTER_RECORDS.OWNING_REGION.eq(EBIKE_OPERATION_REGION.OPERATION_REGION_ID));
query.leftJoin(EBIKE_COMPONENT_TYPE_INFO).on(EBIKE_COMPONENT_ENTER_RECORDS.COMPONENT_TYPE.eq(EBIKE_COMPONENT_TYPE_INFO.ID));
String region = reqEbikeComponentEnterRecordsDto.getRegion();
if(region!=null&&!region.isEmpty())
if (region != null && !region.isEmpty())
query.where(EBIKE_COMPONENT_ENTER_RECORDS.OWNING_REGION.eq(region));
String productType = reqEbikeComponentEnterRecordsDto.getComponentType();
if(productType!=null&&!productType.isEmpty())
if (productType != null && !productType.isEmpty())
query.where(EBIKE_COMPONENT_ENTER_RECORDS.COMPONENT_TYPE.eq(productType));
String state = reqEbikeComponentEnterRecordsDto.getState();
if(state!=null&&!state.isEmpty())
if (state != null && !state.isEmpty())
query.where(EBIKE_COMPONENT_ENTER_RECORDS.STATE.eq(state));
if(reqEbikeComponentEnterRecordsDto.getSortBy()!=null&&!reqEbikeComponentEnterRecordsDto.getSortBy().isEmpty()){
query.orderBy(reqEbikeComponentEnterRecordsDto.getSortBy(),"asc".equals(reqEbikeComponentEnterRecordsDto.getSortMethod()));
}else{
if (reqEbikeComponentEnterRecordsDto.getSortBy() != null && !reqEbikeComponentEnterRecordsDto.getSortBy().isEmpty()) {
query.orderBy(reqEbikeComponentEnterRecordsDto.getSortBy(), "asc".equals(reqEbikeComponentEnterRecordsDto.getSortMethod()));
} else {
query.orderBy(
QueryMethods.case_()
.when(EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_AT.isNotNull()).then(EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_AT)
.else_(EBIKE_COMPONENT_ENTER_RECORDS.CREATED_AT)
.end().desc()
QueryMethods.case_()
.when(EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_AT.isNotNull()).then(EBIKE_COMPONENT_ENTER_RECORDS.UPDATE_AT)
.else_(EBIKE_COMPONENT_ENTER_RECORDS.CREATED_AT)
.end().desc()
);
}

View File

@ -1,20 +1,20 @@
package com.cdzy.ebikeoperate.service.impl;
import com.cdzy.ebikeoperate.mapper.EbikeComponentOutRecordsMapper;
import com.cdzy.ebikeoperate.model.dto.request.ReqEbikeComponentOutRecordsDto;
import com.cdzy.ebikeoperate.model.dto.response.EbikeComponentOutRecordsDto;
import com.cdzy.ebikeoperate.model.pojo.EbikeComponentOutRecords;
import com.cdzy.ebikeoperate.service.EbikeComponentOutRecordsService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryMethods;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cdzy.ebikeoperate.model.pojo.EbikeComponentOutRecords;
import com.cdzy.ebikeoperate.mapper.EbikeComponentOutRecordsMapper;
import com.cdzy.ebikeoperate.service.EbikeComponentOutRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeComponentOutRecordsTableDef.EBIKE_COMPONENT_OUT_RECORDS;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeComponentTypeInfoTableDef.EBIKE_COMPONENT_TYPE_INFO;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeRegionTableDef.EBIKE_REGION;
import static com.cdzy.ebikeoperate.model.pojo.table.EbikeOperationRegionTableDef.EBIKE_OPERATION_REGION;
/**
@ -24,7 +24,7 @@ import static com.cdzy.ebikeoperate.model.pojo.table.EbikeRegionTableDef.EBIKE_R
* @since 2025-03-25
*/
@Service
public class EbikeComponentOutRecordsServiceImpl extends ServiceImpl<EbikeComponentOutRecordsMapper, EbikeComponentOutRecords> implements EbikeComponentOutRecordsService{
public class EbikeComponentOutRecordsServiceImpl extends ServiceImpl<EbikeComponentOutRecordsMapper, EbikeComponentOutRecords> implements EbikeComponentOutRecordsService {
@Autowired
private EbikeComponentOutRecordsMapper ebikeComponentOutRecordsMapper;
@ -36,12 +36,12 @@ public class EbikeComponentOutRecordsServiceImpl extends ServiceImpl<EbikeCompon
, EBIKE_COMPONENT_OUT_RECORDS.OLD_COMPONENT_HANDLE_OPTION, EBIKE_COMPONENT_OUT_RECORDS.STATE, EBIKE_COMPONENT_OUT_RECORDS.CREATED_USER,
EBIKE_COMPONENT_OUT_RECORDS.CREATED_AT, EBIKE_COMPONENT_OUT_RECORDS.UPDATE_USER, EBIKE_COMPONENT_OUT_RECORDS.UPDATE_AT, EBIKE_COMPONENT_OUT_RECORDS.ENTER_QUANTITY);
// 翻译所属区域
query.select(EBIKE_REGION.REGION_NAME.as("owning_region"));
query.select(EBIKE_OPERATION_REGION.OPERATION_REGION_NAME.as("owning_region"));
// 翻译部件类型
query.select(EBIKE_COMPONENT_TYPE_INFO.NAME.as("type_name"),
EBIKE_COMPONENT_TYPE_INFO.BRAND.as("type_brand"),
EBIKE_COMPONENT_TYPE_INFO.COVER.as("type_cover"));
query.leftJoin(EBIKE_REGION).on(EBIKE_COMPONENT_OUT_RECORDS.OWNING_REGION.eq(EBIKE_REGION.REGION_ID));
query.leftJoin(EBIKE_OPERATION_REGION).on(EBIKE_COMPONENT_OUT_RECORDS.OWNING_REGION.eq(EBIKE_OPERATION_REGION.OPERATION_REGION_ID));
query.leftJoin(EBIKE_COMPONENT_TYPE_INFO).on(EBIKE_COMPONENT_OUT_RECORDS.COMPONENT_TYPE.eq(EBIKE_COMPONENT_TYPE_INFO.ID));
String region = reqEbikeComponentOutRecordsDto.getRegion();
if (region != null && !region.isEmpty())
@ -50,19 +50,19 @@ public class EbikeComponentOutRecordsServiceImpl extends ServiceImpl<EbikeCompon
if (productType != null && !productType.isEmpty())
query.where(EBIKE_COMPONENT_OUT_RECORDS.COMPONENT_TYPE.eq(productType));
String oldOption = reqEbikeComponentOutRecordsDto.getOldComponentHandleOption();
if (oldOption!= null &&!oldOption.isEmpty())
if (oldOption != null && !oldOption.isEmpty())
query.where(EBIKE_COMPONENT_OUT_RECORDS.OLD_COMPONENT_HANDLE_OPTION.eq(oldOption));
String state = reqEbikeComponentOutRecordsDto.getState();
if (state!= null &&!state.isEmpty())
if (state != null && !state.isEmpty())
query.where(EBIKE_COMPONENT_OUT_RECORDS.STATE.eq(state));
if(reqEbikeComponentOutRecordsDto.getSortBy()!=null&&!reqEbikeComponentOutRecordsDto.getSortBy().isEmpty()){
query.orderBy(reqEbikeComponentOutRecordsDto.getSortBy(),"asc".equals(reqEbikeComponentOutRecordsDto.getSortMethod()));
}else{
if (reqEbikeComponentOutRecordsDto.getSortBy() != null && !reqEbikeComponentOutRecordsDto.getSortBy().isEmpty()) {
query.orderBy(reqEbikeComponentOutRecordsDto.getSortBy(), "asc".equals(reqEbikeComponentOutRecordsDto.getSortMethod()));
} else {
query.orderBy(
QueryMethods.case_()
.when(EBIKE_COMPONENT_OUT_RECORDS.UPDATE_AT.isNotNull()).then(EBIKE_COMPONENT_OUT_RECORDS.UPDATE_AT)
.else_(EBIKE_COMPONENT_OUT_RECORDS.CREATED_AT)
.end().desc()
QueryMethods.case_()
.when(EBIKE_COMPONENT_OUT_RECORDS.UPDATE_AT.isNotNull()).then(EBIKE_COMPONENT_OUT_RECORDS.UPDATE_AT)
.else_(EBIKE_COMPONENT_OUT_RECORDS.CREATED_AT)
.end().desc()
);
}