DiliService.java 7.21 KB
package com.diligrp.website.domain;

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

import com.diligrp.website.util.domain.BaseDomain;
import com.google.common.base.Strings;


/**
 * <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
 */
public class DiliService extends BaseDomain {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 上架
     */
    public static final Integer STATUS_PUTAWAY = 0;
    /**
     * 下架
     */
    public static final Integer STATUS_DOWN = 1;

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    /**
     * 服务名称
     */
    private String name;
    /**
     * 服务编码
     */
    private String code;
    /**
     * 服务类型;1独立服务,2订单服务,3.通用服务
     */
    private Integer type;

    /**
     * 服务类别;1, 采购, 2, 销售, 3, 通用
     */
    private Integer Category;
    /**
     * 服务介绍
     */
    private String remark;
    /**
     * 上架状态,0上架,1下架
     */
    private Integer status;
    /**
     * 操作人
     */
    private Long creator;
    /**
     * 操作人名
     */
    private String creatorName;
    /**
     * 上架时间
     */
    private Timestamp putawayDate;

    /**
     * 下架时间
     */
    private Timestamp downDate;

    /**
     * 服务图片
     */
    private String image;
    /**
     * 服务图标
     */
    private String icon;

    /**
     * 服务图片
     */
    private String serviceImage;


    
    public String getIcon() {
        return icon;
    }

    
    public void setIcon(String icon) {
        this.icon = icon;
    }

    /**
     * 检测并修正状态
     * @return
     */
    public Boolean checkStatus() {
        Timestamp newDate = new Timestamp(new Date().getTime());
        Integer st = status;
        if (putawayDate == null && downDate == null) {
            return false;
        }

        if (putawayDate == null) {
            setStatus(STATUS_DOWN);
            return st != status;
//            return false;
        }

        if (downDate == null) {
            if (putawayDate.before(newDate)) {
                setStatus(STATUS_PUTAWAY);
                return st != status;
            }
            return false;
        }

        if (downDate.before(newDate) && putawayDate.before(newDate)) {
            if (downDate.before(putawayDate)) {
                setStatus(STATUS_PUTAWAY);
                return st != status;
            }
            setStatus(STATUS_DOWN);
            return st != status;
        }

        if (downDate.before(newDate)) {
            setStatus(STATUS_DOWN);
            return st != status;
        }

        if (putawayDate.before(newDate)) {
            setStatus(STATUS_PUTAWAY);
            return st != status;
        }
        return false;
    }

    public String getDateScope() {
        StringBuffer sb = new StringBuffer();

        if(putawayDate != null) {
            sb.append(sdf.format(putawayDate));
        }
        sb.append("~");
        if (status != null && status.equals(STATUS_DOWN)) {
            if (putawayDate != null && downDate != null && downDate.before(putawayDate)) {

            } else {
                sb.append(sdf.format(downDate));
            }
        } else if (downDate != null && downDate.after(putawayDate)){
            sb.append(sdf.format(downDate));
        }

//        if (putawayDate == null) {
//            sb.append("~");
//            if (downDate != null) {
//                sb.append(sdf.format(downDate));
//            }
//        } else {
//            if (downDate == null) {
//                sb.append(sdf.format(putawayDate));
//                sb.append("~");
//            } else {
//                if (putawayDate.after(downDate)) {
//                    sb.append(sdf.format(putawayDate));
//                    sb.append("~");
////                    sb.append(sdf.format(downDate));
//                } else {
//                    sb.append(sdf.format(putawayDate));
//                    sb.append("~");
//                    sb.append(sdf.format(downDate));
//                }
//            }
//        }

        return sb.toString();
    }

    public void setName (String name){
        this.name = name;
    }
    public String getName(){
        return this.name;
    }

    public void setCode (String code){
        this.code = code;
    }
    public String getCode(){
        return this.code;
    }

    public void setType (Integer type){
        this.type = type;
    }
    public Integer getType(){
        return this.type;
    }

    public void setRemark (String remark){
        this.remark = remark;
    }
    public String getRemark(){
        return this.remark;
    }

    public void setStatus (Integer status){
        this.status = status;
    }
    public Integer getStatus(){
        return this.status;
    }

    public void setCreator (Long creator){
        this.creator = creator;
    }
    public Long getCreator(){
        return this.creator;
    }

    public void setPutawayDate (Timestamp putawayDate){
        this.putawayDate = putawayDate;
    }
    public Timestamp getPutawayDate(){
        return this.putawayDate;
    }

    public Timestamp getDownDate() {
        return downDate;
    }

    public void setDownDate(Timestamp downDate) {
        this.downDate = downDate;
    }

    public String getImage() {
        if (!Strings.isNullOrEmpty(serviceImage)) {
            return serviceImage;
        }
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getServiceImage() {
        return serviceImage;
    }

    public void setServiceImage(String serviceImage) {
        this.serviceImage = serviceImage;
    }

    public Integer getCategory() {
        return Category;
    }

    public void setCategory(Integer category) {
        Category = category;
    }

    public String getCreatorName() {
        return creatorName;
    }

    public void setCreatorName(String creatorName) {
        this.creatorName = creatorName;
    }

    public String toString(){
        StringBuffer sb = new StringBuffer();
        sb.append("DiliService [");
        sb.append("id = ");
        sb.append(id);
        sb.append(", name = ");
        sb.append(name);
        sb.append(", code = ");
        sb.append(code);
        sb.append(", type = ");
        sb.append(type);
        sb.append(", remark = ");
        sb.append(remark);
        sb.append(", status = ");
        sb.append(status);
        sb.append(", creator = ");
        sb.append(creator);
        sb.append(", putawayDate = ");
        sb.append(putawayDate);
        sb.append(", downDate = ");
        sb.append(downDate);
        sb.append(", modified = ");
        sb.append(modified);
        sb.append(", created = ");
        sb.append(created);
        sb.append(", image = ");
        sb.append(image);
        sb.append(", yn = ");
        sb.append(yn);
        sb.append("]");
        return sb.toString();
    }
}