|
@@ -1,14 +1,54 @@
|
|
|
package com.poyee.mapstruct;
|
|
package com.poyee.mapstruct;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.poyee.domain.ProductInfo;
|
|
import com.poyee.domain.ProductInfo;
|
|
|
|
|
+import com.poyee.enums.WhetherEnum;
|
|
|
import com.poyee.param.ProductListBO;
|
|
import com.poyee.param.ProductListBO;
|
|
|
import com.poyee.res.ProductListRes;
|
|
import com.poyee.res.ProductListRes;
|
|
|
import org.mapstruct.Mapper;
|
|
import org.mapstruct.Mapper;
|
|
|
|
|
+import org.mapstruct.Mapping;
|
|
|
|
|
+import org.mapstruct.Named;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
|
|
@Mapper(componentModel = "spring")
|
|
@Mapper(componentModel = "spring")
|
|
|
public interface ProductInfoMapstruct {
|
|
public interface ProductInfoMapstruct {
|
|
|
|
|
|
|
|
ProductListBO productDo2Bo(ProductInfo productInfos);
|
|
ProductListBO productDo2Bo(ProductInfo productInfos);
|
|
|
|
|
|
|
|
|
|
+ @Mapping(target = "fastSaleFlag", source = "fastSaleFlag", qualifiedByName = "integerToBoolean")
|
|
|
|
|
+ @Mapping(target = "idleFlag", source = "idleFlag", qualifiedByName = "integerToBoolean")
|
|
|
|
|
+ @Mapping(target = "saleTime", source = "saleTime", qualifiedByName = "stringToLocalDateTime")
|
|
|
|
|
+ @Mapping(target = "saleType", source = "saleType", qualifiedByName = "stringToInteger")
|
|
|
ProductListRes productBO2Res(ProductListBO productListBO);
|
|
ProductListRes productBO2Res(ProductListBO productListBO);
|
|
|
|
|
+
|
|
|
|
|
+ @Named("integerToBoolean")
|
|
|
|
|
+ default Boolean integerToBoolean(Integer value) {
|
|
|
|
|
+ return Objects.nonNull(value) && value == WhetherEnum.YES.getCode();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Named("stringToLocalDateTime")
|
|
|
|
|
+ default LocalDateTime stringToLocalDateTime(String value) {
|
|
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return LocalDateTime.parse(value);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Named("stringToInteger")
|
|
|
|
|
+ default Integer stringToInteger(String value) {
|
|
|
|
|
+ if (StrUtil.isBlank(value)) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ return Integer.parseInt(value);
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|