package com.gree.mall.manager.logic.engin;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.bean.admin.AdminUserCom;
import com.gree.mall.manager.bean.common.RegionBean;
import com.gree.mall.manager.bean.engin.EnginPayManageBean;
import com.gree.mall.manager.bean.engin.EnginPayManageGatherVO;
import com.gree.mall.manager.bean.engin.EnginPayManageImport;
import com.gree.mall.manager.bean.engin.EnginPayManageVO;
import com.gree.mall.manager.commonmapper.MaterialMapper;
import com.gree.mall.manager.enums.admin.AdminWebsitTypeEnum;
import com.gree.mall.manager.enums.engin.EnginPayManageStatusEnum;
import com.gree.mall.manager.enums.material.StateEnum;
import com.gree.mall.manager.enums.material.WebsitGoodsTypeEnum;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.logic.common.CommonLogic;
import com.gree.mall.manager.logic.common.LbsAmapLogic;
import com.gree.mall.manager.plus.entity.*;
import com.gree.mall.manager.plus.service.*;
import com.gree.mall.manager.utils.excel.ExcelUtils;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
public class EnginPayManageLogic {

    private final CommonLogic commonLogic;
    private final MaterialMapper materialMapper;
    private final EnginPayManageService enginPayManageService;
    private final EnginPayManageItemService enginPayManageItemService;
    private final EnginPayManageRecordService enginPayManageRecordService;
    private final WebsitGoodsAloneService websitGoodsAloneService;
    private final AdminWebsitService adminWebsitService;
    private final OrderSmallTypeService orderSmallTypeService;
    private final LbsAmapLogic lbsAmapLogic;
    private final RegionService regionService;

    public IPage<EnginPayManageVO> list(ZfireParamBean zfireParamBean) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        FieldUtils.materialParam(zfireParamBean, EnginPayManageVO.class, adminUser);

