PickUpPointServiceImpl.java 11.3 KB
package com.diligrp.website.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.Resource;

import com.diligrp.website.dao.PickUpCityDao;
import com.diligrp.website.dao.PickUpPointDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.diligrp.website.domain.PickUpCity;
import com.diligrp.website.domain.PickUpPerson;
import com.diligrp.website.domain.PickUpPointDomain;
import com.diligrp.website.manager.PickUpCityManager;
import com.diligrp.website.manager.PickUpPointManager;
import com.diligrp.website.service.PickUpPointService;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.web.PageTemplate;

/**
 * <B>Description</B> TODO <br />
 * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
 * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
 * <B>Company</B> 地利集团
 *
 * @author liujie
 * @createTime 2014年8月13日 下午5:03:50
 */
@Service
public class PickUpPointServiceImpl implements PickUpPointService {

    @Resource
    private PickUpPointManager pickUpPointManager;
    @Resource
    private PickUpCityManager pickUpCityManager;

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#getPickInfo(com.diligrp
     * .website.util.dao.BaseQuery)
     */
    @Override
    public PageTemplate getPickInfo(BaseQuery bq) {
        try {
            PageTemplate page = new PageTemplate();
            List<PickUpPointDomain> list = pickUpPointManager.getPickInfo(bq);
            for (int i = 0; i < list.size(); i++) {
                list.get(i).getPersonList();
            }
            Integer totalSize = pickUpPointManager.getCountPickInfo(bq);
            page.setList(list);
            page.setCurrPage(bq.getCurrPage());
            page.setPageSize(bq.getPageSize());
            page.setTotalSize(totalSize);
            page.setQuery(bq);
            return page;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#getCountPickInfo(com.diligrp
     * .website.util.dao.BaseQuery)
     */
    @Override
    public Integer getCountPickInfo(BaseQuery bq) {
        try {
            return pickUpPointManager.getCountPickInfo(bq);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#savePickUpInfo(com.diligrp
     * .website.domain.PickUpPointDomain)
     */
    @Override
    public boolean savePickUpInfo(PickUpPointDomain pickUpPointDomain,
                                  List<String> personName, List<String> personTel, String cityDetail) {
        try {
            List<PickUpPerson> personlist = new ArrayList<PickUpPerson>();
            for (int i = 0; i < personName.size(); i++) {
                PickUpPerson person = new PickUpPerson();
                person.setContactName(personName.get(i).toString());
                person.setContactPhone(personTel.get(i).toString());
                personlist.add(person);
            }
            if (!StringUtils.isBlank(cityDetail)) {
                List<PickUpCity> citylist = new ArrayList<PickUpCity>();
                String[] city = cityDetail.split(",");
                List<?> list = Arrays.asList(city);
                for (int i = 0; i < list.size(); i++) {
                    PickUpCity pickCity = new PickUpCity();
                    pickCity.setCityId(Long.parseLong(String.valueOf(list
                            .get(i))));
                    citylist.add(pickCity);
                }
                pickUpPointDomain.setCityList(citylist);
            }
            pickUpPointDomain.setPersonList(personlist);
            pickUpPointDomain.setRecommend(1);
            return pickUpPointManager.savePickUpInfo(pickUpPointDomain);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#modifyPickUpInfo(com.diligrp
     * .website.domain.PickUpPointDomain)
     */
    @Override
    public boolean modifyPickUpInfo(PickUpPointDomain pickUpPointDomain,
                                    List<String> personName, List<String> personTel, String cityDetail) {
        try {
            List<PickUpPerson> personlist = new ArrayList<PickUpPerson>();
            for (int i = 0; i < personName.size(); i++) {
                PickUpPerson person = new PickUpPerson();
                person.setContactName(personName.get(i).toString());
                person.setContactPhone(personTel.get(i).toString());
                personlist.add(person);
            }
            if (!StringUtils.isBlank(cityDetail)) {
                List<PickUpCity> citylist = new ArrayList<PickUpCity>();
                String[] city = cityDetail.split(",");
                List<String> list = Arrays.asList(city);
                for (int i = 0; i < list.size(); i++) {
                    PickUpCity pickCity = new PickUpCity();
                    pickCity.setCityId(Long.parseLong(String.valueOf(list
                            .get(i))));
                    citylist.add(pickCity);
                }
                pickUpPointDomain.setCityList(citylist);
            }
            pickUpPointDomain.setPersonList(personlist);
            return pickUpPointManager.modifyPickUpInfo(pickUpPointDomain);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#modifyPickUpInfoDeafult
     * (com.diligrp.website.domain.PickUpPointDomain)
     */
    @Override
    public boolean modifyPickUpInfoDeafult(Long id) {
        try {
            return pickUpPointManager.modifyPickUpInfoDeafult(id);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#getPickUpPointDomainInfo
     * (java.lang.Long)
     */
    @Override
    public PickUpPointDomain getPickUpPointDomainInfo(Long id) {
        try {
            return pickUpPointManager.getPickUpPointDomainInfo(id);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#getRelationPickInfo(java
     * .lang.Long)
     */
    @Override
    public List<PickUpPointDomain> getRelationPickInfo(Long id) {
        try {
            return pickUpPointManager.getRelationPickInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#getNotMarketPickInfo()
     */
    @Override
    public List<PickUpPointDomain> getNotMarketPickInfo(Long pid) {
        try {
            List<PickUpPointDomain> list = pickUpPointManager.getRelationPickInfo(pid);
            List<PickUpPointDomain> pickList = pickUpPointManager.getNotMarketPickInfo();
            list.addAll(pickList);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /*
     * (non-Javadoc)
     * @see
     * com.diligrp.website.service.PickUpPointService#modifyRelationPoint(java
     * .util.Map)
     */
    @Override
    public boolean modifyRelationPoint(List<Long> list, Long pickId) {
        try {
            return pickUpPointManager.modifyRelationPoint(list, pickId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /* (non-Javadoc)
     * @see com.diligrp.website.service.PickUpPointService#getIsMarketPickUpInfo()
     */
    @Override
    public List<PickUpPointDomain> getIsMarketPickUpInfo() {
        try {
            return pickUpPointManager.getIsMarketPickUpInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /* (non-Javadoc)
     * @see com.diligrp.website.service.PickUpPointService#getIsNotMarketPickUpInfo()
     */
    @Override
    public List<PickUpPointDomain> getIsNotMarketPickUpInfo() throws Exception {
        return pickUpPointManager.getIsNotMarketPickUpInfo();
    }

    /* (non-Javadoc)
     * @see com.diligrp.website.service.PickUpPointService#getAllMarketPickUpInfo()
     */
    @Override
    public List<PickUpPointDomain> getAllMarketPickUpInfo() throws Exception {
        return pickUpPointManager.getAllMarketPickUpInfo();
    }

    /* (non-Javadoc)
     * @see com.diligrp.website.service.PickUpPointService#getCodeByPickUpInfo(java.lang.String)
     */
    @Override
    public PickUpPointDomain getCodeByPickUpInfo(String code) throws Exception {
        return pickUpPointManager.getCodeByPickUpInfo(code);
    }

    @Override
    public PickUpPointDomain getPickInfoByCityId(Long cityId) throws Exception {
        PickUpCity pickUpCity = pickUpCityManager.getPickIdByCityId(cityId);
        if (pickUpCity != null) {
            return pickUpPointManager.getPickUpPointDomainInfo(pickUpCity.getPickId());
        } else {
            return pickUpPointManager.getDefaultPickUpInfo();
        }
    }

    @Override
    public List<PickUpPointDomain> getPickUpInfoByName(String pickName) {
        return pickUpPointManager.getPickUpInfoByName(pickName);
    }

    @Override
    public List<PickUpPointDomain> getRecommendPickUp() {
        return pickUpPointManager.getRecommendPickUp();
    }

    @Override
    public List<PickUpPointDomain> getPickUpListByCityId(Long cityId) {
        List<PickUpCity> pickUpCityList = pickUpCityManager.getPickUpIdListByCityId(cityId);
        List<PickUpPointDomain> pickList = new ArrayList<PickUpPointDomain>();
        if (pickUpCityList != null && pickUpCityList.size() > 0) {
            for (int i = 0; i < pickUpCityList.size(); i++) {
                PickUpCity pickUpCity = pickUpCityList.get(i);
                try {
                    PickUpPointDomain pickUpPointDomain = pickUpPointManager.getPickUpPointDomainInfo(pickUpCity.getPickId());
                    pickList.add(pickUpPointDomain);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return pickList;
        }
        return null;
    }

    @Override
    public boolean configRecommend(PickUpPointDomain pickUpPointDomain) {
        try {
            return pickUpPointManager.configRecommend(pickUpPointDomain);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public List<PickUpPointDomain> getPickUpInfoByCityName(String cityName) {
        return pickUpPointManager.getPickUpInfoByCityName(cityName);
    }

    @Override
    public List<PickUpPointDomain> getAllPickUpListByCityId(Long cityId) {
        return pickUpPointManager.getAllPickUpListByCityId(cityId);
    }
}