package org.springblade.enterprise.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.enterprise.entity.EnterpriseDept;
import org.springblade.enterprise.vo.DeptVO;
import org.springblade.enterprise.wrapper.DeptWrapper;
import org.springblade.enterprise.service.IDeptService;

import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-19
 */

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

public class DeptClient implements IDeptClient {

    private final IDeptService deptService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public DeptVO detail(@SpringQueryMap EnterpriseDept dept) {
        EnterpriseDept detail = deptService.getOne(Condition.getQueryWrapper(dept));
        return DeptWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<DeptVO> list(@SpringQueryMap EnterpriseDept dept) {
        return DeptWrapper.build().listVO(deptService.list(Condition.getQueryWrapper(dept)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody EnterpriseDept dept) {
        return deptService.save(dept);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody EnterpriseDept dept) {
        return deptService.updateById(dept);
        }

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


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


}
