NoticeServiceImpl.java 5.62 KB
package com.bsth.data.notice;

import com.bsth.common.ResponseCode;
import com.bsth.data.gpsdata_v2.cache.GeoCacheData;
import com.bsth.data.gpsdata_v2.entity.StationRoute;
import com.bsth.data.notice.entity.*;
import com.bsth.service.impl.BaseServiceImpl;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class NoticeServiceImpl extends BaseServiceImpl<Notice, Long> implements NoticeService {

    Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public Map<String, Object> findList(Map<String, String> map) {
        Map<String, Object> rs = new HashMap();
        try {

            String lineCodes = map.get("lineCodes") == null ? "" : map.get("lineCodes");
            Date startDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = sdf.format(startDate);
            String sql = "select * from bsth_t_notice where NOTICE_TIME >=\""+time+"\" and (NOTICE_XL in("+lineCodes+") "+" or NOTICE_QY is not null) and STATUS !=2 ";
            List<Notice> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(Notice.class));
            for (Notice notice : list) {
                notice.setNOTICE_TFSJ(TFSJ.getDescription(notice.getNOTICE_TFSJ()));
                notice.setNOTICE_SJYX(SJYX.getDescription(notice.getNOTICE_SJYX()));
                notice.setNOTICE_QY(QY.getDescription(notice.getNOTICE_QY()));
                notice.setNOTICE_GG(GG.getDescription(notice.getNOTICE_GG()));
            }
            rs.put("status", ResponseCode.SUCCESS);
            rs.put("list", list);
        }
        catch (Exception e){
            log.error("", e);
            rs.put("status", ResponseCode.ERROR);
            rs.put("msg", e.getMessage());
        }
        return rs;
    }

    @Override
    public Map<String, Object> getNotice(Map<String, String> map) {
        Map<String, Object> rs = new HashMap();
        ListMultimap<String, String> result = Multimaps.synchronizedListMultimap(ArrayListMultimap.create());
        try {

            String stations = map.get("stations") == null ? "" : map.get("stations");
            String lineCodes = map.get("lineCodes") == null ? "" : map.get("lineCodes");
            Date startDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd  HH:mm:ss");
            String time = sdf.format(startDate);
            String sql = "select * from bsth_t_notice where NOTICE_TIME >=\""+time+"\" and (NOTICE_XL in("+lineCodes+") "+" or NOTICE_QY is not null) and STATUS !=2";
            List<Notice> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper(Notice.class));
            for (Notice notice : list) {
                if(notice.getNOTICE_TYPE()==1){
                    StringBuffer sb=new StringBuffer();
                    List<StationRoute> stationRoutes=GeoCacheData.getStationRoute(notice.getNOTICE_XL(),Integer.parseInt(notice.getNOTICE_XSFX()));
                    /*申港3路开往鸿音路南芦公路方向,临时改道不经过鸿音路两港大道站点,请乘客合理安排出行。*/
                    sb.append(notice.getNOTICE_XLNAME()+"开往"+stationRoutes.get(stationRoutes.size()-1).getName()+"方向,");
                    sb.append("由于"+ TFSJ.getDescription(notice.getNOTICE_TFSJ()));
                    if("1".equals(notice.getNOTICE_SJYX())){
                        sb.append("不经过"+notice.getNOTICE_STATIONNAME()+"站点");
                    }else if("2".equals(notice.getNOTICE_SJYX())){
                        sb.append("可能出现"+ SJYX.getDescription(notice.getNOTICE_SJYX()));
                    }
                    sb.append(",请乘客合理安排出行。");
                    result.put(notice.getNOTICE_XL(),sb.toString());
                }else if(notice.getNOTICE_TYPE()==2){
                    result.put("area", GG.getDescription(notice.getNOTICE_GG()));
                }

            }
            rs.put("status", ResponseCode.SUCCESS);
            Map m=result.asMap();
            List list1=new ArrayList();
            Set<String> keys=m.keySet();
            for (String key : keys) {
                Map m2=new HashMap();
                m2.put("lineId",key);
                m2.put("msg",m.get(key));
                list1.add(m2);
            }

            rs.put("notice", list1);
        }
        catch (Exception e){
            log.error("", e);
            rs.put("status", ResponseCode.ERROR);
            rs.put("msg", e.getMessage());
        }
        return rs;
    }
    @Override
    public Map<String, Object> deleteInfo(Notice rr) {
        Map<String, Object> map = new HashMap<>();
        try{
            Long id = rr.getID();
            String bbr = rr.getNOTICE_BBR();

            jdbcTemplate.update("UPDATE bsth_t_notice SET STATUS = 2,NOTICE_BBR = ? WHERE ID = ? ",bbr,id);
            map.put("status", ResponseCode.SUCCESS);
        }catch(DataIntegrityViolationException de){
            map.put("status", ResponseCode.ERROR);
            map.put("msg", "“完整性约束”校验失败,请检查要删除的对象是否存在外键约束");
        }
        return map;
    }
}