        IPage<EnginPayManageVO> page = materialMapper.enginPayManageList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);

        return page;
    }

    public EnginPayManageBean detail(String id) {
        final EnginPayManage manage = enginPayManageService.getById(id);
        EnginPayManageBean bean = new EnginPayManageBean();
        BeanUtils.copyProperties(manage, bean);

        final List<EnginPayManageItem> items = enginPayManageItemService.lambdaQuery()
                .eq(EnginPayManageItem::getEnginPayManageId, id)
                .list();

        final List<EnginPayManageRecord> records = enginPayManageRecordService.lambdaQuery()
                .eq(EnginPayManageRecord::getEnginPayManageId, id)
                .orderByDesc(EnginPayManageRecord::getId)
                .list();

        bean.setItems(items);
        bean.setRecords(records);

        return bean;
    }

    @Transactional
    public void save(HttpServletRequest request, EnginPayManageBean bean) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        if (StringUtils.isBlank(bean.getWebsitId())
                || StringUtils.isBlank(bean.getWebsitName())) {
            throw new RemoteServiceException("网点名称不能为空");
        }
        if (StringUtils.isBlank(bean.getOrderSmallType())
                || StringUtils.isBlank(bean.getOrderSmallTypeText())) {
            throw new RemoteServiceException("工单类型不能为空");
        }
        if (StringUtils.isBlank(bean.getProjectNo())) {
            throw new RemoteServiceException("工程编号不能为空");
        }
        if (StringUtils.isBlank(bean.getProjectName())) {
            throw new RemoteServiceException("工程名称不能为空");
        }
        if (StringUtils.isBlank(bean.getSalesNo())) {
            throw new RemoteServiceException("销售单号不能为空");
        }
        if (StringUtils.isBlank(bean.getSalesWebsit())) {
            throw new RemoteServiceException("销售网点不能为空");
        }
        if (StringUtils.isBlank(bean.getGoodsType())) {
            throw new RemoteServiceException("费用类型不能为空");
        }
        if (StringUtils.isBlank(bean.getCustomerName())) {
            throw new RemoteServiceException("客户名称不能为空");
        }
        if (StringUtils.isBlank(bean.getLinkName())) {
            throw new RemoteServiceException("联系人不能为空");
        }
        if (StringUtils.isBlank(bean.getCustomerMobile())) {
            throw new RemoteServiceException("客户电话不能为空");
        }
        if (StringUtils.isBlank(bean.getAddress())) {
            throw new RemoteServiceException("详细地址不能为空");
        }
        if (CollectionUtil.isEmpty(bean.getItems())) {
            throw new RemoteServiceException("产品信息不能为空");
        }
        bean.setId(IdWorker.getIdStr());
        if (Objects.nonNull(adminUser.getAdminCompanyWechat())) {
            bean.setCompanyWechatId(adminUser.getAdminCompanyWechat().getCompanyWechatId());
            bean.setCompanyWechatName(adminUser.getAdminCompanyWechat().getCompanyName());
        }

        BigDecimal totalSaleAmount = BigDecimal.ZERO;

        for (EnginPayManageItem item : bean.getItems()) {
            item.setEnginPayManageId(bean.getId());
            item.setAmount(item.getQty().multiply(item.getMarketPrice()));
            totalSaleAmount = totalSaleAmount.add(item.getAmount());
        }
        bean.setTotalSalesAmount(totalSaleAmount);
        bean.setStatus(EnginPayManageStatusEnum.WAIT.getKey());
        bean.insert();
        enginPayManageItemService.saveBatch(bean.getItems());
    }

    @Transactional
    public void confirm(HttpServletRequest request, String id) {
        AdminUserCom adminUser = commonLogic.getAdminUser();

        String companyWechatId = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyWechatId() : null;
        enginPayManageService.lambdaUpdate()
                .set(EnginPayManage::getStatus, EnginPayManageStatusEnum.WAIT_PAY.getKey())
                .set(EnginPayManage::getConfirmBy, adminUser.getNickName())
                .set(EnginPayManage::getConfirmTime, DateUtil.date())
                .eq(EnginPayManage::getCompanyWechatId, companyWechatId)
                .eq(EnginPayManage::getStatus, EnginPayManageStatusEnum.WAIT.getKey())
                .eq(EnginPayManage::getId, id)
                .update();
    }

    @Transactional
    public void pay(String id, BigDecimal amount, String fileUrl, String payRemark) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        String companyWechatId = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyWechatId() : null;

        final EnginPayManage manage = enginPayManageService.getById(id);

        final BigDecimal totalPayAmount = manage.getTotalPayAmount().add(amount);

        if (totalPayAmount.compareTo(manage.getTotalSalesAmount()) > 0) {
            throw new RemoteServiceException("收款总额不能大于销售总额, 请检查");
        }

        String status = manage.getTotalSalesAmount().compareTo(totalPayAmount) > 0 ? EnginPayManageStatusEnum.PART_PAY.getKey() : EnginPayManageStatusEnum.PAY.getKey();

        final DateTime curDate = DateUtil.date();

        final boolean update = enginPayManageService.lambdaUpdate()
                .set(EnginPayManage::getStatus, status)
                .set(EnginPayManage::getTotalPayAmount, totalPayAmount)
                .set(EnginPayManage::getLastUpdateBy, adminUser.getNickName())
                .set(EnginPayManage::getLastUpdateTime, curDate)
                .eq(EnginPayManage::getCompanyWechatId, companyWechatId)
                .eq(EnginPayManage::getId, id)
                .update();

        if (update) {
            new EnginPayManageRecord()
                    .setEnginPayManageId(id)
                    .setPayAmount(amount)
                    .setFileUrl(fileUrl)
                    .setPayRemark(payRemark)
                    .setStatus(status)
                    .setLastUpdateBy(adminUser.getNickName())
                    .setLastUpdateTime(curDate)
                    .insert();
        }
    }

    public Object importData(MultipartFile file) throws IOException {
        AdminUserCom adminUser = commonLogic.getAdminUser();

        String companyWechatId = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyWechatId() : null;
        String companyName = Objects.nonNull(adminUser.getAdminCompanyWechat()) ? adminUser.getAdminCompanyWechat().getCompanyName() : null;

        List<Object> objects = ExcelUtils.importExcel(file);
        List<EnginPayManage> orderList = new ArrayList<>();
        List<EnginPayManageItem> orderItemList = new ArrayList<>();
        List<EnginPayManageImport> orderImportsList = new ArrayList<>();

        List<AdminWebsit> websitList = adminWebsitService.lambdaQuery()
                .eq(AdminWebsit::getCompanyWechatId, companyWechatId)
                .eq(AdminWebsit::getType, AdminWebsitTypeEnum.C.getKey())
//                .eq(AdminWebsit::getStatus, true)
                .list();

        final List<OrderSmallType> smallTypeList = orderSmallTypeService.lambdaQuery()
                .eq(OrderSmallType::getCompanyWechatId, companyWechatId)
                .eq(OrderSmallType::getStatus, true)
                .list();

        final List<WebsitGoodsAlone> materialList = websitGoodsAloneService.lambdaQuery()
                .eq(WebsitGoodsAlone::getCompanyWechatId, companyWechatId)
                .eq(WebsitGoodsAlone::getStatus, StateEnum.ON.getKey())
                .eq(WebsitGoodsAlone::getGoodsType, WebsitGoodsTypeEnum.M.getKey())
                .list();

        final List<WebsitGoodsAlone> partsList = websitGoodsAloneService.lambdaQuery()
                .eq(WebsitGoodsAlone::getCompanyWechatId, companyWechatId)
                .eq(WebsitGoodsAlone::getStatus, StateEnum.ON.getKey())
                .eq(WebsitGoodsAlone::getGoodsType, WebsitGoodsTypeEnum.P.getKey())
                .list();

        final Map<String, WebsitGoodsAlone> materialMap = materialList.stream()
                .collect(Collectors.toMap(WebsitGoodsAlone::getGoodsName, Function.identity()));

        final Map<String, WebsitGoodsAlone> partsMap = partsList.stream()
                .collect(Collectors.toMap(WebsitGoodsAlone::getGoodsCode, Function.identity()));

        Map<String, AdminWebsit> websitMap = websitList.stream()
                .collect(Collectors.toMap(AdminWebsit::getName, Function.identity()));

        final Map<String, OrderSmallType> smallTypeMap = smallTypeList.stream()
                .collect(Collectors.toMap(OrderSmallType::getOrderSmallTypeText, Function.identity()));

        for (int i = 0; i < objects.size(); i++) {
            List<Object> row = (List<Object>) objects.get(i);
            if (row.size() < 15) {
                row.add("");
                row.add("");
            }
            if (row.size() < 16) {
                row.add("");
            }
            if (Objects.isNull(row.get(0))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 辅材名称\\配件编码不能为空");
            }
            if (Objects.isNull(row.get(1))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 销售价格不能为空");
            }
            if (Objects.isNull(row.get(2))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 数量不能为空");
            }
            if (Objects.isNull(row.get(3))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 网点名称不能为空");
            }
            if (Objects.isNull(row.get(4))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 工单类型不能为空");
            }
            if (Objects.isNull(row.get(5))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 工程编号不能为空");
            }
            if (Objects.isNull(row.get(6))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 工程名称不能为空");
            }
            if (Objects.isNull(row.get(7))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 销售单号不能为空");
            }
            if (Objects.isNull(row.get(8))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 销售网点不能为空");
            }
            if (Objects.isNull(row.get(9))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 费用类型不能为空");
            }
            if (Objects.isNull(row.get(10))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 客户名称不能为空");
            }
            if (Objects.isNull(row.get(11))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 详细地址不能为空");
            }
            if (Objects.isNull(row.get(12))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 联系人不能为空");
            }
            if (Objects.isNull(row.get(13))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 客户电话不能为空");
            }

            String goodsStr = (String) row.get(0);
            String salesPriceStr = (String) row.get(1);
            String qtyStr = (String) row.get(2);
            String websitNameStr = (String) row.get(3);
            String smallTypeStr = (String) row.get(4);
            String projectNo = (String) row.get(5);
            String projectName = (String) row.get(6);
            String salesNo = (String) row.get(7);
            String salesWebsit = (String) row.get(8);
            String goodsTypeStr = (String) row.get(9);
            String customerName = (String) row.get(10);
            String linkName = (String) row.get(11);
            String customerMobile = (String) row.get(12);
            String address = (String) row.get(13);
            String customerMobile2 = (String) row.get(14);
            String remark = (String) row.get(15);
            BigDecimal salesPrice = BigDecimal.ZERO;
            BigDecimal qty = BigDecimal.ZERO;

            if (!websitMap.containsKey(websitNameStr)) {
                throw new RemoteServiceException("第" + (i+1) + "行, 网点名称不存在");
            }
            final AdminWebsit adminWebsit = websitMap.get(websitNameStr);

            if (!smallTypeMap.containsKey(smallTypeStr)) {
                throw new RemoteServiceException("第" + (i+1) + "行, 工单类型不存在");
            }
            final OrderSmallType smallType = smallTypeMap.get(smallTypeStr);

            if (!(WebsitGoodsTypeEnum.M.getRemark().equals(goodsTypeStr)
                    || WebsitGoodsTypeEnum.P.getRemark().equals(goodsTypeStr))) {
                throw new RemoteServiceException("第" + (i+1) + "行, 费用类型不存在");
            }
            final String key = WebsitGoodsTypeEnum.M.getRemark().equals(goodsTypeStr) ? WebsitGoodsTypeEnum.M.getKey() : WebsitGoodsTypeEnum.P.getKey();

            if (key.equals(WebsitGoodsTypeEnum.M.getKey()) && !materialMap.containsKey(goodsStr)) {
                throw new RemoteServiceException("第" + (i+1) + "行, 辅材名称不存在");
            }

            if (key.equals(WebsitGoodsTypeEnum.P.getKey()) && !partsMap.containsKey(goodsStr)) {
                throw new RemoteServiceException("第" + (i+1) + "行, 配件编码不存在");
            }

            WebsitGoodsAlone alone;
            if (key.equals(WebsitGoodsTypeEnum.M.getKey())) {
                alone = materialMap.get(goodsStr);
            } else {
                alone = partsMap.get(goodsStr);
            }


            try {
                if (StringUtils.isNotBlank(salesPriceStr)) {
                    salesPrice = new BigDecimal(salesPriceStr);
                }
            } catch (Exception e) {
                throw new RemoteServiceException("第" + (i+1) + "行, 销售价格异常");
            }

            try {
                if (StringUtils.isNotBlank(qtyStr)) {
                    qty = new BigDecimal(qtyStr);
                }
            } catch (Exception e) {
                throw new RemoteServiceException("第" + (i+1) + "行, 数量异常");
            }

            String location = lbsAmapLogic.getLocationByAddress(address);
            RegionBean regionBean = lbsAmapLogic.getRegionByLngLat(location);
            Region region = getRegion(regionBean.getProvinceName(), regionBean.getCityName(), regionBean.getAreaName(), regionBean.getName());
            if(region == null){
                throw new RemoteServiceException("第" + (i+1) + "行, 地址【"+address+"】解析失败");
            }

            EnginPayManageImport manageImport = new EnginPayManageImport();
            manageImport.setCompanyWechatId(companyWechatId)
                    .setCompanyWechatName(companyName)
                    .setWebsitId(adminWebsit.getWebsitId())
                    .setWebsitName(adminWebsit.getName())
                    .setOrderSmallType(smallType.getId())
                    .setOrderSmallTypeText(smallType.getOrderSmallTypeText())
                    .setProjectName(projectName)
                    .setProjectNo(projectNo)
                    .setSalesNo(salesNo)
                    .setSalesWebsit(salesWebsit)
                    .setGoodsType(key)
                    .setCustomerName(customerName)
                    .setLinkName(linkName)
                    .setCustomerMobile(customerMobile)
                    .setCustomerMobile2(customerMobile2)
                    .setAddress(address)
                    .setRemark(remark)
                    .setRegion(region)
                    .setRegionBean(regionBean)
                    .setGoodsAlone(alone)
                    .setSalesPrice(salesPrice)
                    .setQty(qty);

            orderImportsList.add(manageImport);
        }

        if (CollectionUtil.isNotEmpty(orderImportsList)) {
            // 以工程编号、网点分组
            Map<String, List<EnginPayManageImport>> serviceGroupMap = orderImportsList.stream()
                    .collect(Collectors.groupingBy(v -> v.getProjectNo() + v.getWebsitId()));

            for (Map.Entry<String, List<EnginPayManageImport>> entry : serviceGroupMap.entrySet()) {
                BigDecimal totalSalesAmount = BigDecimal.ZERO;
                EnginPayManage order = new EnginPayManage();

                order.setId(IdWorker.getIdStr());

                Map<String, EnginPayManageItem> itemMap = new HashMap<>();

                for (EnginPayManageImport orderImport : entry.getValue()) {
                    if (itemMap.containsKey(orderImport.getGoodsAlone().getGoodsId())) {
                        EnginPayManageItem item = itemMap.get(orderImport.getGoodsAlone().getGoodsId());
                        item.setQty(item.getQty().add(orderImport.getQty()))
                                .setAmount(item.getMarketPrice().multiply(item.getQty()));
                        continue;
                    }
                    EnginPayManageItem item = new EnginPayManageItem();
                    item.setId(IdWorker.getIdStr())
                            .setEnginPayManageId(order.getId())
                            .setGoodsId(orderImport.getGoodsAlone().getGoodsId())
                            .setGoodsName(orderImport.getGoodsAlone().getGoodsName())
                            .setGoodsCode(orderImport.getGoodsAlone().getGoodsCode())
                            .setCategoryName(orderImport.getGoodsAlone().getCategoryName())
                            .setGoodsSpecification(orderImport.getGoodsAlone().getGoodsSpecification())
                            .setUnit(orderImport.getGoodsAlone().getGoodsStockUnit())
                            .setMarketPrice(orderImport.getSalesPrice())
                            .setQty(orderImport.getQty())
                            .setAmount(orderImport.getSalesPrice().multiply(orderImport.getQty()));

                    itemMap.put(orderImport.getGoodsAlone().getGoodsId(), item);

                }

                for (EnginPayManageItem value : itemMap.values()) {
                    totalSalesAmount = totalSalesAmount.add(value.getAmount());
                }

                order.setCompanyWechatId(entry.getValue().get(0).getCompanyWechatId());
                order.setCompanyWechatName(entry.getValue().get(0).getCompanyWechatName());
                order.setWebsitId(entry.getValue().get(0).getWebsitId());
                order.setWebsitName(entry.getValue().get(0).getWebsitName());
                order.setOrderSmallType(entry.getValue().get(0).getOrderSmallType());
                order.setOrderSmallTypeText(entry.getValue().get(0).getOrderSmallTypeText());
                order.setProjectName(entry.getValue().get(0).getProjectName());
                order.setProjectNo(entry.getValue().get(0).getProjectNo());
                order.setSalesNo(entry.getValue().get(0).getSalesNo());
                order.setSalesWebsit(entry.getValue().get(0).getSalesWebsit());
                order.setGoodsType(entry.getValue().get(0).getGoodsType());
                order.setCustomerName(entry.getValue().get(0).getCustomerName());
                order.setLinkName(entry.getValue().get(0).getLinkName());
                order.setCustomerMobile(entry.getValue().get(0).getCustomerMobile());
                order.setCustomerMobile2(entry.getValue().get(0).getCustomerMobile2());
                order.setAddress(entry.getValue().get(0).getAddress());
                order.setTotalSalesAmount(totalSalesAmount);
                order.setRemark(entry.getValue().get(0).getRemark());
                order.setProvinceId(entry.getValue().get(0).getRegion().getProvinceCode())
                        .setProvince(entry.getValue().get(0).getRegion().getProvinceName())
                        .setCityId(entry.getValue().get(0).getRegion().getCityCode())
                        .setCity(entry.getValue().get(0).getRegion().getCityName())
                        .setAreaId(entry.getValue().get(0).getRegion().getAreaCode())
                        .setArea(entry.getValue().get(0).getRegion().getAreaName())
                        .setStreetId(entry.getValue().get(0).getRegion().getId())
                        .setStreet(entry.getValue().get(0).getRegion().getName());

                orderItemList.addAll(itemMap.values());

                orderList.add(order);
            }

            enginPayManageService.saveBatch(orderList);
            enginPayManageItemService.saveBatch(orderItemList);
        }

        return null;
    }

    public IPage<EnginPayManageGatherVO> gatherList(ZfireParamBean zfireParamBean) {
        AdminUserCom adminUser = commonLogic.getAdminUser();
        FieldUtils.materialParam(zfireParamBean, EnginPayManageGatherVO.class, adminUser);

        IPage<EnginPayManageGatherVO> page = materialMapper.enginPayManageGatherList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);

        if (CollectionUtil.isNotEmpty(page.getRecords())) {
            final List<String> projectList = page.getRecords().stream()
                    .map(EnginPayManageGatherVO::getProjectNo)
                    .collect(Collectors.toList());

            final List<EnginPayManageGatherVO> vos = materialMapper.enginPayManageGatherLastUpdate(page.getRecords().get(0).getCompanyWechatId(), projectList);

            final Map<String, EnginPayManageGatherVO> voMap = vos.stream().collect(Collectors.toMap(EnginPayManageGatherVO::getProjectNo, Function.identity()));

            for (EnginPayManageGatherVO record : page.getRecords()) {
                if (record.getTotalNotPayAmount().compareTo(BigDecimal.ZERO) == 0) {
                    record.setStatus(EnginPayManageStatusEnum.PAY);
                }
                if (record.getTotalNotPayAmount().compareTo(BigDecimal.ZERO) > 0
                        && record.getTotalNotPayAmount().compareTo(record.getTotalSalesAmount()) < 0) {
                    record.setStatus(EnginPayManageStatusEnum.PART_PAY);
                }
                if (record.getTotalNotPayAmount().compareTo(record.getTotalSalesAmount()) == 0) {
                    record.setStatus(EnginPayManageStatusEnum.WAIT_PAY);
                }
                final EnginPayManageGatherVO vo = voMap.get(record.getProjectNo());
                if (Objects.nonNull(vo)) {
                    record.setLastUpdateBy(vo.getLastUpdateBy());
                    record.setLastUpdateTime(vo.getLastUpdateTime());
                }
            }
        }

        return page;
    }

    private Region getRegion(String province,String city,String area,String street){
        Region one = regionService.lambdaQuery().eq(Region::getProvinceName, province).eq(Region::getCityName, city).eq(Region::getAreaName, area).eq(Region::getName, street).one();
        return one;
    }
}
