package cn.xluobo.business.sys.address;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.page.RespPage;
import com.ruoyi.mall.domain.Address;
import com.ruoyi.mall.mapper.AddressMapper;
import lombok.AllArgsConstructor;
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.Map;

@RestController
@RequestMapping("api/address")
@AllArgsConstructor
public class AddressController {

    private final AddressMapper addressMapper;

    @PostMapping("list")
    public AjaxResult list(@RequestBody Map<String,Object> params){
        RespPage<Address> page = new RespPage<>((Integer) params.get("pageNum"), (Integer) params.get("pageSize"));
        RespPage<Address> address = addressMapper.selectPage(page, Wrappers.<Address>lambdaQuery()
                .eq(ObjectUtil.isNotEmpty(params.get("getLevel")),Address::getLevel, params.get("getLevel"))
                .eq(ObjectUtil.isNotEmpty(params.get("parentCode")),Address::getParentCode, params.get("parentCode"))
        );
        return AjaxResult.success(address);
    }
}
