package com.jwipc.order.controller.pc;

import com.alibaba.fastjson2.JSON;
import com.jwipc.order.dto.AppointmentDockerDTO;
import com.jwipc.order.entity.AppointmentDocker;
import com.jwipc.order.logic.AppointmentDockerLogic;
import com.jwipc.order.model.query.AppointmentDockerQuery;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.jwipc.order.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 *预约工厂码头配置表
 * </p>
 *
 * @author wt
 * @version 1.0
 * @since 2024/3/5
 */
@RestController
@RequiredArgsConstructor
@RequestMapping(MODULE_ROOT + "/appointmentDocker/rest")
public class AppointmentDockerRestController {

    private final AppointmentDockerLogic appointmentDockerLogic;

    @RequestMapping("/list")
    public PageView list(AppointmentDockerQuery query){
        PageView pageView = appointmentDockerLogic.getList(query);
        return pageView;
    }
    /**
     * 查询工厂码头下拉框
     * @return
     */
    @RequestMapping("/listAll")
    public ResponseEntity<?> listAll(AppointmentDockerQuery query){
        List<AppointmentDockerDTO> dtoList =appointmentDockerLogic.listAll(query);
        return ResponseEntity.ok(dtoList);
    }

    /**
     * 保存数据
     * @param data
     * @return
     */
    @PostMapping("/save")
    public ResponseEntity<String> save(String data) {
        appointmentDockerLogic.createOrUpdate(JSON.parseObject(data, AppointmentDockerDTO.class));
        return ResponseEntity.ok(StringUtils.EMPTY);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @PostMapping("/del")
    public ResponseEntity<?> del(Long id) {
        appointmentDockerLogic.deleteById(id);
        return ResponseEntity.ok(StringUtils.EMPTY);
    }
}
