package com.jwipc.shopping.controller.pc;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.base.Strings;
import com.jwipc.page.PageUtil;
import com.jwipc.page.PageView;
import com.jwipc.security.LoginUtil;
import com.jwipc.shopping.constant.ModuleConst;
import com.jwipc.shopping.entity.ShoppingReceivingAddress;
import com.jwipc.shopping.logic.OnlineMallLogic;
import com.jwipc.shopping.model.query.ReceivingAddressQuery;
import com.jwipc.shopping.service.IShoppingReceivingAddressService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * 功能描述:
 *
 * @Author: zx
 * @Date: 2024/3/14 0014 15:05
 */
@RestController
@RequestMapping(ModuleConst.MODULE_ROOT + "/address/rest")
@RequiredArgsConstructor
@Slf4j
public class ShoppingReceivingAddressRestController {

    @Autowired
    IShoppingReceivingAddressService shoppingReceivingAddressService;

    @Autowired
    OnlineMallLogic onlineMallLogic;

    /**
     * 列表数据查询
     *
     * @param page 当前页码
     * @param rows 每页显示行数
     * @param query 查询条件
     * @return 结果
     */
    @RequestMapping("/list")
    public PageView list(ReceivingAddressQuery query) {
        if (!LoginUtil.isSupplier()) {
            if (1L != LoginUtil.getUserId()) {
                query.setUserId(LoginUtil.getUserId());
            }
        } else {
            query.setUserId(-100L);
        }
        return onlineMallLogic.addresslistPage(query);
    }


    /**
     * 数据删除
     *
     * @param receivingAddressId 待删除的关系数据ID
     * @return 结果
     */
    @RequestMapping("/del")
    public ResponseEntity<?> dataDel(String receivingAddressId) {
        if (Strings.isNullOrEmpty(receivingAddressId)) {
            return ResponseEntity.badRequest().body("参数错误, 请检查");
        }
        onlineMallLogic.updateAddressById(receivingAddressId);
        return ResponseEntity.ok(true);
    }


    /**
     * 新建收货地址
     **/
    @RequestMapping("data/save")
    public ResponseEntity<?> addEntity(@RequestBody ShoppingReceivingAddress data ) {
        onlineMallLogic.saveOrUpdate(data);
        return ResponseEntity.ok(true);
    }



}
