NewDriverController.java 3.24 KB
package com.ruoyi.controller.driver;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.ResponseResult;
import com.ruoyi.domain.driver.NewDriver;
import com.ruoyi.domain.driver.dto.NewDriverAddDTO;
import com.ruoyi.domain.driver.dto.NewDriverQueryDTO;
import com.ruoyi.domain.driver.dto.NewDriverUpdateDTO;
import com.ruoyi.domain.driver.vo.NewDriverVO;
import com.ruoyi.service.driver.NewDriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



@RestController
@RequestMapping("new/driver")
@Api(tags = "新-驾驶员信息")
public class NewDriverController extends BaseController {
    @Autowired
    private NewDriverService newDriverService;


    @PostMapping(value = "/list/select")
    @ApiOperation("(页面选择)")
    public ResponseResult listSelect() {
        NewDriver entity = new NewDriver();
        List<NewDriver> selectList = newDriverService.listOfSelect(entity);
        return ResponseResult.success(convert(selectList));
    }

    private NewDriver convert(NewDriverQueryDTO source) {
        return java.util.Optional.ofNullable(source).map(sc -> {
            NewDriver target = new NewDriver();
            BeanUtils.copyProperties(sc, target);
            return target;
        }).orElse(null);
    }

    private NewDriver convert(NewDriverUpdateDTO source) {
        return java.util.Optional.ofNullable(source).map(sc -> {
            NewDriver target = new NewDriver();
            BeanUtils.copyProperties(sc, target);
            return target;
        }).orElse(null);
    }


    private NewDriver convert(NewDriverAddDTO source) {
        return java.util.Optional.ofNullable(source).map(sc -> {
            NewDriver target = new NewDriver();
            BeanUtils.copyProperties(sc, target);
            return target;
        }).orElseGet(null);
    }

    private NewDriverVO convert(NewDriver source) {
        return java.util.Optional.ofNullable(source).map(sc -> {
            NewDriverVO target = new NewDriverVO();
            BeanUtils.copyProperties(source, target);
            return target;
        }).orElseGet(null);
    }

    private List<NewDriverVO> convert(List<NewDriver> sources) {
        return java.util.Optional.ofNullable(sources).map(scs -> {
            return scs.stream().map(source -> {
                return convert(source);
            }).collect(java.util.stream.Collectors.toList());
        }).orElseGet(null);
    }

    private IPage<NewDriverVO> convert(IPage<NewDriver> sources) {
        return java.util.Optional.ofNullable(sources).map(scs -> {
            IPage<NewDriverVO> target = new com.baomidou.mybatisplus.extension.plugins.pagination.Page();
            BeanUtils.copyProperties(scs, target);
            List<NewDriverVO> voNames = convert(scs.getRecords());
            target.setRecords(voNames);

            return target;
        }).orElseGet(null);
    }
}