Helius
2020-12-09 660fba5b40303dd661afcc2e2bd54a18d4f53c5c
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java
@@ -3,6 +3,7 @@
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
@@ -26,6 +27,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.awt.event.WindowStateListener;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -88,6 +90,9 @@
        shoppingGoods.setCreateTime(new Date());
        setPublicAttr(shoppingGoods);
        setShoppingGoodsInvalidTime(shoppingGoods);
        if (shoppingGoods.getReferencePice() == null) {
            //赠送金额
            shoppingGoods.setReferencePice(0D);
@@ -116,6 +121,24 @@
        return i;
    }
    private void setShoppingGoodsInvalidTime(ShoppingGoods shoppingGoods) {
        // 若未设置购买有效期和消耗有效期,则默认永久有效
        if (shoppingGoods.getBuyDateNum() == null && shoppingGoods.getUseDateNum() == null) {
            shoppingGoods.setInvalidTime(DateUtil.stringToDate("9999-12-31", DateUtil.DATE_FORMAT_DD));
        } else {
            // 计算失效日期,判断购买有效期和消耗有效期哪个先失效,则为失效日期
            Date buyValidDate = DateUtil.calDate(shoppingGoods.getBuyDateNum(), shoppingGoods.getBuyDateUnit());
            Date useValidDate = DateUtil.calDate(shoppingGoods.getUseDateNum(), shoppingGoods.getUseDateUnit());
            if (buyValidDate.after(useValidDate)) {
                shoppingGoods.setInvalidTime(useValidDate);
            } else {
                shoppingGoods.setInvalidTime(buyValidDate);
            }
            shoppingGoods.setBuyValid(shoppingGoods.getBuyDateNum() + shoppingGoods.getBuyDateUnit());
            shoppingGoods.setUseValid(shoppingGoods.getUseDateNum() + shoppingGoods.getUseDateUnit());
        }
    }
    private void setGoodsAssembles(ShoppingGoods shoppingGoods) {
@@ -190,7 +213,7 @@
            }
        }
        setShoppingGoodsInvalidTime(shoppingGoods);
        return shoppingGoodsDao.update(shoppingGoods);