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.XhpcCommunity;
import com.xhpc.user.domain.XhpcCommunityPersonnel;
import com.xhpc.user.domain.XhpcMotorcade;
import com.xhpc.user.domain.XhpcMotorcadePersonnel;
import com.xhpc.user.service.IXhpcMotorcadeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 车队
 *
 * @author yuyang
 * @Date 2026-01-15 14:13
 */
@RestController
@RequestMapping("/motorcade")
public class XhpcMotorcadeController extends BaseController {

    @Autowired
    private IXhpcMotorcadeService xhpcMotorcadeService;

    /**
     * 车队列表
     */
    @GetMapping("/userList")
    public R userList(HttpServletRequest request, String name) {
        return R.ok(xhpcMotorcadeService.userList(request,name));
    }

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

    /**
     * 新增车队组树
     *
     * @return
     */
    @Log(title = "车队", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addMotorcade")
    public AjaxResult addMotorcade(HttpServletRequest request, @RequestBody XhpcMotorcade xhpcMotorcade) {
        return xhpcMotorcadeService.addMotorcade(request,xhpcMotorcade);
    }

    /**
     * 删除车队组树
     */
    @Log(title = "车队", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteMotorcade")
    public AjaxResult deleteMotorcade(@RequestBody XhpcMotorcade xhpcMotorcade) {
        return xhpcMotorcadeService.deleteMotorcade(xhpcMotorcade);
    }

    /**
     * 查询车队组
     */
    @PostMapping(value = "/getMotorcadeById")
    public AjaxResult getMotorcadeById(@RequestBody XhpcMotorcade xhpcMotorcade) {
        return AjaxResult.success(xhpcMotorcadeService.getMotorcadeById(xhpcMotorcade));
    }

    /**
     * 编辑车队组树
     *
     * @return
     */
    @Log(title = "车队", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateMotorcade")
    public AjaxResult updateMotorcade(@RequestBody XhpcMotorcade xhpcMotorcade) {
        return xhpcMotorcadeService.updateMotorcade(xhpcMotorcade);
    }

    /**
     * 编辑金额
     *
     * @return
     */
    @Log(title = "车队", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateMotorcadeMoney")
    public AjaxResult updateMotorcadeMoney(@RequestBody XhpcMotorcade xhpcMotorcade) {
        return xhpcMotorcadeService.updateMotorcadeMoney(xhpcMotorcade);
    }

    /**
     * 车队人员列表
     */
    @GetMapping("/getOrderMotorcade")
    public R getOrderMotorcade(String mark) {
        Map<String, Object> map = xhpcMotorcadeService.getOrderMotorcade(mark);
        return R.ok(map);
    }


    /**
     * 车队人员列表
     */
    @GetMapping("/motorcadePersonnelList")
    public TableDataInfo motorcadePersonnelList(Long motorcadeId,String account,String phone,Integer status) {
        startPage();
        List<Map<String, Object>> list = xhpcMotorcadeService.motorcadePersonnelList(motorcadeId, account, phone, status);
        return getDataTable(list);
    }

    /**
     * 车队人员添加
     *
     */
    @Log(title = "车队人员", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addMotorcadePersonnel")
    public AjaxResult addMotorcadePersonnel(HttpServletRequest request,@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        return xhpcMotorcadeService.addMotorcadePersonnel(request,xhpcMotorcadePersonnel);
    }

    /**
     * 查看车队人员
     *
     */
    @PostMapping(value = "/getMotorcadePersonnelById")
    public AjaxResult getMotorcadePersonnelById(@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        return AjaxResult.success(xhpcMotorcadeService.getMotorcadePersonnelById(xhpcMotorcadePersonnel));
    }

    /**
     * 编辑车队人员
     *
     */
    @Log(title = "车队人员", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateMotorcadePersonnel")
    public AjaxResult updateMotorcadePersonnel(@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        return xhpcMotorcadeService.updateMotorcadePersonnel(xhpcMotorcadePersonnel);
    }

    /**
     * 删除车队人员
     */
    @Log(title = "车队人员", businessType = BusinessType.DELETE)
    @PostMapping(value = "/deleteMotorcadePersonnel")
    public AjaxResult deleteMotorcadePersonnel(@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        xhpcMotorcadeService.deleteMotorcadePersonnel(xhpcMotorcadePersonnel);
        return AjaxResult.success();
    }

    /**
     * 改变车队人员状态
     */
    @Log(title = "车队人员-状态", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/updateMotorcadePersonnelStatus")
    public AjaxResult updateMotorcadePersonnelStatus(@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        xhpcMotorcadeService.updateMotorcadePersonnelStatus(xhpcMotorcadePersonnel);
        return AjaxResult.success();
    }

    /**
     * 分配
     */
    @Log(title = "车队人员-分配", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addRecharge")
    public AjaxResult addRecharge(@RequestBody XhpcMotorcadePersonnel xhpcMotorcadePersonnel) {
        xhpcMotorcadePersonnel.setRechargeType(UserTypeUtil.RECHARGE_PT);
        return xhpcMotorcadeService.addRecharge(xhpcMotorcadePersonnel);
    }

}
