Procházet zdrojové kódy

行程在库对应

libin před 3 roky
rodič
revize
e81125e71c

+ 8 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/domain/BusCompany.java

@@ -89,6 +89,14 @@ public class BusCompany extends BaseEntity
     @Excel(name = "プライバシーポリシー")
     private String privacy;
 
+    /** ポイントルール説明 */
+    @Excel(name = "ポイントルール説明")
+    private String pointDesc;
+
+    /** クーポン使用説明 */
+    @Excel(name = "クーポン使用説明")
+    private String couponDesc;
+
     /**  親権者同意書 */
     @Excel(name = "親権者同意書")
     private String agreement;

+ 16 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/mapper/TCommodityManageMapper.java

@@ -5,6 +5,7 @@ import java.util.Map;
 
 import com.ruoyi.web.pcApi.domain.TCommodityManage;
 import com.ruoyi.web.pcApi.domain.TCommodityJourneyInformation;
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.security.core.parameters.P;
 
@@ -79,16 +80,29 @@ public interface TCommodityManageMapper
      * @return 结果
      */
     public int batchTCommodityJourneyInformation(List<TCommodityJourneyInformation> tCommodityJourneyInformationList);
-    
 
+    /**
+     * 批量新增旅游日程详细
+     *
+     * @param tCommoditySchedulList 旅游日程详细列表
+     * @return 结果
+     */
+    public int batchTCommoditySchedul(List<TCommoditySchedul> tCommoditySchedulList);
     /**
      * 通过商品信息管理主键删除商品旅程信息信息
      * 
      * @param id 商品信息管理ID
      * @return 结果
      */
-    public int deleteTCommodityJourneyInformationByCommodityId(Long id);
+    public int deleteTCommoditySchedulByCommodityId(Long id);
 
+    /**
+     * 通过商品信息管理主键删除座位在库
+     *
+     * @param id 商品信息管理ID
+     * @return 结果
+     */
+    public int deleteTCommodityJourneyInformationByCommodityId(Long id);
 
     List<TCommodityManage> selectSameTypeCommodityTop5(@Param("id") Long id, @Param("typeId") Long typeId, @Param("deptId") Long deptId);
 

+ 146 - 5
ruoyi-admin/src/main/java/com/ruoyi/web/pcApi/service/impl/TCommodityManageServiceImpl.java

@@ -1,15 +1,19 @@
 package com.ruoyi.web.pcApi.service.impl;
 
-import java.util.List;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
 import com.ruoyi.common.annotation.DataScope;
+import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.web.pcApi.domain.TCommodityCoupon;
+import com.ruoyi.web.pcApi.domain.TCommoditySchedul;
 import com.ruoyi.web.pcApi.mapper.TCommodityCouponMapper;
+import com.ruoyi.web.pcApi.mapper.TCommoditySchedulMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import java.util.ArrayList;
-import java.util.Map;
 
 import com.ruoyi.common.utils.StringUtils;
 import org.springframework.transaction.annotation.Transactional;
@@ -31,7 +35,8 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
     private TCommodityManageMapper tCommodityManageMapper;
     @Autowired
     private TCommodityCouponMapper tCommodityCouponMapper;
