125 lines
4.3 KiB
Java
125 lines
4.3 KiB
Java
package com.ruoyi.airline.controller.convert;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.ruoyi.airline.api.domain.AirlineAreaVO;
|
|
import com.ruoyi.airline.api.domain.AirlineAreaTimeRuleVO;
|
|
import com.ruoyi.airline.controller.convert.AirlineAreaTimeRuleControllerConvert;
|
|
import com.ruoyi.airline.service.dto.AirlineAreaDTO;
|
|
import com.ruoyi.airline.service.dto.AirlineAreaTimeRuleDTO;
|
|
import com.ruoyi.common.core.utils.BaseConvert;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 空域Controller转换类
|
|
* 用于API VO和Service DTO之间的转换
|
|
*
|
|
* @author ruoyi
|
|
* @date 2026-02-25
|
|
*/
|
|
public class AirlineAreaControllerConvert extends BaseConvert<AirlineAreaDTO, AirlineAreaVO>
|
|
{
|
|
private static final Logger log = LoggerFactory.getLogger(AirlineAreaControllerConvert.class);
|
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
private static final AirlineAreaControllerConvert INSTANCE = new AirlineAreaControllerConvert();
|
|
|
|
private AirlineAreaControllerConvert() {
|
|
super(AirlineAreaDTO.class, AirlineAreaVO.class);
|
|
}
|
|
|
|
public static AirlineAreaVO from(AirlineAreaDTO dto)
|
|
{
|
|
return INSTANCE.innerFrom(dto);
|
|
}
|
|
|
|
public static AirlineAreaDTO to(AirlineAreaVO vo)
|
|
{
|
|
return INSTANCE.innerTo(vo);
|
|
}
|
|
|
|
public static List<AirlineAreaVO> fromList(List<AirlineAreaDTO> dtoList)
|
|
{
|
|
return INSTANCE.innerFromList(dtoList);
|
|
}
|
|
|
|
public static List<AirlineAreaDTO> toList(List<AirlineAreaVO> voList)
|
|
{
|
|
return INSTANCE.innerToList(voList);
|
|
}
|
|
|
|
@Override
|
|
protected AirlineAreaVO innerFrom(AirlineAreaDTO dto) {
|
|
if (dto == null) {
|
|
return null;
|
|
}
|
|
AirlineAreaVO vo = super.innerFrom(dto);
|
|
|
|
// 转换时间规则列表
|
|
if (dto.getTimeRules() != null && !dto.getTimeRules().isEmpty()) {
|
|
List<AirlineAreaTimeRuleVO> timeRuleVOs = AirlineAreaTimeRuleControllerConvert.fromList(dto.getTimeRules());
|
|
vo.setTimeRules(timeRuleVOs);
|
|
}
|
|
|
|
// 将字符串转换为 List<PointInfo>
|
|
if (dto.getPoints() != null && !dto.getPoints().isEmpty()) {
|
|
try {
|
|
List<AirlineAreaVO.PointInfo> pointsList = objectMapper.readValue(
|
|
dto.getPoints(),
|
|
objectMapper.getTypeFactory().constructCollectionType(List.class, AirlineAreaVO.PointInfo.class)
|
|
);
|
|
vo.setPoints(pointsList);
|
|
} catch (JsonProcessingException e) {
|
|
log.error("转换坐标点信息失败: {}", e.getMessage());
|
|
}
|
|
}
|
|
|
|
// 复制创建者名称
|
|
vo.setCreateByName(dto.getCreateByName());
|
|
|
|
// 复制分组ID
|
|
vo.setGroupId(dto.getGroupId());
|
|
|
|
return vo;
|
|
}
|
|
|
|
@Override
|
|
protected AirlineAreaDTO innerTo(AirlineAreaVO vo) {
|
|
if (vo == null) {
|
|
return null;
|
|
}
|
|
log.info("AirlineAreaControllerConvert.innerTo - vo.getName(): {}, vo.getAreaType(): {}, vo.getStatus(): {}",
|
|
vo.getName(), vo.getAreaType(), vo.getStatus());
|
|
|
|
AirlineAreaDTO dto = super.innerTo(vo);
|
|
|
|
// 转换时间规则列表
|
|
if (vo.getTimeRules() != null && !vo.getTimeRules().isEmpty()) {
|
|
List<AirlineAreaTimeRuleDTO> timeRuleDTOs = AirlineAreaTimeRuleControllerConvert.toList(vo.getTimeRules());
|
|
dto.setTimeRules(timeRuleDTOs);
|
|
}
|
|
|
|
// 将 List<PointInfo> 转换为字符串
|
|
if (vo.getPoints() != null && !vo.getPoints().isEmpty()) {
|
|
try {
|
|
String pointsJson = objectMapper.writeValueAsString(vo.getPoints());
|
|
dto.setPoints(pointsJson);
|
|
} catch (JsonProcessingException e) {
|
|
log.error("转换坐标点信息失败: {}", e.getMessage());
|
|
dto.setPoints("[]"); // Default to empty array
|
|
}
|
|
} else {
|
|
dto.setPoints("[]"); // Default to empty array
|
|
}
|
|
|
|
log.info("AirlineAreaControllerConvert.innerTo - dto.getName(): {}, dto.getAreaType(): {}, dto.getStatus(): {}",
|
|
dto.getName(), dto.getAreaType(), dto.getStatus());
|
|
|
|
return dto;
|
|
}
|
|
|
|
}
|