package com.nmgs.service.impl;

import com.nmgs.mapper.Mapper;
import com.nmgs.service.IServiceAreaSpecialService;
import com.nmgs.util.LogUtil;
import com.nmgs.util.PubTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Service
@Slf4j
public class ServiceAreaSpecialServiceImpl implements IServiceAreaSpecialService {
        @Autowired
        private Mapper mapperI;
        private String sql="     select\n" +
                " special.ID,\n" +
                " special.SERVICEID,\n" +
                " special.PICDATA,\n" +
                " (SELECT IPS.BAK1 FROM INTEGRAL_PUBLIC_SET ips WHERE IPS.PARAMCODE='PICURL') AS PICURL,\n" +
                " special.SPECIALNAME,\n" +
                " area.AREANAME as areaName\n" +
                " from\n" +
                "  SERVICE_AREA_SPECIAL_TABLE special\n" +
                "  left join SERVICE_AREA_TABLE area on area.ID = special.SERVICEID";

    @Override
    public List getServiceAreaSpecialList(String serviceId) {
        List list=null;
        List retList=new ArrayList();
        try{
            String sqlTemp=sql;
            if(!PubTools.isNull(serviceId)){
                sqlTemp += " and special.SERVICEID = '"+serviceId+"'";
            }
            sqlTemp += " order by area.AREANAME";
            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(),"ServiceAreaSpecialServiceImpl");
            return new ArrayList();
        }
        return retList;
    }
}
