package com.dk.mdm.service.wxapi.basic;


import com.dk.common.infrastructure.annotaiton.Pagination;
import com.dk.common.mapper.BaseMapper;
import com.dk.common.model.pojo.PageList;
import com.dk.common.model.wxapi.wxResponse.WxCommonResponse;
import com.dk.common.response.ResponseResultUtil;
import com.dk.common.response.ResponseResultVO;
import com.dk.mdm.infrastructure.util.AuthUtils;
import com.dk.mdm.mapper.wxapi.basic.WxCommonMapper;
import com.dk.mdm.model.query.wxapi.basic.WxCommonQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dk.common.service.BaseService;

import java.util.List;
import java.util.Map;

/**
 * @author : admin
 * @desc : wx-控件数据源API
 * @date : 2024/2/22 17:21
 */
@Service
public class WxCommonService extends BaseService<WxCommonResponse> {

    @Override
    public BaseMapper<WxCommonResponse> getRepository() {
        return wxCommonMapper;
    }

    @Autowired
    private WxCommonMapper wxCommonMapper;

    @Autowired
    private AuthUtils authUtils;


    //TODO 未完成,待续
    public ResponseResultVO<List<WxCommonResponse>> getWxInitData(WxCommonQuery wxCommonQuery) {
        //获取前台数据源CODE
        String dataSourceCode = wxCommonQuery.getDataSourceCode();
        //查询到的结果集
        List<WxCommonResponse> list = null;


        //客户来源
        if (dataSourceCode.equals("customerFrom")) {

            list = wxCommonMapper.getCustomerSource(wxCommonQuery);
        }
        //卫生间数
        else if (dataSourceCode.equals("toiletCount")) {
            list = wxCommonMapper.getNumberToilets(wxCommonQuery);
        }
        //装修类型
        else if (dataSourceCode.equals("fitupType")) {
            wxCommonQuery.setDataSourceCode("客户-装修类型");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //房屋类型
        else if (dataSourceCode.equals("houseType")) {
            wxCommonQuery.setDataSourceCode("客户-房屋类型");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //装修风格
        else if (dataSourceCode.equals("fitupStyle")) {
            wxCommonQuery.setDataSourceCode("客户-装修风格");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //年龄构成
        else if (dataSourceCode.equals("ageComposition")) {
            wxCommonQuery.setDataSourceCode("客户-年龄构成");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //决策者
        else if (dataSourceCode.equals("decisionMaker")) {
            wxCommonQuery.setDataSourceCode("客户-决策者");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //结算类型
        else if (dataSourceCode.equals("settlement")) {
            list = wxCommonMapper.getSettlement(wxCommonQuery);
        }
        //费用项目
        else if (dataSourceCode.equals("feeItem")) {
            list = wxCommonMapper.getFeeItem(wxCommonQuery);
        }
        //商品分类
        else if (dataSourceCode.equals("商品规格分类")) {
            list = wxCommonMapper.getGoodsSpecs(wxCommonQuery);
        }
        //接待状态
        else if (dataSourceCode.equals("接待状态")) {
            list = wxCommonMapper.getReceptionStatus(wxCommonQuery);
        }
        //商品分类 - 其他
        else if (dataSourceCode.equals("商品规格其他分类")) {
            list = wxCommonMapper.getGoodsSpecsOrther(wxCommonQuery);
        }
        //组织机构
        else if (dataSourceCode.equals("org")) {
//                //docName == '销售订单'
            list = wxCommonMapper.getOrganization(wxCommonQuery);
        }
        //角色
        else if (dataSourceCode.equals("role")) {
            list = wxCommonMapper.getRole(wxCommonQuery);
        }
        //员工/业务员
        else if (dataSourceCode.equals("staff")) {
            list = wxCommonMapper.getStaff(wxCommonQuery);
        }
        //范围权限类型
        else if (dataSourceCode.equals("purviewType")) {
            list = wxCommonMapper.getPurviewType(wxCommonQuery);
        }
        //渠道
        else if (dataSourceCode.equals("salesChannel")) {
            list = wxCommonMapper.getChannel(wxCommonQuery);
        } else if (dataSourceCode.equals("warehouse")) {
            list = wxCommonMapper.getWareHouse(wxCommonQuery);
        } else if (dataSourceCode.equals("orderStatus")) {
            list = wxCommonMapper.getOrderStatus(wxCommonQuery);
        }
        //邀约结果
        else if (dataSourceCode.equals("inviteResult")) {
            wxCommonQuery.setDataSourceCode("邀约结果");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        }
        //客户意向
        else if (dataSourceCode.equals("customerIntentions")) {
            wxCommonQuery.setDataSourceCode("客户意向");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        }
        //跟进方式
        else if (dataSourceCode.equals("followType")) {
            wxCommonQuery.setDataSourceCode("跟进方式");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        }
        //留店时长
        else if (dataSourceCode.equals("followTime")) {
            wxCommonQuery.setDataSourceCode("留店时长");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        } //小区档案
        else if (dataSourceCode.equals("estate")) {
            list = wxCommonMapper.getEstate(wxCommonQuery);
        }
        //交货方式
        else if (dataSourceCode.equals("deliveryType")) {
            list = wxCommonMapper.getDeliveryType(wxCommonQuery);
        }
        //流失原因
        else if (dataSourceCode.equals("loseReason")) {
            wxCommonQuery.setDataSourceCode("客户-流失原因");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //kaihuhang
        else if (dataSourceCode.equals("refundBlank")) {
            list = wxCommonMapper.getRefundBlank(wxCommonQuery);
        } else if (dataSourceCode.equals("rejectReasonType")) {
            list = wxCommonMapper.getRejectReasonType(wxCommonQuery);
        } else if (dataSourceCode.equals("customerClassified")) {
            //客户分类
            list = wxCommonMapper.getCustomerClassified(wxCommonQuery);
        }
        else if (dataSourceCode.equals("sample")) {
            //上样部门
            list = wxCommonMapper.getStoreSampleAdvise(wxCommonQuery);
        }//出库类型
        else if (dataSourceCode.equals("outType")) {
            wxCommonQuery.setDataSourceCode("出库类型");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        }
        //出库原因
        else if (dataSourceCode.equals("outReason")) {
            wxCommonQuery.setDataSourceCode("库存-入库原因");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        //入库类型
        else if (dataSourceCode.equals("enterType")) {
            wxCommonQuery.setDataSourceCode("入库类型");
            list = wxCommonMapper.getBasicData(wxCommonQuery);
        }
        //入库原因
        else if (dataSourceCode.equals("enterReason")) {
            wxCommonQuery.setDataSourceCode("库存-入库原因");
            list = wxCommonMapper.getHouseType(wxCommonQuery);
        }
        else if (dataSourceCode.equals("hgSpuCategory")) {
            list = wxCommonMapper.selectByCategor(wxCommonQuery);
        }
        //品牌
        else if (dataSourceCode.equals("brand")) {
            list = wxCommonMapper.getBrand(wxCommonQuery);
        }
        //获取供应商类别
        else if (dataSourceCode.equals("supplierType")) {
            list = wxCommonMapper.getSupplierType(wxCommonQuery);
        }
        //获取服务类别
        else if (dataSourceCode.equals("serviceCategories")) {
            list = wxCommonMapper.getServiceCategories(wxCommonQuery);
        }
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 小区档案
     * @author : 于继渤
     * @date : 2022/7/5 19:33
     */
    @Pagination
    public ResponseResultVO<PageList<WxCommonResponse>> getEstate(WxCommonQuery wxCommonQuery) {
        return this.mergeListWithCount(wxCommonQuery, wxCommonMapper.getEstate(wxCommonQuery), wxCommonMapper.countByEstateCond(wxCommonQuery));
    }

    /**
     * @desc : 根据业务部门id 查询销售渠道
     * @author : 王英杰
     * @date : 2022/6/14 19:52
     */
    public ResponseResultVO<WxCommonResponse> selectSaleChannelByOrg(WxCommonQuery wxCommonQuery) {
        return ResponseResultUtil.success(wxCommonMapper.selectSaleChannelByOrg(wxCommonQuery));
    }

    /**
     * @desc : 查询组织机构下的结算方式
     * @author : 王英杰
     * @date : 2022/6/14 19:52
     */
    public ResponseResultVO<List<WxCommonResponse>> selectSettlementByOrg(WxCommonQuery wxCommonQuery) {
        return ResponseResultUtil.success(wxCommonMapper.selectSettlementByOrg(wxCommonQuery));
    }

    /**
     * @desc   : 查询供应商与客户
     * @author : 孙超
     * @date   : 2023/09/05 17:17
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getSupplierAndCustomer(WxCommonQuery wxCommonQuery) {
        return  null;
    }
}
