DiliServiceCoverageServiceImpl.java 3.84 KB
package com.diligrp.website.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diligrp.website.domain.DataDictionary;
import com.diligrp.website.domain.DataDictionaryValue;
import com.diligrp.website.domain.DiliServiceCoverage;
import com.diligrp.website.manager.DiliServiceCoverageManager;
import com.diligrp.website.service.DataDictionaryService;
import com.diligrp.website.service.DiliServiceCoverageService;
import com.diligrp.website.util.dao.BaseQuery;
import com.diligrp.website.util.domain.Result;
import com.diligrp.website.util.web.BeanUtils;

/**
 * <B>Description</B>  <br />
 * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
 * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
 * <B>Company</B> 地利集团
 * @createTime 2014-6-3 11:33:00
 * @author template
 */
@Service
public class DiliServiceCoverageServiceImpl implements DiliServiceCoverageService {
    
    /**
     * 交割地, 提货点
     */
    private final static String CODE_THD = "DIC_PACKUP_ADDRESS";

    @Autowired
    private DiliServiceCoverageManager diliServiceCoverageManager;

    @Autowired
    private DataDictionaryService dataDictionaryService;

    public Result findOne(Long pk) {
        return Result.create(diliServiceCoverageManager.findOne(pk));
    }

    public Result save(DiliServiceCoverage diliServiceCoverage) {
        diliServiceCoverage.setCreated(new Timestamp(new Date().getTime()));
        diliServiceCoverage.setModified(new Timestamp(new Date().getTime()));
        return Result.create(diliServiceCoverageManager.save(diliServiceCoverage));
    }

    public Result update(DiliServiceCoverage diliServiceCoverage) {
        DiliServiceCoverage up = diliServiceCoverageManager.findOne(diliServiceCoverage.getId());
        if (up == null) {
            return Result.create(false);
        }
        up = BeanUtils.merge(up, diliServiceCoverage);
        up.setModified(new Timestamp(new Date().getTime()));

        return Result.create(diliServiceCoverageManager.update(up));
    }

    @Override
    public Result findByService(Long serviceId) {
        return Result.create(diliServiceCoverageManager.findByService(serviceId));
    }

    public Result findByServiceInfo(Long serviceId) {
        Result result = Result.create();
        List<Long> coverages = new ArrayList<Long>();
        if (serviceId != null && serviceId > 0) {
            List<DiliServiceCoverage> list = diliServiceCoverageManager.findByService(serviceId);
            for (DiliServiceCoverage dsc : list) {
                coverages.add(dsc.getCoverageId());
            }
        }
        DataDictionary data = dataDictionaryService.getDataDictionaryByCode(CODE_THD);
        if (data != null && data.getId() != null) {
            List<DataDictionaryValue> vals = dataDictionaryService.getDataDictionaryValue(data.getId());
            for (DataDictionaryValue ddv : vals) {
                if (coverages.contains(ddv.getId())) {
                    ddv.setDdId(1);
                } else {
                    ddv.setDdId(0);
                }
            }
            result.addResult(Result.RESULT_KEY_DEFAULT_VALUE, vals);
        }
        return result;
    }

    public Result find(BaseQuery bq) {
        return Result.create(diliServiceCoverageManager.find(bq));
    }

    public Result del(Long id){
        return Result.create(diliServiceCoverageManager.del(id));
    }

    /* (non-Javadoc)
     * @see com.diligrp.website.service.DiliServiceCoverageService#findServiceByPickId(java.lang.Long)
     */
    @Override
    public List<DiliServiceCoverage> findServiceByPickId(Long id) {
        return diliServiceCoverageManager.findServiceByPickId(id);
    }

}