package org.springblade.enterprise.feign;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.Staff;
import org.springblade.enterprise.vo.StaffVO;
import org.springblade.enterprise.wrapper.StaffWrapper;
import org.springblade.enterprise.service.IStaffService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-03-30
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/staff")
public class StaffClient implements IStaffClient {

    private final IStaffService staffService;

	@Override
	public Staff getById(@RequestParam Long id) {
		Staff staff = staffService.getById(id);
		return staff;
	}

	/**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public StaffVO detail(@SpringQueryMap Staff staff) {
        Staff detail = staffService.getOne(Condition.getQueryWrapper(staff));
        return StaffWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<StaffVO> list(@SpringQueryMap Staff staff) {
        return StaffWrapper.build().listVO(staffService.list(Condition.getQueryWrapper(staff)));
    }

    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Staff staff) {
        return staffService.save(staff);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Staff staff) {
        return staffService.updateById(staff);
        }

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


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

	@Override
	@GetMapping("/count")
	public Integer count(@RequestParam(value = "tenantId", required = false) String tenantId) {
		return staffService.count();
	}

	@Override
	public Integer staffCount (@SpringQueryMap Staff staff) {
		return staffService.count(Condition.getQueryWrapper(staff));
	}

	@Override
	public Integer yxfCount(@RequestBody List<Long> ids) {
		return staffService.count(Condition.getQueryWrapper(new Staff()).lambda().in(CollUtil.isNotEmpty(ids),Staff::getId, ids));
	}

}
