package org.springblade.person.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.person.entity.Disabler;
import org.springblade.person.service.IDisablerService;
import org.springblade.person.vo.DisablerVO;
import org.springblade.person.wrapper.DisablerWrapper;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;

import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-14
 */

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

public class DisablerClient implements IDisablerClient {

    private final IDisablerService disablerService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public DisablerVO detail(@SpringQueryMap Disabler disabler) {
        Disabler detail = disablerService.getOne(Condition.getQueryWrapper(disabler));
        return DisablerWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<DisablerVO> list(Disabler disabler) {
        return DisablerWrapper.build().listVO(disablerService.list(Condition.getQueryWrapper(disabler)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Disabler disabler) {
        return disablerService.save(disabler);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Disabler disabler) {
        return disablerService.updateById(disabler);
        }

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


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

	/**
	 * 根据parentId获取对应标签表信息
	 */
	@GetMapping("/detailByParentId")
	@ApiOperationSupport(order = 8)
	@ApiOperation(value = "详情", notes = "传入disabler")
	public DisablerVO detailByParentId(Long parentId) {
		Disabler detail = disablerService.getBaseMapper().selectOne(new QueryWrapper<Disabler>().eq("parent_id",parentId));
		return DisablerWrapper.build().entityVO(detail);
	}
}
