package com.bs.tm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bs.common.annotation.Log;
import com.bs.common.core.controller.BaseController;
import com.bs.common.core.domain.AjaxResult;
import com.bs.common.core.page.TableDataInfo;
import com.bs.common.enums.BusinessType;
import com.bs.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.hutool.core.lang.Validator;
import com.bs.tm.domain.TmOrderPrice;
import com.bs.tm.service.ITmOrderPriceService;
import javax.annotation.Resource;

/**
 * 承运价格信息Controller
 *
 * @author bs
 * @date 2024-02-07
 */
@Api(tags = "承运价格信息")
@RestController
@RequestMapping("/order/price")
public class TmOrderPriceController extends BaseController {
    @Resource
    private ITmOrderPriceService tmOrderPriceService;

    /**
     * 分页查询承运价格信息列表
     */
    @ApiOperation("分页查询承运价格信息列表")
    @GetMapping("/pageList")
    public TableDataInfo pageList(TmOrderPrice tmOrderPrice) {
        startPage();
        LambdaQueryWrapper<TmOrderPrice> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmOrderPrice);
        List<TmOrderPrice> list = tmOrderPriceService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 查询承运价格信息列表
     */
    @ApiOperation("查询承运价格信息列表")
    @GetMapping("/list")
    public AjaxResult list(TmOrderPrice tmOrderPrice) {
        LambdaQueryWrapper<TmOrderPrice> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmOrderPrice);
        List<TmOrderPrice> list = tmOrderPriceService.list(queryWrapper);
        return success(list);
    }

    /**
     * 导出承运价格信息列表
     */
    @ApiOperation("导出承运价格信息列表")
    @Log(title = "承运价格信息导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmOrderPrice tmOrderPrice) {
        LambdaQueryWrapper<TmOrderPrice> queryWrapper = new LambdaQueryWrapper();
        condition(queryWrapper,tmOrderPrice);
        List<TmOrderPrice> list = tmOrderPriceService.list(queryWrapper);
        ExcelUtil<TmOrderPrice> util = new ExcelUtil<TmOrderPrice>(TmOrderPrice. class);
        util.exportExcel(response, list, "承运价格信息数据");
    }

    /**
     * 获取承运价格信息详细信息
     */
    @ApiOperation("获取承运价格信息详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(tmOrderPriceService.getById(ID));
    }

    /**
     * 新增承运价格信息
     */
    @ApiOperation("新增承运价格信息")
    @Log(title = "承运价格信息新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmOrderPrice tmOrderPrice) {
        return toAjax(tmOrderPriceService.save(tmOrderPrice));
    }

    /**
     * 修改承运价格信息
     */
    @ApiOperation("修改承运价格信息")
    @Log(title = "承运价格信息修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmOrderPrice tmOrderPrice) {
        return toAjax(tmOrderPriceService.updateById(tmOrderPrice));
    }

    /**
     * 删除承运价格信息
     */
    @ApiOperation("删除承运价格信息")
    @Log(title = "承运价格信息删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable List<Long> IDs) {
        return toAjax(tmOrderPriceService.removeBatchByIds(IDs));
    }

    /**
      * 条件设置
      */
    private void condition (LambdaQueryWrapper<TmOrderPrice> queryWrapper,TmOrderPrice tmOrderPrice){


        //id
        if(Validator.isNotEmpty(tmOrderPrice.getId())){
            queryWrapper.eq(TmOrderPrice::getId,tmOrderPrice.getId());
        }

        //订单ID
        if(Validator.isNotEmpty(tmOrderPrice.getOrderId())){
            queryWrapper.eq(TmOrderPrice::getOrderId,tmOrderPrice.getOrderId());
        }

        //货物ID
        if(Validator.isNotEmpty(tmOrderPrice.getCargoId())){
            queryWrapper.eq(TmOrderPrice::getCargoId,tmOrderPrice.getCargoId());
        }

        //价格类型
        if(Validator.isNotEmpty(tmOrderPrice.getPriceType())){
            queryWrapper.eq(TmOrderPrice::getPriceType,tmOrderPrice.getPriceType());
        }

        //价格代码
        if(Validator.isNotEmpty(tmOrderPrice.getPriceCode())){
            queryWrapper.eq(TmOrderPrice::getPriceCode,tmOrderPrice.getPriceCode());
        }

        //价格名称
        if(Validator.isNotEmpty(tmOrderPrice.getPriceName())){
            queryWrapper.eq(TmOrderPrice::getPriceName,tmOrderPrice.getPriceName());
        }

        //价格
        if(Validator.isNotEmpty(tmOrderPrice.getPrice())){
            queryWrapper.eq(TmOrderPrice::getPrice,tmOrderPrice.getPrice());
        }

        //备注
        if(Validator.isNotEmpty(tmOrderPrice.getRemark())){
            queryWrapper.eq(TmOrderPrice::getRemark,tmOrderPrice.getRemark());
        }

        //创建人
        if(Validator.isNotEmpty(tmOrderPrice.getCreateBy())){
            queryWrapper.eq(TmOrderPrice::getCreateBy,tmOrderPrice.getCreateBy());
        }

        //创建时间
        if(Validator.isNotEmpty(tmOrderPrice.getCreateTime())){
            queryWrapper.eq(TmOrderPrice::getCreateTime,tmOrderPrice.getCreateTime());
        }

        //修改人
        if(Validator.isNotEmpty(tmOrderPrice.getUpdateBy())){
            queryWrapper.eq(TmOrderPrice::getUpdateBy,tmOrderPrice.getUpdateBy());
        }

        //修改时间
        if(Validator.isNotEmpty(tmOrderPrice.getUpdateTime())){
            queryWrapper.eq(TmOrderPrice::getUpdateTime,tmOrderPrice.getUpdateTime());
        }

        //删除标志（0代表存在 2代表删除）
        if(Validator.isNotEmpty(tmOrderPrice.getDelFlag())){
            queryWrapper.eq(TmOrderPrice::getDelFlag,tmOrderPrice.getDelFlag());
        }

        }

}
