package org.springblade.estate.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.Company;
import org.springblade.estate.vo.CompanyVO;
import org.springblade.estate.wrapper.CompanyWrapper;
import org.springblade.estate.service.ICompanyService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-15
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/company")

public class CompanyClient implements ICompanyClient {

    private final ICompanyService companyService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public CompanyVO detail(@SpringQueryMap Company company) {
        Company detail = companyService.getOne(Condition.getQueryWrapper(company));
        return CompanyWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<CompanyVO> list(@SpringQueryMap Company company) {
        return CompanyWrapper.build().listVO(companyService.list(Condition.getQueryWrapper(company)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Company company) {
        return companyService.save(company);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Company company) {
        return companyService.updateById(company);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Company company) {
        return companyService.saveOrUpdate(company);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return companyService.deleteLogic(Func.toLongList(ids));
        }


}
