package com.jwipc.order.controller.pc;

import com.jwipc.order.dto.AppointmentShowMainDTO;
import com.jwipc.order.dto.DevAppointmentParamDTO;
import com.jwipc.order.logic.AppointmentRecordLogic;
import com.jwipc.order.model.query.AppointmentRecordQuery;
import com.jwipc.order.model.query.AppointmentShowTimeQuery;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import lombok.RequiredArgsConstructor;
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.Arrays;

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 + "/appointmentRecord/rest")
public class AppointmentRecordRestController {

    private final AppointmentRecordLogic appointmentRecordLogic;

    /**
     * 加载送货单预约记录表列表
     * @param query
     * @return
     */
    @RequestMapping("/list")
    public PageView list(AppointmentRecordQuery query) {
        PageView pageView = appointmentRecordLogic.getList(query);
        return pageView;
    }

    /**
     * 送货单类型 预约送货保存
     *
     * @return
     */
    @PostMapping("/devOrder/save")
    public ResponseEntity<?> devOrderSave(DevAppointmentParamDTO paramDTO) throws Exception {
        if(LoginUtil.isSupplier()){
            paramDTO.setSupplierName(LoginUtil.getName());
            paramDTO.setSupplierCode(LoginUtil.getAccount());
        }
        appointmentRecordLogic.devOrderSave(paramDTO);
        return ResponseEntity.ok("ok");
    }
    /**
     * 送货单类型 预约变更
     *
     * @param selectDay     变更的日期
     * @param appointmentId 变更选择的时间范围
     * @param ids           预约记录ids
     * @param dockerCode    码头编码
     * @param factoryCode   工厂编码
     * @return
     */
    @PostMapping("/devOrder/change")
    public ResponseEntity<?> devOrderChange(String selectDay, String appointmentId, String ids, String dockerCode, String factoryCode) throws Exception {
        appointmentRecordLogic.devOrderChange(selectDay,appointmentId,ids,dockerCode,factoryCode);
        return ResponseEntity.ok("ok");
    }

    @PostMapping("pass")
    public ResponseEntity<?> pass(String id) {
        appointmentRecordLogic.pass(id);
        return ResponseEntity.ok("ok");
}
    /**
     * 取消预约
     *
     * @param ids
     * @return
     */
    @PostMapping("cancle")
    public ResponseEntity<?> cancle(String ids) {
        appointmentRecordLogic.deleteBatchIds(Arrays.asList(ids.split(",")));
        return ResponseEntity.ok("ok");
    }
    /**
     * 送货单类型预约记录的查看
     *
     * @param query
     * @return
     */
    @PostMapping("/deliveryDetailsRecord")
    public PageView deliveryDetailsRecord(AppointmentRecordQuery query) {
        PageView pageView = appointmentRecordLogic.deliveryDetailsRecord(query);
        return pageView;
    }
    /**
     * 预约看板数据
     *
     * @param query 查询条件
     * @return
     */
    @PostMapping("/appointmentShow")
    public AppointmentShowMainDTO appointmentShow(AppointmentShowTimeQuery query) {
        return appointmentRecordLogic.appointmentShow(query);
    }
}
