package org.springblade.party.feign;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.community.feign.IAgencyClient;
import org.springblade.community.feign.IResidentialClient;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.enterprise.feign.IEnterpriseClient;
import org.springblade.party.service.IBranchService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.party.entity.BranchRelation;
import org.springblade.party.vo.BranchRelationVO;
import org.springblade.party.wrapper.BranchRelationWrapper;
import org.springblade.party.service.IBranchRelationService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-19
 */

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

public class BranchRelationClient implements IBranchRelationClient {

    private final IBranchRelationService branchRelationService;
    private IAgencyClient agencyClient;
    private IResidentialClient residentialClient;
    private IEnterpriseClient enterpriseClient;
    private IBranchService branchService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public BranchRelationVO detail(BranchRelation branchRelation) {
        BranchRelation detail = branchRelationService.getOne(Condition.getQueryWrapper(branchRelation));
        return BranchRelationWrapper.build(agencyClient,residentialClient,enterpriseClient,branchService).entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<BranchRelationVO> list(BranchRelation branchRelation) {
        return BranchRelationWrapper.build(agencyClient,residentialClient,enterpriseClient,branchService).listVO(branchRelationService.list(Condition.getQueryWrapper(branchRelation)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody BranchRelation branchRelation) {
        return branchRelationService.save(branchRelation);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody BranchRelation branchRelation) {
        return branchRelationService.updateById(branchRelation);
        }

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


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

	/**
	 * 分页
	 */
	@GetMapping("/app/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入branchRelation")
	public R<IPage<BranchRelationVO>> appList(BranchRelation branchRelation, Query query) {
		Assert.notNull(branchRelation.getResourceType(),"resourceType不能为空");
		Assert.notNull(branchRelation.getResourceId(),"resourceId不能为空");
		IPage<BranchRelation> pages = branchRelationService.page(Condition.getPage(query), Condition.getQueryWrapper(branchRelation));
		return R.data(BranchRelationWrapper.build(agencyClient,residentialClient,enterpriseClient,branchService).pageVO(pages));
	}


}
