gasWellWatch/src/main/java/com/isu/gaswellwatch/mapper/GasWellMapper.java

64 lines
2.0 KiB
Java

package com.isu.gaswellwatch.mapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import com.isu.gaswellwatch.entity.GasWell;
import com.isu.gaswellwatch.dto.GasWellCreateRequest;
import com.isu.gaswellwatch.dto.GasWellEditRequest;
import com.isu.gaswellwatch.vo.GasWellVO;
import com.isu.gaswellwatch.vo.UserLoginInfoVO;
import cn.dev33.satoken.stp.StpUtil;
import com.isu.gaswellwatch.constants.UserConstant;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.List;
/**
* 气井Mapper gas_wells
*
* @author scwsl
* @date 2024-11-17
*/
@Mapper
public interface GasWellMapper {
void create(GasWellCreateRequest request, @MappingTarget GasWell gasWell);
@Mapping(target = "id", ignore = true)
void copyToEntity(GasWellEditRequest request, @MappingTarget GasWell gasWell);
GasWellVO toPageVO(GasWell entity);
List<GasWellVO> toPageVO(List<GasWell> entities);
default void copy(GasWellEditRequest request, GasWell gasWell) {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession()
.get(UserConstant.TOKEN_SESSION);
if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) {
gasWell.setUpdateBy(gasWell.getCreateBy());
}
gasWell.setUpdateTime(LocalDateTime.now());
copyToEntity(request, gasWell);
}
default GasWell create(GasWellCreateRequest request) {
UserLoginInfoVO userLoginInfoVO = (UserLoginInfoVO) StpUtil.getTokenSession()
.get(UserConstant.TOKEN_SESSION);
GasWell gasWell =new GasWell();
gasWell.setCreateTime(LocalDateTime.now());
gasWell.setUpdateTime(gasWell.getCreateTime());
if (Objects.nonNull(userLoginInfoVO) && Objects.nonNull(userLoginInfoVO.getUserVO())) {
gasWell.setCreateBy(userLoginInfoVO.getUserVO().getId());
gasWell.setUpdateBy(gasWell.getCreateBy());
}
create(request, gasWell);
return gasWell;
}
}