package com.fjhx.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.Condition;
import com.fjhx.params.contract.ContractEx;
import com.fjhx.params.customer.CustomerVo;
import com.fjhx.service.customer.CustomerService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 客户 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-10-25
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    @PostMapping("/page")
    public R page(@RequestBody Condition condition) {
        Page<Map<String, Object>> result = customerService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody CustomerVo customerVo) {
        customerService.add(customerVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody CustomerVo customerVo) {
        customerService.edit(customerVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody CustomerVo customerVo) {
        customerService.delete(customerVo);
        return R.success();
    }

    @PostMapping("/details")
    public R details(@RequestBody ContractEx contractVo) {
        CustomerVo customerVo = customerService.details(contractVo.getId());
        return R.success(customerVo);
    }

}

