21 changed files with 106 additions and 84 deletions
@ -0,0 +1,23 @@ |
|||||
|
package com.mathvision.diet.convert; |
||||
|
|
||||
|
import com.alibaba.fastjson2.JSONArray; |
||||
|
import com.alibaba.fastjson2.JSON; |
||||
|
import com.mathvision.diet.domian.RuleItemDTO; |
||||
|
|
||||
|
import javax.persistence.Converter; |
||||
|
import javax.persistence.AttributeConverter; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Converter(autoApply = true) |
||||
|
public class RuleItemConvert implements AttributeConverter<List<RuleItemDTO>, String> { |
||||
|
|
||||
|
@Override |
||||
|
public String convertToDatabaseColumn(List<RuleItemDTO> ruleItemDTO) { |
||||
|
return JSON.toJSONString(ruleItemDTO); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<RuleItemDTO> convertToEntityAttribute(String string) { |
||||
|
return JSONArray.parseArray(string, RuleItemDTO.class); |
||||
|
} |
||||
|
} |
@ -0,0 +1,5 @@ |
|||||
|
package com.mathvision.diet.domian; |
||||
|
|
||||
|
public enum MeasurementType { |
||||
|
weight, quantity |
||||
|
} |
@ -0,0 +1,41 @@ |
|||||
|
package com.mathvision.diet.domian; |
||||
|
|
||||
|
import lombok.*; |
||||
|
import org.apache.commons.collections4.CollectionUtils; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
|
||||
|
import java.math.BigDecimal; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Builder |
||||
|
@AllArgsConstructor |
||||
|
@NoArgsConstructor |
||||
|
@Getter |
||||
|
@Setter |
||||
|
@EqualsAndHashCode |
||||
|
public class RuleItemDTO { |
||||
|
/** |
||||
|
* 规则名称 |
||||
|
*/ |
||||
|
String name; |
||||
|
/** |
||||
|
* 计量单位 |
||||
|
*/ |
||||
|
MeasurementType type; |
||||
|
/** |
||||
|
* 食材种类 |
||||
|
*/ |
||||
|
List<String> category; |
||||
|
/** |
||||
|
* 最大值 |
||||
|
*/ |
||||
|
BigDecimal max; |
||||
|
/** |
||||
|
* 最小值 |
||||
|
*/ |
||||
|
BigDecimal min; |
||||
|
|
||||
|
public boolean check() { |
||||
|
return StringUtils.isNotBlank(name) && type != null && CollectionUtils.isNotEmpty(category) && (max != null || min != null); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue