package com.example.his.api.mis.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.his.api.common.result.R;
import com.example.his.api.mis.service.CustomerService;
import com.example.his.api.req.MisCustomer.CustomerOrderForm;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

@RestController("MisCustomerController")
@RequestMapping("/mis/customer")
public class CustomerController {

    @Resource
    private CustomerService customerService;

    /**
     * 查询客户摘要信息
     * @param customerId
     * @return
     */
    @GetMapping("/searchCustomerInfo")
    public R searchCustomerInfo(@RequestParam int customerId) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("customerId",customerId);
        HashMap result = customerService.searchCustomerInfo(map);
        return R.success(result);
    }

    /**
     * 查询客户订单记录
     * @param form
     * @return
     */
    @PostMapping("/searchCustomerOrder")
    public  R searchCustomerOrder(@RequestBody @Valid CustomerOrderForm form) {
        Map param = BeanUtil.beanToMap(form);
        PageInfo<HashMap> list = customerService.searchCustomerOrder(param);
        return R.success(list);
    }
}

