package com.njcn.advance.service.carrycapacity.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.advance.mapper.carrycapacity.CarryCapacityStrategyDhlPOMapper;
import com.njcn.advance.pojo.carrycapacity.po.CarryCapacityStrategyDhlPO;
import com.njcn.advance.pojo.carrycapacity.vo.CarryCapacityStrategyDhlVO;
import com.njcn.advance.service.carrycapacity.CarryCapacityStrategyDhlPOService;
import com.njcn.advance.utils.CheckStringUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 
 * Description:
 * Date: 2024/3/15  10:45【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Service
public class CarryCapacityStrategyDhlPOServiceImpl extends ServiceImpl<CarryCapacityStrategyDhlPOMapper, CarryCapacityStrategyDhlPO> implements CarryCapacityStrategyDhlPOService{


    @Override
    public List<CarryCapacityStrategyDhlVO> queyDetailDhl() {
        List<CarryCapacityStrategyDhlPO> list = this.lambdaQuery().eq(CarryCapacityStrategyDhlPO::getUserFlag, 1).list();
        return list.stream().map(t -> {
            CarryCapacityStrategyDhlVO vo = new CarryCapacityStrategyDhlVO();
            vo.setCount1(t.getCount1());
            vo.setCount2(t.getCount2());
            vo.setCount3(t.getCount3());
            vo.setCount4(t.getCount4());
            vo.setComparisonOperators1(t.getComparisonOperators1());
            vo.setComparisonOperators2(t.getComparisonOperators2());
            vo.setComparisonOperators3(t.getComparisonOperators3());
            vo.setComparisonOperators4(t.getComparisonOperators4());
            vo.setId(t.getId());
            vo.setProtoFlag(t.getProtoFlag());
            vo.setType(t.getType());
            return vo;
        }).collect(Collectors.toList());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean adddhl(CarryCapacityStrategyDhlVO capacityStrategyDhlVO) {
        this.lambdaUpdate().eq(CarryCapacityStrategyDhlPO::getId, capacityStrategyDhlVO.getId()).
                set(CarryCapacityStrategyDhlPO::getUserFlag, 2).update();
        CarryCapacityStrategyDhlPO carryCapacityStrategyDhlPO = new CarryCapacityStrategyDhlPO();
        BeanUtils.copyProperties(capacityStrategyDhlVO,carryCapacityStrategyDhlPO);
        carryCapacityStrategyDhlPO.setId(null);
        carryCapacityStrategyDhlPO.setUserFlag(1);
        carryCapacityStrategyDhlPO.setProtoFlag(2);
        boolean save = this.save(carryCapacityStrategyDhlPO);
        return save;
    }

}
