package com.huimv.receive.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.entity.BaseLocation;
import com.huimv.receive.entity.Exist;
import com.huimv.receive.service.IBaseLocationService;
import com.huimv.receive.service.IExistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-07-21
 */
@RestController
@RequestMapping("/base-location")
@CrossOrigin
public class BaseLocationController {
    @Autowired
    private IBaseLocationService baseLocationService;
    @Autowired
    private IExistService existService;

    @PostMapping("/listAll")
    public Result listAll(@RequestBody Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String vistitType = paramsMap.get("vistitType");
        QueryWrapper<Exist> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId);
        Exist one = existService.getOne(queryWrapper);
        if (one.getExist() == 1 && vistitType.equals("0")) {
            return new Result(ResultCode.SUCCESS, baseLocationService.list(new QueryWrapper<BaseLocation>()
                    .eq("vistit_type", vistitType)
                    .ne("location_type", 0).ne("id", 3)));
        }
        if (one.getExist() == 1 && vistitType.equals("3")) {
            return new Result(ResultCode.SUCCESS, baseLocationService.list(new QueryWrapper<BaseLocation>()
                    .eq("vistit_type", vistitType)
                    .ne("location_type", 0).ne("id", 7)));
        }
        if (one.getExist() == 1 && vistitType.equals("5")) {
            return new Result(ResultCode.SUCCESS, baseLocationService.list(new QueryWrapper<BaseLocation>()
                    .eq("vistit_type", vistitType)
                    .eq("id", 9)));
        }
        return new Result(ResultCode.SUCCESS, baseLocationService.list(new QueryWrapper<BaseLocation>()
                .eq("vistit_type", vistitType)
                .ne("location_type", 0)));
    }

    @PostMapping("/listLuggageLocation")
    public Result listLuggageLocation(@RequestBody Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        return new Result(ResultCode.SUCCESS, baseLocationService.list(new QueryWrapper<BaseLocation>()
                .eq("vistit_type", 0).eq("parent_id", 0)));
    }
}