-
+    @Autowired
+    private TCommoditySchedulMapper tCommoditySchedulMapper;
     /**
      * 查询商品信息管理
      * 
@@ -72,6 +77,9 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
     {
         tCommodityManage.setCreateTime(DateUtils.getNowDate());
         int rows = tCommodityManageMapper.insertTCommodityManage(tCommodityManage);
+        //旅游日程详细
+        tCommodityManageMapper.batchTCommoditySchedul(createTCommoditySchedulList(tCommodityManage));
+        //行程
         insertTCommodityJourneyInformation(tCommodityManage);
         // 优惠券信息
         insertTCommodityCoupon(tCommodityManage);
@@ -89,8 +97,12 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
     public int updateTCommodityManage(TCommodityManage tCommodityManage)
     {
         tCommodityManage.setUpdateTime(DateUtils.getNowDate());
+        //旅游日程详细
+        updateTCommoditySchedul(tCommodityManage);
+        //行程
         tCommodityManageMapper.deleteTCommodityJourneyInformationByCommodityId(tCommodityManage.getId());
         insertTCommodityJourneyInformation(tCommodityManage);
+        // 优惠券信息
         if(tCommodityManage.getCommodityCouponList() != null && tCommodityManage.getCommodityCouponList().size()>0){
             tCommodityCouponMapper.updateTCommodityCoupon(tCommodityManage.getCommodityCouponList().get(0));
         }
@@ -123,6 +135,7 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
     public int deleteTCommodityManageById(Long id)
     {
         tCommodityManageMapper.deleteTCommodityJourneyInformationByCommodityId(id);
+        delTCommoditySchedul(id);
         return tCommodityManageMapper.deleteTCommodityManageById(id);
     }
 
@@ -137,7 +150,7 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
         Long id = tCommodityManage.getId();
         if (StringUtils.isNotNull(tCommodityJourneyInformationList))
         {
-            List<TCommodityJourneyInformation> list = new ArrayList<TCommodityJourneyInformation>();
+            List<TCommodityJourneyInformation> list = new ArrayList<>();
             for (TCommodityJourneyInformation tCommodityJourneyInformation : tCommodityJourneyInformationList)
             {
                 tCommodityJourneyInformation.setCommodityId(id);
@@ -167,6 +180,101 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
             }
         }
     }
+    /**
+     * 更改旅游日程详细
+     *
+     * @param tCommodityManage 商品信息管理对象
+     */
+    private void updateTCommoditySchedul(TCommodityManage tCommodityManage)
+    {
+        //旅游日程详细
+        List<TCommoditySchedul> newSchedulList = createTCommoditySchedulList(tCommodityManage);
+
+        TCommoditySchedul searchConditionTCommoditySchedul = new TCommoditySchedul();
+        searchConditionTCommoditySchedul.setCommodityId(tCommodityManage.getId());
+        searchConditionTCommoditySchedul.setDeptId(tCommodityManage.getDeptId());
+        List<TCommoditySchedul> oldSchedulList = tCommoditySchedulMapper.selectTCommoditySchedulList(searchConditionTCommoditySchedul);
+
+        Long oldStock = tCommodityManageMapper.selectTCommodityManageById(tCommodityManage.getId()).getStock();
+
+        Long id = tCommodityManage.getId();
+        if (newSchedulList.size()>0)
+        {
+            for (TCommoditySchedul tCommoditySchedul : newSchedulList)
+            {
+                // if in then update otherwise add
+                Optional<TCommoditySchedul> matchTCommoditySchedul= oldSchedulList.stream()
+                        .filter(a -> a.getDepartureDate().equals(tCommoditySchedul.getDepartureDate()))
+                        .findFirst();
+                if (!matchTCommoditySchedul.isPresent()){
+                    tCommoditySchedulMapper.insertTCommoditySchedul(tCommoditySchedul);
+                }else{
+                    int newSeat = matchTCommoditySchedul.get().getSeatNum().intValue()-oldStock.intValue()+tCommoditySchedul.getSeatNum().intValue();
+                    if (newSeat>=0) {
+                        tCommoditySchedul.setId(matchTCommoditySchedul.get().getId());
+                        tCommoditySchedul.setSeatNum((long) newSeat);
+                        tCommoditySchedulMapper.updateTCommoditySchedul(tCommoditySchedul);
+                    }else{
+                        throw new ServiceException(String.format("【%1$s】既に予約しましたので、変更不可 ", tCommoditySchedul.getDepartureDate()));
+                    }
+                }
+            }
+        }
+        if (oldSchedulList.size()>0)
+        {
+            DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+            LocalDate today = LocalDate.now();
+            String todayStr = today.format(fmt);
+
+            for (TCommoditySchedul tCommoditySchedul : oldSchedulList)
+            {
+                // if in then update otherwise add
+                Optional<TCommoditySchedul> matchTCommoditySchedul= newSchedulList.stream()
+                        .filter(a -> a.getDepartureDate().equals(tCommoditySchedul.getDepartureDate()))
+                        .findFirst();
+                if (matchTCommoditySchedul.isPresent()){
+                    //前边已经处理完了,什么页不需要做
+                }else{
+                    //当前日之前的数据忽视
+                    if (todayStr.compareTo(tCommoditySchedul.getDepartureDate())<0) {
+                        if (oldStock.intValue()>tCommoditySchedul.getSeatNum().intValue()) {
+                            throw new ServiceException(String.format("【%1$s】既に予約はいりますので、変更不可 ", tCommoditySchedul.getDepartureDate()));
+
+                        } else {
+                            tCommoditySchedulMapper.deleteTCommoditySchedulId(tCommoditySchedul.getId());
+                        }
+                    }
+                }
+            }
+        }
+    }
+    /**
+     * 删除旅游日程详细
+     *
+     * @param id 商品信息管理对象
+     */
+    private void delTCommoditySchedul(Long id)
+    {
+        TCommodityManage tCommodityManage= tCommodityManageMapper.selectTCommodityManageById(id);
+        TCommoditySchedul searchConditionTCommoditySchedul = new TCommoditySchedul();
+        searchConditionTCommoditySchedul.setCommodityId(id);
+        searchConditionTCommoditySchedul.setDeptId(tCommodityManage.getDeptId());
+        List<TCommoditySchedul> oldSchedulList = tCommoditySchedulMapper.selectTCommoditySchedulList(searchConditionTCommoditySchedul);
+
+        Long stock = tCommodityManageMapper.selectTCommodityManageById(tCommodityManage.getId()).getStock();
+
+
+        if (StringUtils.isNotNull(oldSchedulList))
+        {
+            boolean exists = oldSchedulList.stream()
+                        .anyMatch(a -> a.getSeatNum().intValue()<stock.intValue());
+            if (exists){
+                throw new ServiceException("既に予約はいりますので、削除不可 ");
+            }else{
+                tCommodityManageMapper.deleteTCommoditySchedulByCommodityId(id);
+            }
+        }
+    }
 
     @Override
     public List<TCommodityManage> selectSalesTop10(TCommodityManage commodityManage) {
@@ -182,4 +290,37 @@ public class TCommodityManageServiceImpl implements ITCommodityManageService
     public List<TCommodityManage> selectTCommodityManageList4H5(TCommodityManage commodityManage) {
         return tCommodityManageMapper.selectTCommodityManageList4H5(commodityManage);
     }
+
+    /**
+     *  从画面生成旅游日程详细List
+     *
+     * @param tCommodityManage 商品信息管理对象
+     */
+    private List<TCommoditySchedul> createTCommoditySchedulList(TCommodityManage tCommodityManage)
+    {
+        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+
+        LocalDate startDate = LocalDate.parse(tCommodityManage.getPeriodStart(), fmt);
+        LocalDate endDate= LocalDate.parse(tCommodityManage.getPeriodEnd(), fmt);
+        int[] weeks = Arrays.stream(tCommodityManage.getPeriodWeek().split("\\s*,\\s*"))
+                .mapToInt(Integer::parseInt)
+                .toArray();
+
+        List<TCommoditySchedul> commoditySchedulList = new ArrayList<>();
+        Long id = tCommodityManage.getId();
+        while (startDate.isBefore(endDate)) {
+            int key= startDate.getDayOfWeek().getValue();
+            if(Arrays.stream(weeks).anyMatch(i -> i == key)){
+                TCommoditySchedul e= new TCommoditySchedul();
+                e.setDeptId(tCommodityManage.getDeptId());
+                e.setCommodityId(id);
+                e.setDepartureDate(startDate.format(fmt));
+                e.setSeatNum(tCommodityManage.getStock());
+                e.setDelFlag("0");
+                commoditySchedulList.add(e);
+            }
+            startDate = startDate.plusDays(1);
+        }
+        return commoditySchedulList;
+    }
 }

