package com.fjhx.controller.logistics;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.constants.StatusConstant;
import com.fjhx.constants.logistics.LogisticsConstant;
import com.fjhx.entity.logistics.LogisticsInfo;
import com.fjhx.params.logistics.DeliverDetailsVo;
import com.fjhx.params.logistics.LogisticsInfoVo;
import com.fjhx.service.logistics.LogisticsInfoService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 物流信息 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-30
 */
@RestController
@RequestMapping("/logisticsInfo")
public class LogisticsInfoController {

    @Autowired
    private LogisticsInfoService logisticsInfoService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<LogisticsInfo> result = logisticsInfoService.getPage(condition);
        return R.success(result);
    }

    /**
     * 发货通知
     *
     * @param entity
     * @return
     */
    @PostMapping("/add")
    public R add(@RequestBody LogisticsInfoVo entity) {
        logisticsInfoService.add(entity);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody LogisticsInfoVo logisticsInfoVo) {
        logisticsInfoService.edit(logisticsInfoVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody LogisticsInfoVo logisticsInfoVo) {
        logisticsInfoService.delete(logisticsInfoVo);
        return R.success();
    }

    @PostMapping("/list")
    public R list() {
        List<LogisticsInfo> list = logisticsInfoService.list(q -> q.eq(LogisticsInfo::getStatus, StatusConstant.NO).eq(LogisticsInfo::getLogisticsStatus, LogisticsConstant.KD100Status.STATUS_3));
        return R.success(list);
    }

    /**
     * 查询物流单号下拉款
     *
     * @param entity
     * @return
     */
    @PostMapping("/code/select")
    public R codeSelect(@RequestBody LogisticsInfoVo entity) {
        return R.success(logisticsInfoService.codeSelectByBusinessId(entity.getBusinessId()));
    }

    /**
     * 发货明细
     */
    @PostMapping("/deliverDetails")
    public R deliverDetails(@RequestBody LogisticsInfoVo entity) {
        List<DeliverDetailsVo> list = logisticsInfoService.deliverDetails(entity.getId());
        return R.success(list);
    }

    /**
     * 到货通知
     *
     * @param entity
     * @return
     */
    @PostMapping("/arrival/notice")
    public R arrivalNotice(@RequestBody LogisticsInfoVo entity) {
        logisticsInfoService.arrivalNotice(entity);
        return R.success();
    }

}

