Helius
2020-12-11 aeaae1d860575e0c4097031f0274262d8df17901
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
@@ -26,6 +26,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.validation.constraints.NotNull;
import java.awt.event.WindowStateListener;
import java.time.LocalDate;
import java.util.ArrayList;
@@ -421,4 +422,34 @@
        return shoppingGoodsDao.selectByModelData(shoppingGoods);
    }
    /**
     * 计算失效时间
     *
     * @param shoppingGoods
     * @param type 1 - 购买时  2 - 消耗时
     * @return
     */
    @Override
    public Date calInvalidTime(ShoppingGoods shoppingGoods, @NotNull Integer type) {
        if (StringUtils.isBlank(shoppingGoods.getBuyValid()) && StringUtils.isBlank(shoppingGoods.getUseValid()) && shoppingGoods.getInvalidTime() == null) {
            return null;
        }
        Date target = null;
        Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
        Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit());
        if (buyValidDate.after(useValidDate)) {
            target = useValidDate;
        } else {
            target = buyValidDate;
        }
        if (shoppingGoods.getInvalidTime() != null) {
            if (target.after(shoppingGoods.getInvalidTime())) {
                target = shoppingGoods.getInvalidTime();
            }
        }
        return target;
    }
}