LinggangSchedulingController.java 7.22 KB
package com.ruoyi.controller.scheduling;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.domain.scheduling.LinggangScheduling;
import com.ruoyi.domain.scheduling.dto.LinggangSchedulingAddDTO;
import com.ruoyi.domain.scheduling.dto.LinggangSchedulingQueryDTO;
import com.ruoyi.domain.scheduling.dto.LinggangSchedulingUpdateDTO;
import com.ruoyi.domain.scheduling.vo.LinggangSchedulingVO;
import com.ruoyi.service.scheduling.LinggangSchedulingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;

import org.springframework.security.access.prepost.PreAuthorize;

import java.util.List;
import java.util.Date;

import com.ruoyi.domain.OrderEntity;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import com.ruoyi.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;


@RestController
@Api(tags = "")
@RequestMapping("linggang/scheduling")
public class LinggangSchedulingController extends BaseController {
    @Autowired
    private LinggangSchedulingService linggangSchedulingService;

    @ApiOperation("分页查询")
    @PreAuthorize("@ss.hasPermi('linggang:scheduling:list:limit:page:limit')")
    @PostMapping(value = "/list/limit/{page}/{pageLimit}")
    public IPage<LinggangSchedulingVO> listLimit(@ModelAttribute LinggangSchedulingQueryDTO request, @ModelAttribute OrderEntity orderEntity, @PathVariable Integer page, @PathVariable Integer pageLimit, org.springframework.ui.Model model) {
        LinggangScheduling entity = convert(request);
        entity.setType(1);
        IPage<LinggangScheduling> response = linggangSchedulingService.pageList(new Page<LinggangScheduling>(page, pageLimit), entity, orderEntity);

        return convert(response);
    }

    @ApiOperation("根据ID查询详情")
    @GetMapping(value = "/view/{id}")
    public com.ruoyi.common.core.domain.ResponseResult<LinggangSchedulingVO> view(@PathVariable("id") Integer id, org.springframework.ui.Model model) {
        LinggangScheduling source = linggangSchedulingService.getById(id);

        return com.ruoyi.common.core.domain.ResponseResult.success(convert(source));
    }

//    @PostMapping(value = "/list/select")
//    @ApiOperation("(页面选择)")
//    public com.ruoyi.common.core.domain.ResponseResult<List<LinggangSchedulingVO>> listSelect( LinggangSchedulingQueryDTO request) {
//        LinggangScheduling entity = convert(request);
//        List<LinggangScheduling> selectList = linggangSchedulingService.listOfSelect(entity);
//        return  com.ruoyi.common.core.domain.ResponseResult.success(convert(selectList));
//    }

    @PreAuthorize("@ss.hasPermi('linggang:scheduling:export')")
    @ApiOperation("导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody LinggangSchedulingQueryDTO request) {
        LinggangScheduling entity = convert(request);
        List<LinggangScheduling> list = linggangSchedulingService.list(entity);
        ExcelUtil<LinggangScheduling> util = new ExcelUtil<LinggangScheduling>(LinggangScheduling.class);
        util.exportExcel(response, list, "LinggangScheduling");
    }

    //    @ApiOperation("添加")
//        @PreAuthorize("@ss.hasPermi('linggang:scheduling:add')")
//    @PostMapping(value="/add")
//    public com.ruoyi.common.core.domain.ResponseResult add(@Valid @ModelAttribute LinggangSchedulingAddDTO request, BindingResult bindingResult) {
//        if(bindingResult.hasErrors()){
//             return com.ruoyi.common.core.domain.ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
//        }
//        LinggangScheduling entity = convert(request);
//        entity.setCreateBy(getUserId());
//        entity.setCreateTime(new Date());
//        int count = linggangSchedulingService.insertSelective(entity);
//        return count > 0?com.ruoyi.common.core.domain.ResponseResult.success(Boolean.TRUE):com.ruoyi.common.core.domain.ResponseResult.error("添加数据失败,请稍后再试");
//    }
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('linggang:scheduling:update')")
    @PostMapping(value = "/update")
    public com.ruoyi.common.core.domain.ResponseResult update(@Valid @ModelAttribute LinggangSchedulingUpdateDTO request, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return com.ruoyi.common.core.domain.ResponseResult.error(bindingResult.getFieldError().getDefaultMessage());
        }
        LinggangScheduling entity = convert(request);
//         entity.setUpdateBy(getUserId());
//         entity.setUpdateTime(new Date());
        boolean flag = linggangSchedulingService.updateAlcoholCountByPrimaryKey(entity);
        return flag ? com.ruoyi.common.core.domain.ResponseResult.success(Boolean.TRUE) : com.ruoyi.common.core.domain.ResponseResult.error("修改数据失败,请稍后再试");
    }


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

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


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

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

    private List<LinggangSchedulingVO> convert(List<LinggangScheduling> 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<LinggangSchedulingVO> convert(IPage<LinggangScheduling> sources) {
        return java.util.Optional.ofNullable(sources).map(scs -> {
            IPage<LinggangSchedulingVO> target = new Page();
            BeanUtils.copyProperties(scs, target);
            List<LinggangSchedulingVO> voNames = convert(scs.getRecords());
            target.setRecords(voNames);

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