package com.pj.project.tb_logistics;

import java.util.List;

import com.pj.api.dto.TbLogisticsDto;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.pj.utils.sg.*;
import com.pj.project4sp.SP;

import cn.dev33.satoken.annotation.SaCheckPermission;


/**
 * Controller: tb_logistics -- 物流订单表
 * @author qzy
 */
@RestController
@RequestMapping("/TbLogistics/")
public class TbLogisticsController {

	/** 底层 Service 对象 */
	@Autowired
	TbLogisticsService tbLogisticsService;

	/** 增 */
	@RequestMapping("add")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_ADD)
	public AjaxJson add(TbLogistics t){
		tbLogisticsService.add(t);
		t = tbLogisticsService.getById(SP.publicMapper.getPrimarykey());
		return AjaxJson.getSuccessData(t);
	}

	/** 删 */
	@RequestMapping("delete")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_DEL)
	public AjaxJson delete(Long id){
		 tbLogisticsService.delete(id);
		return AjaxJson.getSuccess();
	}

	/** 删 - 根据id列表 */
	@RequestMapping("deleteByIds")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_DEL)
	public AjaxJson deleteByIds(){
		List<Long> ids = SoMap.getRequestSoMap().getListByComma("ids", long.class);
		int line = SP.publicMapper.deleteByIds(TbLogistics.TABLE_NAME, ids);
		return AjaxJson.getByLine(line);
	}

	/** 改 */
	@RequestMapping("update")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson update(TbLogistics t){
		tbLogisticsService.update(t);
		return AjaxJson.getSuccess();
	}

	/** 查 - 根据id */
	@RequestMapping("getById")
		@SaCheckPermission(TbLogistics.PERMISSION_CODE)
	public AjaxJson getById(Long id){
		TbLogistics t = tbLogisticsService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	@RequestMapping("getList")
		@SaCheckPermission(TbLogistics.PERMISSION_CODE)
	public AjaxJson getList() {
		SoMap so = SoMap.getRequestSoMap();
		List<TbLogistics> list = tbLogisticsService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}



	/** 改 - 订单待司机确认(0=待确认,1=订单已确认,2=订单确认失败) */
	@RequestMapping("updatePrepare")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updatePrepare(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "prepare", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 待装货(0=待装货,1=已装货) */
	@RequestMapping("updateLoading")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateLoading(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "loading", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 发货(0=未发,1=已发) */
	@RequestMapping("updateDelivery")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateDelivery(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "delivery", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 已出海关(0=禁用,1=启用) */
	@RequestMapping("updateClearedCustom")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateClearedCustom(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "cleared_custom", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 接货人确定接货(0=禁用,1=启用) */
	@RequestMapping("updateMakeCargo")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateMakeCargo(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "make_cargo", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 收购商确认(0=禁用,1=启用) */
	@RequestMapping("updateConfirmReceipt")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateConfirmReceipt(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "confirm_receipt", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 订单完成状态 (0=未完成,1=已完成) */
	@RequestMapping("updateOrderFinish")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateOrderFinish(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "order_finish", value, id);
		return AjaxJson.getByLine(line);
	}

	/** 改 - 删除状态(0=禁用,1=启用) */
	@RequestMapping("updateDeleteStatus")
	@SaCheckPermission(TbLogistics.PERMISSION_CODE_EDIT)
	public AjaxJson updateDeleteStatus(Long id, Integer value){
		int line = SP.publicMapper.updateColumnById(TbLogistics.TABLE_NAME, "delete_status", value, id);
		return AjaxJson.getByLine(line);
	}

	/*-----               正常业务接口👆👆    不越界     rpc远程调用 👇👇                     -----*/



	/** 查 - 根据id */
	@RequestMapping("rpc/selectByOrderId")
//	@SaCheckPermission(TbLogistics.PERMISSION_CODE)
	public TbLogisticsDto selectByOrderId(@RequestParam("orderId") Long orderId){
		TbLogisticsDto t = tbLogisticsService.selectByOrderId(orderId);
		return t;
	}



}
