DiliServiceServiceImpl.java 5.19 KB
package com.diligrp.website.service.impl;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.diligrp.website.domain.DiliService;
import com.diligrp.website.manager.DiliServiceManager;
import com.diligrp.website.rpc.UserRPCService;
import com.diligrp.website.service.DataDictionaryService;
import com.diligrp.website.service.DiliServiceCoverageService;
import com.diligrp.website.service.DiliServiceService;
import com.diligrp.website.service.PickUpPointService;
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 DiliServiceServiceImpl implements DiliServiceService {
    private final static Logger LOG = LoggerFactory
            .getLogger(DiliServiceServiceImpl.class);

    @Autowired
    private DiliServiceManager diliServiceManager;

    @Autowired
    private DataDictionaryService dataDictionaryService;


    @Autowired
    private DiliServiceCoverageService diliServiceCoverageService;

    @Autowired
    private UserRPCService userRPCService;

    @Autowired
    private PickUpPointService pickUpPointService;
    public Result findOne(Long pk) {
        return Result.create(diliServiceManager.findOne(pk));
    }

    public Result show(Long pk) {
        Result result = Result.create();
        DiliService service = diliServiceManager.findOne(pk);
        result.addResult(Result.RESULT_KEY_DEFAULT_VALUE, service);
      try{
          result.addResult("coverage",  diliServiceCoverageService.findByService(pk).getAllResult());
          result.addResult("datas", pickUpPointService.getAllMarketPickUpInfo());
      }catch(Exception e){
          e.printStackTrace();
      }
       
//        try {
//            UserInfoResp user = userRPCService.getUserInfoById(service.getCreator());
//            result.addResult("creator", user);
//        } catch (Exception e) {
//            LOG.warn("查询用户信息出错");
//        }
        return result;
    }

    public Result save(DiliService diliService, Long[] coverages) {
        diliService.setCreated(new Timestamp(new Date().getTime()));
        diliService.setModified(new Timestamp(new Date().getTime()));
        if (diliService.getCode() == null || diliService.getCode().equals("")) {
            LOG.warn("必须填写CODE!");
            return Result.create(false);
        }
        DiliService item = diliServiceManager.findByCode(diliService.getCode());
        if (item != null) {
            LOG.warn("服务已存在");
            return Result.create(false);
        }
        //默认上架
        diliService.setPutawayDate(new Timestamp(new Date().getTime()));
//        diliService.setStatus(DiliService.STATUS_PUTAWAY);
        return Result.create(diliServiceManager.save(diliService, coverages));
    }

    public Result update(DiliService diliService, Long[] coverages) {
        DiliService up = diliServiceManager.findOne(diliService.getId());
        if (up == null) {
            return Result.create(false);
        }
        diliService.setCode(null);
        up = BeanUtils.merge(up, diliService);
        up.setModified(new Timestamp(new Date().getTime()));

        return Result.create(diliServiceManager.update(up, coverages));
    }

    @Override
    public Result updateStatus(DiliService ser, Long type, Timestamp date) {
        if (ser == null || ser.getId() == null) {
            return Result.create(false);
        }
        DiliService service = diliServiceManager.findOne(ser.getId());
        if (service == null) {
            return Result.create(false);
        }
        if (type == null || type == 0) {
            if (ser.getStatus().equals(DiliService.STATUS_PUTAWAY)) {
                service.setPutawayDate(new Timestamp(new Date().getTime()));
            } else{
                service.setDownDate(new Timestamp(new Date().getTime()));
            }
        } else {
            if (date == null) {
                date = new Timestamp(new Date().getTime());
            }
            if (ser.getStatus().equals(DiliService.STATUS_PUTAWAY)) {
                service.setPutawayDate(date);
            } else{
                service.setDownDate(date);
            }
        }
        service.setModified(new Timestamp(new Date().getTime()));
        return Result.create(diliServiceManager.update(service));
    }

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

    public Result findAll(BaseQuery baseQuery) {
        return Result.create(diliServiceManager.findAll(baseQuery));
    }

    @Override
    public Result findByCode(String code) {
        return Result.create(diliServiceManager.findByCode(code));
    }

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

}