+ 12 - 0
ruoyi-admin/src/main/resources/mapper/busCompany/BusCompanyMapper.xml

@@ -22,6 +22,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="mark"    column="mark"    />
         <result property="privacy"    column="privacy"    />
         <result property="agreement"   column="agreement"    />
+        <result property="pointDesc"   column="point_desc"    />
+        <result property="couponDesc"   column="coupon_desc"    />
         <result property="status"    column="status"    />
         <result property="delFlag"    column="del_flag"    />
         <result property="createBy"    column="create_by"    />
@@ -50,6 +52,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             a.mark,
             a.privacy,
             a.agreement,
+            a.point_desc,
+            a.coupon_desc,
             a.STATUS,
             a.del_flag,
             a.create_by,
@@ -81,6 +85,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="mark != null and mark != ''"> and mark = #{mark}</if>
             <if test="privacy != null and privacy != ''"> and privacy = #{privacy}</if>
             <if test="agreement != null and agreement != ''"> and agreement = #{agreement}</if>
+            <if test="pointDesc != null and pointDesc != ''"> and point_desc = #{pointDesc}</if>
+            <if test="couponDesc != null and couponDesc != ''"> and coupon_desc = #{couponDesc}</if>
             <if test="status != null  and status != ''"> and status = #{status}</if>
             <if test="params.beginDate != null and params.beginDate != ''"><!-- 开始时间检索 -->
                 and date_format(a.create_time,'%y%m%d') &gt;= date_format(#{params.beginDate},'%y%m%d')
@@ -115,6 +121,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="mark != null">mark,</if>
             <if test="privacy != null">privacy,</if>
             <if test="agreement != null">agreement,</if>
+            <if test="pointDesc != null">point_desc,</if>
+            <if test="couponDesc != null">coupon_desc,</if>
             <if test="status != null">status,</if>
             <if test="delFlag != null">del_flag,</if>
             <if test="createBy != null">create_by,</if>
@@ -139,6 +147,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="mark != null">#{mark},</if>
             <if test="privacy != null">#{privacy},</if>
             <if test="agreement != null">#{agreement},</if>
+            <if test="pointDesc != null">point_desc,</if>
+            <if test="couponDesc != null">coupon_desc,</if>
             <if test="status != null">#{status},</if>
             <if test="delFlag != null">#{delFlag},</if>
             <if test="createBy != null">#{createBy},</if>
@@ -167,6 +177,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="mark != null">mark = #{mark},</if>
             <if test="privacy != null">privacy = #{privacy},</if>
             <if test="agreement != null">agreement = #{agreement},</if>
+            <if test="pointDesc != null">point_desc = #{pointDesc},</if>
+            <if test="couponDesc != null">coupon_desc = #{couponDesc},</if>
             <if test="status != null">status = #{status},</if>
             <if test="delFlag != null">del_flag = #{delFlag},</if>
             <if test="createBy != null">create_by = #{createBy},</if>

+ 11 - 0
ruoyi-admin/src/main/resources/mapper/commodity/TCommodityManageMapper.xml

@@ -289,6 +289,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         delete from t_commodity_journey_information where commodity_id = #{commodityId}
     </delete>
 
+    <delete id="deleteTCommoditySchedulByCommodityId" parameterType="Long">
+        delete from t_commodity_schedul where commodity_id = #{commodityId}
+    </delete>
+
     <insert id="batchTCommodityJourneyInformation">
         insert into t_commodity_journey_information( id, commodity_id, journey_time, detail, create_by, create_time, update_by, update_time, remark) values
 		<foreach item="item" index="index" collection="list" separator=",">
@@ -296,6 +300,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </insert>
 
+    <insert id="batchTCommoditySchedul">
+        insert into t_commodity_schedul( commodity_id, departure_date, dept_id, create_by, create_time, update_by, update_time, remark,seat_num) values
+        <foreach item="item" index="index" collection="list" separator=",">
+            ( #{item.commodityId}, #{item.departureDate}, #{item.deptId}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}, #{item.seatNum})
+        </foreach>
+    </insert>
+
     <select id="selectSameTypeCommodityTop5" resultMap="TCommodityManageResult">
         <include refid="selectTCommodityManageVo"/>
         where a.status = '0'