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.utils.Func;
import org.springblade.person.entity.KeyPeople;
import org.springblade.person.service.IKeyPeopleService;
import org.springblade.person.vo.KeyPeopleVO;
import org.springblade.person.wrapper.KeyPeopleWrapper;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;

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

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

public class KeyPeopleClient implements IKeyPeopleClient {

    private final IKeyPeopleService keyPeopleService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public KeyPeopleVO detail(@SpringQueryMap KeyPeople keyPeople) {
        KeyPeople detail = keyPeopleService.getOne(Condition.getQueryWrapper(keyPeople));
        return KeyPeopleWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<KeyPeopleVO> list(KeyPeople keyPeople) {
        return KeyPeopleWrapper.build().listVO(keyPeopleService.list(Condition.getQueryWrapper(keyPeople)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody KeyPeople keyPeople) {
        return keyPeopleService.save(keyPeople);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody KeyPeople keyPeople) {
        return keyPeopleService.updateById(keyPeople);
        }

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


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

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

}
