package org.springblade.estate.feign;

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.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.AuthorizeRecords;
import org.springblade.estate.vo.AuthorizeRecordsVO;
import org.springblade.estate.wrapper.AuthorizeRecordsWrapper;
import org.springblade.estate.service.IAuthorizeRecordsService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2022-01-06
 */

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

public class AuthorizeRecordsClient implements IAuthorizeRecordsClient {

    private final IAuthorizeRecordsService authorizeRecordsService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public AuthorizeRecordsVO detail(AuthorizeRecords authorizeRecords) {
        AuthorizeRecords detail = authorizeRecordsService.getOne(Condition.getQueryWrapper(authorizeRecords));
        return AuthorizeRecordsWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<AuthorizeRecordsVO> list(AuthorizeRecords authorizeRecords) {
        return AuthorizeRecordsWrapper.build().listVO(authorizeRecordsService.list(Condition.getQueryWrapper(authorizeRecords)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody AuthorizeRecords authorizeRecords) {
        return authorizeRecordsService.save(authorizeRecords);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody AuthorizeRecords authorizeRecords) {
        return authorizeRecordsService.updateById(authorizeRecords);
        }

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


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

	@Override
	@PostMapping("/getAuthRecord")
	public List<AuthorizeRecords> getAuthRecord(@RequestParam(value = "serialNum", required = true)String serialNum,
												@RequestParam(value = "authReqNo", required = true)String authReqNo,
												@RequestParam(value = "authCmd", required = false)String authCmd) {
		return authorizeRecordsService.getAuthRecord(serialNum, authReqNo, authCmd);
	}

	@Override
	@PostMapping("/generateAuthRecord")
	public R generateAuthRecord(@RequestParam(value = "serialNum", required = true) String serialNum,
								@RequestParam(value = "userId", required = true) String userId,
								@RequestParam(value = "userName", required = false) String userName,
								@RequestParam(value = "userType", required = true) String userType,
								@RequestParam(value = "authReqNo", required = true) String authReqNo,
								@RequestParam(value = "authCmd", required = false) String authCmd,
								@RequestParam(value = "reqData", required = false) String reqData,
								@RequestParam(value = "smartDeviceType", required = true) Integer smartDeviceType,
								@RequestParam(value = "respMsg", required = false) String respMsg,
								@RequestParam(value = "tenantId", required = false) String tenantId) {
		return authorizeRecordsService.generateAuthRecord(serialNum, userId, userName, userType, authReqNo, authCmd, reqData, smartDeviceType, respMsg, tenantId);
	}


}
