Helius
2020-12-09 660fba5b40303dd661afcc2e2bd54a18d4f53c5c
add invalid time function
5 files modified
218 ■■■■■ changed files
zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java 32 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/hive/bean/ShoppingGoods.java 102 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/hive/service/imp/ShoppingGoodsServiceImpl.java 25 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/mybatis/mapper/hive/ShoppingGoodsDao.xml 19 ●●●● patch | view | raw | blame | history
zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html 40 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/core/tools/DateUtil.java
@@ -5,6 +5,7 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -694,4 +695,35 @@
        }
        return um;
    }
    /**
     * 根据单位计算目标日期
     *
     * @param num 距离
     * @param unit 日期单位 Y/M/D
     * @return
     */
    public static Date calDate(Integer num, String unit) {
        Calendar calendar = Calendar.getInstance();
        Date targetDate = null;
        switch (unit) {
            case "Y":
                calendar.add(Calendar.YEAR, num);
                targetDate = calendar.getTime();
                break;
            case "M":
                calendar.add(Calendar.MONTH, num);
                targetDate = calendar.getTime();
                break;
            case "D":
                calendar.add(Calendar.DAY_OF_MONTH, num);
                targetDate = calendar.getTime();
                break;
            default:
                targetDate = new Date();
        }
        return targetDate;
    }
}
zq-erp/src/main/java/com/matrix/system/hive/bean/ShoppingGoods.java
@@ -2,6 +2,7 @@
import com.matrix.core.anotations.Extend;
import com.matrix.core.tools.DateUtil;
import com.matrix.core.tools.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
@@ -393,7 +394,108 @@
     */
    private Integer isDel;
    /**
     * 购买有效期
     */
    private String buyValid;
    /**
     * 购买有效期单位 - 扩展字段用于参数接收  y/m/d
     */
    private String buyDateUnit;
    /**
     * 购买有效期时长
     */
    private Integer buyDateNum;
    /**
     * 消耗有效期
     */
    private String useValid;
    /**
     * 消耗有效期单位 - 扩展字段用于参数接收  y/m/d
     */
    private String useDateUnit;
    /**
     * 消耗有效期时长
     */
    private Integer useDateNum;
    /**
     * 失效时间
     */
    private Date invalidTime;
    public Integer getBuyDateNum() {
        return buyDateNum;
    }
    public void setBuyDateNum(Integer buyDateNum) {
        this.buyDateNum = buyDateNum;
    }
    public Integer getUseDateNum() {
        return useDateNum;
    }
    public void setUseDateNum(Integer useDateNum) {
        this.useDateNum = useDateNum;
    }
    public String getBuyValid() {
        return buyValid;
    }
    public void setBuyValid(String buyValid) {
        if (StringUtils.isNotBlank(buyValid)) {
            if (buyValid.contains("Y") || buyValid.contains("M") || buyValid.contains("D")) {
                this.buyDateUnit = buyValid.substring(buyValid.length() - 1);
                this.buyDateNum = Integer.parseInt(buyValid.substring(0, buyValid.length() - 1));
            }
        }
        this.buyValid = buyValid;
    }
    public String getBuyDateUnit() {
        return buyDateUnit;
    }
    public void setBuyDateUnit(String buyDateUnit) {
        this.buyDateUnit = buyDateUnit;
    }
    public String getUseValid() {
        return useValid;
    }
    public void setUseValid(String useValid) {
        if (StringUtils.isNotBlank(useValid)) {
            if (useValid.contains("Y") || useValid.contains("M") || useValid.contains("D")) {
                this.useDateUnit = useValid.substring(useValid.length() - 1);
                this.useDateNum = Integer.parseInt(useValid.substring(0, useValid.length() - 1));
            }
        }
        this.useValid = useValid;
    }
    public String getUseDateUnit() {
        return useDateUnit;
    }
    public void setUseDateUnit(String useDateUnit) {
        this.useDateUnit = useDateUnit;
    }
    public Date getInvalidTime() {
        return invalidTime;
    }
    public void setInvalidTime(Date invalidTime) {
        this.invalidTime = invalidTime;
    }
    public Integer getIsDel() {
        return isDel;
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);
zq-erp/src/main/resources/mybatis/mapper/hive/ShoppingGoodsDao.xml
@@ -290,7 +290,10 @@
        use_shop,
        headquarters,
        is_del,
        zjm
        zjm,
        buy_valid,
        use_valid,
        invalid_time
        )
        VALUES (
        #{id},
@@ -346,7 +349,10 @@
            #{useShop},
            #{headquarters},
            #{isDel},
            #{zjm}
            #{zjm},
            #{buyValid},
            #{useValid},
            #{invalidTime}
        )
    </insert>
@@ -519,6 +525,15 @@
            <if test="isDel != null and isDel !='' ">
                is_del = #{isDel},
            </if>
            <if test="invalidTime != null">
                invalid_time = #{invalidTime},
            </if>
            <if test="buyValid != null and buyValid !='' ">
                buy_valid = #{buyValid},
            </if>
            <if test="useValid != null and useValid !='' ">
                use_valid = #{useValid},
            </if>
        </set>
zq-erp/src/main/resources/templates/views/admin/hive/products/goods-form.html
@@ -892,6 +892,44 @@
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :offset="2" :span="5">
                        <el-form-item label="购买有效期">
                            <el-col  :span="6">
                                <el-form-item label="">
                                    <el-input v-model="form.buyDateNum"></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item lable="">
                                    <el-select v-model="form.buyDateUnit" placeholder="请选择">
                                        <el-option
                                                v-for="item in dateList"
                                                :key="item.value"
                                                :label="item.label"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-form-item>
                    </el-col>
                    <el-col :offset="1" :span="5">
                        <el-form-item label="消耗有效期">
                            <el-col  :span="6">
                                <el-input v-model="form.useDateNum"></el-input>
                            </el-col>
                            <el-col  :span="12">
                                <el-select v-model="form.useDateUnit" placeholder="请选择">
                                    <el-option
                                            v-for="item in dateList"
                                            :key="item.value"
                                            :label="item.label"
                                            :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-col>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row v-if="shopInfo.shopType==1">
                    <el-col :span="10">
@@ -944,7 +982,7 @@
    var app = new Vue({
        el: '#app',
        data: {
            dateList : [{value : 'Y', label : '年'}, {value : 'M', label : '月'}, { value : 'D' , label : '日' }],
            selectTreeParam: {
                holder: '请选择商品类型',
                treeData: [],