package com.usky.fire.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usky.fire.domain.DemStore;
import com.usky.fire.mapper.DemStoreMapper;
import com.usky.fire.service.DemStoreService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 仓库信息表 服务实现类
 * </p>
 *
 * @author ZYJ
 * @since 2023-01-16
 */
@Service
public class DemStoreServiceImpl extends AbstractCrudService<DemStoreMapper, DemStore> implements DemStoreService {
    @Override
    public List<Object> storeScatterer(String streetTown){
        List<Object> list = new ArrayList<>();
        LambdaQueryWrapper<DemStore> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(StringUtils.isNotBlank(streetTown), DemStore::getPoliceStation, streetTown);
        List<DemStore> list1 = this.list(queryWrapper);

        if(CollectionUtils.isNotEmpty(list1)){
            for(int i=0;i<list1.size();i++){
                Map<String, Object> map = new HashMap<>();
                map.put("companyType", list1.get(i).getCompanyType());
                map.put("companyNature", list1.get(i).getCompanyNature());
                map.put("delegateName", list1.get(i).getDelegateName());
                map.put("socialCode", list1.get(i).getSocialCode());
                map.put("companyName", list1.get(i).getCompanyName());
                map.put("policeStation", list1.get(i).getPoliceStation());
                map.put("address", list1.get(i).getAddress());
                map.put("longitude", list1.get(i).getLongitude());
                map.put("latitude", list1.get(i).getLatitude());
                map.put("fireDutyName", list1.get(i).getFireDutyName());
                map.put("fireManageName", list1.get(i).getFireManageName());
                map.put("linkPhone", list1.get(i).getLinkPhone());
                map.put("fireSafetyManage", list1.get(i).getFireSafetyManage());
                map.put("companyArea", list1.get(i).getCompanyArea());
                map.put("industryType", list1.get(i).getIndustryType());
                map.put("cleanRoom", list1.get(i).getCleanRoom());
                map.put("organizationForm", list1.get(i).getOrganizationForm());
                map.put("gridNo", list1.get(i).getGridNo());
                map.put("particularYear", list1.get(i).getParticularYear());
                map.put("submitTime", (list1.get(i).getSubmitTime()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));

                list.add(map);
            }
        }

        return list;
    }
}
