package com.jiayue.insu.incloud.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiayue.insu.common.core.util.R;
import com.jiayue.insu.incloud.entity.IntegrationCompany;
import com.jiayue.insu.incloud.service.IntegrationCompanyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * IntegrationCompanyController
 *
 * @author yh
 * @date 2022-03-18 15:48:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/integrationCompany")
public class IntegrationCompanyController {

    private final IntegrationCompanyService integrationCompanyService;

    /**
     * 分页查询
     *
     * @param page   分页对象
     * @param integrationCompany station
     * @return
     */

    @GetMapping("/page")
    public R getPage(Page page, IntegrationCompany integrationCompany) {

        LambdaQueryWrapper<IntegrationCompany> lambdaQueryWrapper = new LambdaQueryWrapper<>();

        if(integrationCompany.getCode() !=null){
            lambdaQueryWrapper.eq(IntegrationCompany::getCode,integrationCompany.getCode());
        }
        if(integrationCompany.getName() !=null){
            lambdaQueryWrapper.like(IntegrationCompany::getName,integrationCompany.getName());
        }
        return R.ok(integrationCompanyService.page(page, lambdaQueryWrapper));
    }

    @GetMapping("/all")
    public R getAll() {
        return R.ok(integrationCompanyService.list());
    }

    /**
     * 通过code查询场站信息
     *
     * @param code code
     * @return R
     */
    @GetMapping("/{code}")
    public R getByCode(@PathVariable("code") String  code) {
        return R.ok(integrationCompanyService.findByCode(code));
    }


    /**
     * 新增integrationCompany
     *
     * @param integrationCompany station
     * @return R
     */

    @PostMapping
    public R save(@RequestBody IntegrationCompany integrationCompany) {
        return R.ok(integrationCompanyService.save(integrationCompany));
    }

    /**
     * 修改integrationCompany
     *
     * @param integrationCompany station
     * @return R
     */

    @PutMapping
    public R updateById(@RequestBody IntegrationCompany integrationCompany) {
        return R.ok(integrationCompanyService.updateById(integrationCompany));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return R.ok(integrationCompanyService.removeById(id));
    }


}
