package com.fs.express;

import com.fs.common.core.domain.R;
import com.fs.store.domain.FsStoreDelivers;
import com.fs.store.param.FsStoreOrderExpressParam;
import com.fs.store.service.IFsExpressService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 物流信息管理
 * @author xdd
 */
@RestController
@RequestMapping("/fsStoreDelivers")
public class FsStoreDeliversController {

    @Autowired
    private FsStoreDeliversService fsStoreDeliversService;

    @Autowired
    private IFsExpressService fsExpressService;


    /**
     * 根据ID查询
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id) {
        FsStoreDelivers fsStoreDelivers = fsStoreDeliversService.findById(id);
        return R.ok();
    }
    /**
     * 根据orderId查询
     */
    @GetMapping("/getByOrderId/{orderId}")
    public R getByOrderId(@PathVariable Long orderId) {
        List<FsStoreDelivers> byOrderId = fsStoreDeliversService.findByOrderId(orderId);
        return R.ok().put("data",byOrderId);
    }

    @ApiOperation("物流查询")
    @PostMapping("/getExpressByDeliverId")
    public R getExpressByDeliverId(@Validated @RequestBody FsStoreOrderExpressParam param, HttpServletRequest request){
        return fsExpressService.getExpressByDeliverId(param);
    }

    /**
     * 新增
     */
    @PostMapping
    public R create(@RequestBody FsStoreDelivers fsStoreDelivers) {
        FsStoreDelivers savedFsStoreDelivers = fsStoreDeliversService.save(fsStoreDelivers);
        return R.ok().put("data",savedFsStoreDelivers);
    }
     /**
     *全部更新
     */
    @PutMapping("/{id}")
    public R update(@PathVariable Long id, @RequestBody FsStoreDelivers fsStoreDelivers) {
        fsStoreDelivers.setId(id); // Ensure ID is set for update
        boolean updated = fsStoreDeliversService.update(fsStoreDelivers);
        return R.ok();
    }
}
