package com.xhpc.charging.station.controller;

import com.xhpc.charging.station.dto.XhpcPlaceholderDto;
import com.xhpc.charging.station.service.IXhpcPlaceholderService;
import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.common.util.LogUserUtils;
import com.xhpc.system.api.model.LoginUser;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 占位费
 *
 * @author yuyang
 * @Date 2025-04-22 22:06
 */
@RestController
@RequestMapping("/placeholder")
public class XhpcPlaceholderController extends BaseController {

    @Resource
    IXhpcPlaceholderService xhpcPlaceholderService;
    @Resource
    LogUserUtils logUserUtils;

    @GetMapping("/list")
    public TableDataInfo list(HttpServletRequest request, Long chargingStationId,Integer status,Long operatorId,String startTime,String endTime,Integer type,Integer ykcStatus) {

        LoginUser loginUser = logUserUtils.getLogUser(request);
        startPage();
        Map<String, Object> params = new HashMap<>();
        params.put("tenantId", loginUser.getTenantId());
        params.put("status", status);
        params.put("type", type);
        params.put("ykcStatus", ykcStatus);
        params.put("chargingStationId", chargingStationId);
        params.put("operatorId", operatorId);
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        List<Map<String, Object>> list = xhpcPlaceholderService.getXhpcPlaceholderList(request,params);
        return getDataTable(list);
    }

    @GetMapping("/detail")
    public R getXhpcPlaceholderDetail(@RequestParam("placeholderId") Long placeholderId) {

        return R.ok(xhpcPlaceholderService.getXhpcPlaceholderDetail(placeholderId));
    }

    @PostMapping("/updateXhpcPlaceholder")
    public R updateXhpcPlaceholder(HttpServletRequest request, @RequestBody XhpcPlaceholderDto xhpcPlaceholder) {

        LoginUser loginUser = logUserUtils.getLogUser(request);

        xhpcPlaceholder.setUpdateBy(loginUser.getUserid().toString());
        xhpcPlaceholder.setUpdateTime(new Date());
        xhpcPlaceholder.setChargingStationId(xhpcPlaceholder.getChargingStationId());
        return xhpcPlaceholderService.updateXhpcPlaceholder(xhpcPlaceholder);
    }

    @PostMapping("/installXhpcPlaceholder")
    public R installXhpcPlaceholder(HttpServletRequest request, @RequestBody XhpcPlaceholderDto xhpcPlaceholder) {

        LoginUser loginUser = logUserUtils.getLogUser(request);
        xhpcPlaceholder.setCreateBy(loginUser.getUserid().toString());
        xhpcPlaceholder.setCreateTime(new Date());
        return xhpcPlaceholderService.installXhpcPlaceholder(xhpcPlaceholder);
    }

    /**
     * 桩-删除
     */
    @DeleteMapping("/{placeholderId}")
    public R remove(HttpServletRequest request,@PathVariable Long placeholderId) {
        LoginUser loginUser = logUserUtils.getLogUser(request);
        XhpcPlaceholderDto xhpcPlaceholder= new XhpcPlaceholderDto();
        xhpcPlaceholder.setCreateBy(loginUser.getUserid().toString());
        xhpcPlaceholder.setCreateTime(new Date());
        xhpcPlaceholder.setPlaceholderId(placeholderId);
        return xhpcPlaceholderService.removeXhpcPlaceholderById(request,xhpcPlaceholder);
    }

}
