package com.xhpc.user.controller;

import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.log.annotation.Log;
import com.xhpc.common.log.enums.BusinessType;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.user.domain.XhpcCustomers;
import com.xhpc.user.domain.XhpcCustomersPersonnel;
import com.xhpc.user.service.IXhpcCustomersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @author yuyang
 * @date 2021/12/23 15:52
 */
@RestController
@RequestMapping("/customers")
public class XhpcCustomersController extends BaseController {

    @Autowired
    private IXhpcCustomersService xhpcCustomersService;


    @GetMapping("/userList")
    public R userList(HttpServletRequest request, String name) {
        List<Map<String, Object>> list = xhpcCustomersService.userList(request,name);
        return R.ok(list);
    }


    /**
     * 大客户组树列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request,String name) {
        List<Map<String, Object>> list = xhpcCustomersService.list(request,name);
        return getDataTable(list);
    }

    /**
     * 新增大客户
     *
     * @return
     */
    @Log(title = "大客户组", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addCustomers")
    public AjaxResult addCustomers(HttpServletRequest request, @RequestBody XhpcCustomers xhpcCustomers) {
        return xhpcCustomersService.addCustomers(request,xhpcCustomers);
    }

    /**
     * 删除大客户
     */
    @Log(title = "大客户组", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteCustomers")
    public AjaxResult deleteCustomers(@RequestBody XhpcCustomers xhpcCustomers) {
        return xhpcCustomersService.deleteCustomers(xhpcCustomers);
    }

    /**
     * 查询大客户
     */
    @PostMapping(value = "/getCustomersById")
    public AjaxResult getCustomersById(@RequestBody XhpcCustomers xhpcCustomers) {
        return AjaxResult.success(xhpcCustomersService.getCustomersById(xhpcCustomers));
    }

    /**
     * 编辑大客户组树
     *
     * @return
     */
    @Log(title = "大客户组", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCustomers")
    public AjaxResult updateCustomers(@RequestBody XhpcCustomers xhpcCustomers) {
        return xhpcCustomersService.updateCustomers(xhpcCustomers);
    }

    /**
     * 大客户人员列表
     */
    @GetMapping("/customersPersonnelList")
    public TableDataInfo communityPersonnelList(Long customersId,String account,String phone,Integer status) {
        startPage();
        List<Map<String, Object>> list = xhpcCustomersService.customersPersonnelList(customersId, account, phone, status);
        return getDataTable(list);
    }
    /**
     * 大客户人员添加
     *
     */
    @Log(title = "大客户人员", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addCustomersPersonnel")
    public AjaxResult addCustomersPersonnel(HttpServletRequest request, @RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        return xhpcCustomersService.addCustomersPersonnel(request,xhpcCustomersPersonnel);
    }

    /**
     * 查看大客户人员
     *
     */
    @PostMapping(value = "/getCustomersPersonnelById")
    public AjaxResult getCustomersPersonnelById(@RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        return AjaxResult.success(xhpcCustomersService.getCustomersPersonnelById(xhpcCustomersPersonnel));
    }

    /**
     * 编辑大客户人员
     *
     */
    @Log(title = "大客户人员", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCustomersPersonnel")
    public AjaxResult updateCustomersPersonnel(@RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        return xhpcCustomersService.updateCustomersPersonnel(xhpcCustomersPersonnel);
    }

    /**
     * 删除社区人员
     */
    @Log(title = "大客户人员", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteCustomersPersonnel")
    public AjaxResult deleteCustomersPersonnel(@RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        xhpcCustomersService.deleteCustomersPersonnel(xhpcCustomersPersonnel);
        return AjaxResult.success();
    }

    /**
     * 充值
     */
    @Log(title = "大客户人员-充值", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addRecharge")
    public AjaxResult addRecharge(@RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        xhpcCustomersPersonnel.setRechargeType(UserTypeUtil.RECHARGE_PT);
        return xhpcCustomersService.addRecharge(xhpcCustomersPersonnel);
    }

    /**
     * 改变社区人员状态
     */
    @Log(title = "大客户人员-状态", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateCustomersPersonnelStatus")
    public AjaxResult updateCustomersPersonnelStatus(@RequestBody XhpcCustomersPersonnel xhpcCustomersPersonnel) {
        xhpcCustomersService.updateCustomersPersonnelStatus(xhpcCustomersPersonnel);
        return AjaxResult.success();
    }
}
