package com.fjhx.controller.customer;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.BaseEntity;
import com.fjhx.entity.customer.CustomerInfo;
import com.fjhx.params.customer.CustomerInfoEx;
import com.fjhx.params.customer.CustomerInfoVo;
import com.fjhx.service.customer.CustomerInfoService;
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.List;
import java.util.Map;

/**
 * <p>
 * 客户 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-02
 */
@RestController
@RequestMapping("/customerInfo")
public class CustomerInfoController {

    @Autowired
    private CustomerInfoService customerInfoService;

    @PostMapping("/list")
    public R list() {
        List<CustomerInfo> list = customerInfoService.list(
                q -> q.select(BaseEntity::getId, CustomerInfo::getName, CustomerInfo::getCode));
        return R.success(list);
    }

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

    @PostMapping("/add")
    public R add(@RequestBody CustomerInfoVo customerInfoVo) {
        customerInfoService.add(customerInfoVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody CustomerInfoVo customerInfoVo){
        customerInfoService.edit(customerInfoVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody CustomerInfoVo customerInfoVo){
        customerInfoService.delete(customerInfoVo);
        return R.success();
    }

}

