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.ElderlyPeople;
import org.springblade.person.service.IElderlyPeopleService;
import org.springblade.person.vo.ElderlyPeopleVO;
import org.springblade.person.wrapper.ElderlyPeopleWrapper;
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/elderlypeople")

public class ElderlyPeopleClient implements IElderlyPeopleClient {

    private final IElderlyPeopleService elderlyPeopleService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public ElderlyPeopleVO detail(@SpringQueryMap ElderlyPeople elderlyPeople) {
        ElderlyPeople detail = elderlyPeopleService.getOne(Condition.getQueryWrapper(elderlyPeople));
        return ElderlyPeopleWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<ElderlyPeopleVO> list(ElderlyPeople elderlyPeople) {
        return ElderlyPeopleWrapper.build().listVO(elderlyPeopleService.list(Condition.getQueryWrapper(elderlyPeople)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody ElderlyPeople elderlyPeople) {
        return elderlyPeopleService.save(elderlyPeople);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody ElderlyPeople elderlyPeople) {
        return elderlyPeopleService.updateById(elderlyPeople);
        }

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


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

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

}
