package com.nmgs.service.impl;

import com.nmgs.mapper.Mapper;
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 java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class RotationServiceImpl {
    @Autowired
    public Mapper mapperI;
    private static String  DBType= PropertiesUtil.getValue("DBType");
    private String sql = "select pic.ID,pic.RETATIONPIC,pic.JUMPURL,pic.ORDERNO，pic.RETATIONPICNAME,(SELECT IPS.BAK1 FROM INTEGRAL_PUBLIC_SET ips WHERE IPS.PARAMCODE='PICURL') AS PICURL from INTEGRAL_ROTATION pic where 1=1  ";

    public List getRotationList(String picType) {
        List list=null;
        List retList=new ArrayList();
        String sqlTemp=sql;
        try{
            if(!PubTools.isNull(picType)){
                sqlTemp += " and pic.PICTYPE = '"+picType+"'";
            }
            sqlTemp +=" ORDER BY pic.ORDERNO  ";
            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("RETATIONPIC");
                    String s = PubTools.ClobToString( o);
                    if(!PubTools.isNull(s)){
                        obj1.remove("RETATIONPIC");
                        obj1.put("RETATIONPIC",s);
                    }else{
                        obj1.remove("RETATIONPIC");
                        obj1.put("RETATIONPIC","");
                    }
                    retList.add(obj1);
                }
            }
        }catch (Exception e){
            LogUtil.WriteLog_Error("查询轮播图列表失败：===>"+e.getMessage(),"ServiceAreaPicServiceImpl");
            return retList=new ArrayList();
        }
        return retList;
    }


}
