package com.nmgs.service.impl;

import com.nmgs.mapper.Mapper;
import com.nmgs.mapper.ServiceAreaPicMapper;
import com.nmgs.service.IServiceAreaService;
import com.nmgs.util.LogUtil;
import com.nmgs.util.PropertiesUtil;
import com.nmgs.util.PubTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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


@Service
@Slf4j
public class ServiceAreaPicServiceImpl  {
    @Autowired
    public Mapper mapperI;
    private static String  DBType= PropertiesUtil.getValue("DBType");
    private String sql = "select pic.ID,pic.SERVICEID,pic.PICDATA,(SELECT IPS.BAK1 FROM INTEGRAL_PUBLIC_SET ips WHERE IPS.PARAMCODE='PICURL') AS PICURL from SERVICE_AREA_PIC_TABLE pic where 1=1  ";

    public List getServiceAreaPicList(String serviceId) {
        List list=null;
        String sqlTemp=sql;
        List retList=new ArrayList();
        try{
            if(!PubTools.isNull(serviceId)){
                sqlTemp += " and pic.SERVICEID = '"+serviceId+"'";
            }
            list= this.mapperI.selectforlist(sqlTemp);
            if(list != null && list.size()>0){
                for(Object obj:list){
                    Map<String, Object> obj1 = (Map<String, Object>) obj;
                    Object o=obj1.get("PICDATA");
                    String s = PubTools.ClobToString( o);
                    if(!PubTools.isNull(s)){
                        obj1.remove("PICDATA");
                        obj1.put("PICDATA",s);
                    }else{
                        obj1.remove("PICDATA");
                        obj1.put("PICDATA","");
                    }
                    retList.add(obj1);
                }
            }else{
                retList=list;
            }
        }catch (Exception e){
            LogUtil.WriteLog_Error("查询服务区图片列表失败：===>"+e.getMessage(),"ServiceAreaPicServiceImpl");
            return retList=null;
        }
        return retList;
    }


}
