package com.bonus.canteen.core.reportforms.controller;

import com.bonus.canteen.core.reportforms.beans.CanteenOrg;
import com.bonus.canteen.core.reportforms.beans.CanteenRecord;
import com.bonus.canteen.core.reportforms.beans.OrgConsume;
import com.bonus.canteen.core.reportforms.service.reportformsService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.bonus.common.core.utils.PageUtils.startPage;

@RestController
@RequestMapping({"/api/v2/report"})
public class reportformsController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(reportformsController.class);

    @Resource
    private reportformsService service;
    @PostMapping("/consume/list")
    public List<OrgConsume> list(@RequestBody OrgConsume orgConsume) {
        return service.getOrgConsumeList(orgConsume);
    }

    @GetMapping("/consume/peoplelist")
    public TableDataInfo peoplelist(CanteenRecord orgConsume) {
        startPage();
        List<CanteenRecord> peoplelist = service.getPeoplelist(orgConsume);
        return getDataTable(peoplelist);
    }
    /**
     * 食堂预订餐接口查询
     * 通过区域名称查询
     * @param orgConsume
     * @return
     */
    @PostMapping("/consume/listByArea")
    /*public List<OrgConsume> listByArea(@RequestBody OrgConsume orgConsume) {
        //区域
        String orgName = orgConsume.getOrgName();
        // 去掉里面的“食堂”字样
        if (orgName != null) {
            orgName = orgName.replace("食堂", "");
            orgConsume.setOrgName(orgName);
        }
        if(orgConsume.getConSource() == 1){
            if ("运检后勤".equals(orgName)) {
                orgName = "运检分公司";
                orgConsume.setOrgName(orgName);
            }
            return service.getlistByH5list(orgConsume);
        } else if (orgConsume.getConSource() == 3) {
            //如果是送变电工业园食堂  修改成sbd工业园
            if ("送变电工业园".equals(orgName)) {
                orgName = "sbd工业园";
                orgConsume.setOrgName(orgName);
            }
            return service.getlistByArealist(orgConsume);
        } else if (orgConsume.getConSource() ==4 ) {
            if ("送变电工业园".equals(orgName)) {
                orgName = "sbd工业园";
                orgConsume.setOrgName(orgName);
            }
            return service.getlistBySuperlist(orgConsume);
        }else if (orgConsume.getConSource() ==5){
            if ("送变电工业园".equals(orgName)) {
                orgName = "sbd工业园";
                orgConsume.setOrgName(orgName);
                return service.getDeductionlist(orgConsume);
            }
        }
        else if (orgConsume.getConSource() ==2 ) {
            //驿站消费
            return service.getlistByOtherlist(orgConsume);
        }
        return null;
    }*/
    public List<OrgConsume> listByArea(@RequestBody OrgConsume orgConsume) {
        String orgName = orgConsume.getOrgName();
        Integer conSource = orgConsume.getConSource();

        // 统一处理机构名称
        if (orgName != null) {
            orgName = orgName.replace("食堂", "");

            // 特殊机构名称处理
            if ("运检后勤".equals(orgName) && conSource == 1) {
                orgName = "运检分公司";
            } else if ("送变电工业园".equals(orgName) && (conSource == 3 || conSource == 4 || conSource == 5)) {
                orgName = "sbd工业园";
            }

            orgConsume.setOrgName(orgName);
        }

        // 根据数据源类型路由到不同的服务方法
        switch (conSource) {
            case 1:
                return service.getlistByH5list(orgConsume);
            case 2:
                return service.getlistByOtherlist(orgConsume);
            case 3:
                return service.getlistByArealist(orgConsume);
            case 4:
                return service.getlistBySuperlist(orgConsume);
            case 5:
                return service.getDeductionlist(orgConsume);
            default:
                break;
        }

        return null;
    }
    /**
     * 超市预订餐接口查询
     */
    @PostMapping("/consume/listBySuper")
    public List<OrgConsume> listBySuper(@RequestBody OrgConsume orgConsume) {
        return service.getlistBySuperlist(orgConsume);
    }

    /**
     * H5预订餐详情查询
     */
    @PostMapping("/consume/listByH5")
    public List<OrgConsume> listByH5(@RequestBody OrgConsume orgConsume) {
        return service.getlistByH5list(orgConsume);
    }
    /**
     * 组织结构后台
     */
    @GetMapping("/tree")
    public List<CanteenOrg> getOrgTree() {
        return service.getOrgTree();
    }

}
