|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|