|
@@ -3,9 +3,15 @@ package com.ruoyi.system.service.impl;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import com.ruoyi.common.constant.Constants;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.system.domain.BomanReservatConfigTime;
|
|
|
+import com.ruoyi.system.mapper.BomanReservatConfigTimeMapper;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.math.NumberUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.system.mapper.BomanReservatMapper;
|
|
@@ -14,42 +20,44 @@ import com.ruoyi.system.service.IBomanReservatService;
|
|
|
|
|
|
/**
|
|
|
* 陵园预约Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
* @date 2023-11-02
|
|
|
*/
|
|
|
@Service
|
|
|
-public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
-{
|
|
|
+public class BomanReservatServiceImpl implements IBomanReservatService {
|
|
|
@Autowired
|
|
|
private BomanReservatMapper bomanReservatMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BomanReservatConfigTimeMapper bomanReservatConfigTimeMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
/**
|
|
|
* 查询陵园预约
|
|
|
- *
|
|
|
+ *
|
|
|
* @param reservatId 陵园预约主键
|
|
|
* @return 陵园预约
|
|
|
*/
|
|
|
@Override
|
|
|
- public BomanReservat selectBomanReservatByReservatId(Long reservatId)
|
|
|
- {
|
|
|
+ public BomanReservat selectBomanReservatByReservatId(Long reservatId) {
|
|
|
return bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询陵园预约列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bomanReservat 陵园预约
|
|
|
* @return 陵园预约
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<BomanReservat> selectBomanReservatList(BomanReservat bomanReservat)
|
|
|
- {
|
|
|
+ public List<BomanReservat> selectBomanReservatList(BomanReservat bomanReservat) {
|
|
|
String dataType = bomanReservat.getDataType();
|
|
|
- if ("1".equals(dataType)){
|
|
|
+ if ("1".equals(dataType)) {
|
|
|
bomanReservat.setVisitDate(DateUtils.getDate());
|
|
|
}
|
|
|
- if ("2".equals(dataType)){
|
|
|
+ if ("2".equals(dataType)) {
|
|
|
bomanReservat.setVisitDate(DateUtils.getDateByDays(-1));
|
|
|
}
|
|
|
return bomanReservatMapper.selectBomanReservatList(bomanReservat);
|
|
@@ -57,15 +65,33 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
|
|
|
/**
|
|
|
* 新增陵园预约
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bomanReservat 陵园预约
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertBomanReservat(BomanReservat bomanReservat)
|
|
|
- {
|
|
|
+ public int insertBomanReservat(BomanReservat bomanReservat) {
|
|
|
+ Long reservatConfigTimeId = bomanReservat.getReservatConfigTimeId();
|
|
|
+ //查询可预约人数
|
|
|
+ BomanReservatConfigTime bomanReservatConfigTime = bomanReservatConfigTimeMapper.selectBomanReservatConfigTimeByReservatConfigTimeId(reservatConfigTimeId);
|
|
|
+ //组装key
|
|
|
+ //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
|
|
|
+ String key = Constants.RESERVAT_NUM + bomanReservat.getVisitDate() + "_" + reservatConfigTimeId;
|
|
|
+ //已经预约人数
|
|
|
+ Object reservatNum = redisCache.getCacheObject(key);
|
|
|
+ //最新预约人数 = 已经预约人数 + 新增预约人数
|
|
|
+ long numNew = (long) reservatNum + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
+ if (ObjectUtils.isNotEmpty(reservatNum)) {
|
|
|
+ //判断已预约人数+新增预约人数=是否大于可预约人数
|
|
|
+ //如果 x==y 返回0;x<y 返回负数(-1);x>y 返回正数(1)
|
|
|
+ if (NumberUtils.compare(bomanReservatConfigTime.getReservatConfigNum(), numNew) < 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //新增预约往redis中存放数据
|
|
|
+ redisCache.setCacheObject(key, numNew);
|
|
|
bomanReservat.setCreateTime(DateUtils.getNowDate());
|
|
|
- if("2".equals(bomanReservat.getReservatType())){
|
|
|
+ if ("2".equals(bomanReservat.getReservatType())) {
|
|
|
bomanReservat.setVisitType("3");
|
|
|
}
|
|
|
return bomanReservatMapper.insertBomanReservat(bomanReservat);
|
|
@@ -73,38 +99,51 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
|
|
|
/**
|
|
|
* 修改陵园预约
|
|
|
- *
|
|
|
+ *
|
|
|
* @param bomanReservat 陵园预约
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateBomanReservat(BomanReservat bomanReservat)
|
|
|
- {
|
|
|
+ public int updateBomanReservat(BomanReservat bomanReservat) {
|
|
|
bomanReservat.setUpdateTime(DateUtils.getNowDate());
|
|
|
return bomanReservatMapper.updateBomanReservat(bomanReservat);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除陵园预约
|
|
|
- *
|
|
|
+ *
|
|
|
* @param reservatIds 需要删除的陵园预约主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteBomanReservatByReservatIds(Long[] reservatIds)
|
|
|
- {
|
|
|
+ public int deleteBomanReservatByReservatIds(Long[] reservatIds) {
|
|
|
+ //取消预约,需要修改redis中的预约人数
|
|
|
+ for (Long reservatId : reservatIds) {
|
|
|
+ BomanReservat bomanReservat = bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
|
|
|
+ Long reservatConfigTimeId = bomanReservat.getReservatConfigTimeId();
|
|
|
+ String visitNum = bomanReservat.getVisitNum();
|
|
|
+ //去redis找对应日期,对应时段id的预约数量 reservat_num:2023-10-10_1
|
|
|
+ String key = Constants.RESERVAT_NUM + bomanReservat.getVisitDate() + "_" + reservatConfigTimeId;
|
|
|
+ Object reservatNum = redisCache.getCacheObject(key);
|
|
|
+ if (ObjectUtils.isNotEmpty(reservatNum)) {
|
|
|
+ long reservatNumNew = (long)reservatNum - Long.parseLong(visitNum);
|
|
|
+ if (reservatNumNew < 0){
|
|
|
+ reservatNumNew = 0;
|
|
|
+ }
|
|
|
+ redisCache.setCacheObject(key,reservatNumNew);
|
|
|
+ }
|
|
|
+ }
|
|
|
return bomanReservatMapper.deleteBomanReservatByReservatIds(reservatIds);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除陵园预约信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param reservatId 陵园预约主键
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteBomanReservatByReservatId(Long reservatId)
|
|
|
- {
|
|
|
+ public int deleteBomanReservatByReservatId(Long reservatId) {
|
|
|
return bomanReservatMapper.deleteBomanReservatByReservatId(reservatId);
|
|
|
}
|
|
|
|
|
@@ -112,7 +151,7 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
public AjaxResult examine(BomanReservat bomanReservat) {
|
|
|
BomanReservat reservat = bomanReservatMapper.selectBomanReservatByReservatId(bomanReservat.getReservatId());
|
|
|
|
|
|
- if("3".equals(bomanReservat.getVisitType()) && "Y".equals(reservat.getIsReception()) && StringUtils.isEmpty(reservat.getReceptionName())){
|
|
|
+ if ("3".equals(bomanReservat.getVisitType()) && "Y".equals(reservat.getIsReception()) && StringUtils.isEmpty(reservat.getReceptionName())) {
|
|
|
return AjaxResult.error("请先分配接待人员");
|
|
|
}
|
|
|
bomanReservat.setUpdateTime(DateUtils.getNowDate());
|
|
@@ -122,26 +161,27 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
|
|
|
/**
|
|
|
* 预约首页统计
|
|
|
+ *
|
|
|
* @param
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult indexStatistics(BomanReservat bomanReservat) {
|
|
|
- Map<String,Object> map = new HashMap<>(4);
|
|
|
- map.put("canGuan",0);
|
|
|
- map.put("yuYue",0);
|
|
|
- map.put("todayYuYue",0);
|
|
|
- map.put("todayCanGuan",0);
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
+ map.put("canGuan" , 0);
|
|
|
+ map.put("yuYue" , 0);
|
|
|
+ map.put("todayYuYue" , 0);
|
|
|
+ map.put("todayCanGuan" , 0);
|
|
|
List<BomanReservat> bomanReservats = bomanReservatMapper.selectBomanReservatList(bomanReservat);
|
|
|
- if (bomanReservats != null && bomanReservats.size() > 0){
|
|
|
+ if (bomanReservats != null && bomanReservats.size() > 0) {
|
|
|
//来访数
|
|
|
long canGuan = bomanReservats.stream().filter(s -> "2".equals(s.getVisitStatus())).count();
|
|
|
long todayYuYue = bomanReservats.stream().filter(s -> DateUtils.getDate().equals(s.getVisitDate())).count();
|
|
|
long todayCanGuan = bomanReservats.stream().filter(s -> DateUtils.getDate().equals(s.getVisitDate())).filter(s -> "2".equals(s.getVisitStatus())).count();
|
|
|
- map.put("canGuan",canGuan);
|
|
|
- map.put("yuYue",bomanReservats.size());
|
|
|
- map.put("todayYuYue",todayYuYue);
|
|
|
- map.put("todayCanGuan",todayCanGuan);
|
|
|
+ map.put("canGuan" , canGuan);
|
|
|
+ map.put("yuYue" , bomanReservats.size());
|
|
|
+ map.put("todayYuYue" , todayYuYue);
|
|
|
+ map.put("todayCanGuan" , todayCanGuan);
|
|
|
}
|
|
|
return AjaxResult.success(map);
|
|
|
}
|
|
@@ -149,7 +189,7 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
@Override
|
|
|
public AjaxResult verification(Long reservatId) {
|
|
|
BomanReservat reservat = bomanReservatMapper.selectBomanReservatByReservatId(reservatId);
|
|
|
- if("2".equals(reservat.getVisitStatus())){
|
|
|
+ if ("2".equals(reservat.getVisitStatus())) {
|
|
|
return AjaxResult.error("当前预约已核销,请勿重复操作。");
|
|
|
}
|
|
|
BomanReservat bomanReservat = new BomanReservat();
|
|
@@ -166,17 +206,17 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
@Override
|
|
|
public AjaxResult realTime() {
|
|
|
// todo
|
|
|
- Map<String,Object> resultMap = new HashMap<>();
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
|
- resultMap.put("scale","50%");
|
|
|
- resultMap.put("current",50);
|
|
|
- resultMap.put("total",100);
|
|
|
+ resultMap.put("scale" , "50%");
|
|
|
+ resultMap.put("current" , 50);
|
|
|
+ resultMap.put("total" , 100);
|
|
|
return AjaxResult.success(resultMap);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult people() {
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
String time = DateUtils.getDate();
|
|
|
//获取当前年
|
|
@@ -190,39 +230,39 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
long todayYy = 0;
|
|
|
for (BomanReservat bomanReservat : bomanReservatYearList) {
|
|
|
yearYy = yearYy + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
- if(bomanReservat.getVisitDate().contains(time.substring(0,time.lastIndexOf("_")))){
|
|
|
+ if (bomanReservat.getVisitDate().contains(time.substring(0, time.lastIndexOf("_")))) {
|
|
|
monthYy = monthYy + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
}
|
|
|
- if(bomanReservat.getVisitDate().equals(time)){
|
|
|
+ if (bomanReservat.getVisitDate().equals(time)) {
|
|
|
todayYy = todayYy + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
}
|
|
|
}
|
|
|
- map.put("yearYy",yearYy);
|
|
|
- map.put("monthYy",monthYy);
|
|
|
- map.put("todayYy",todayYy);
|
|
|
+ map.put("yearYy" , yearYy);
|
|
|
+ map.put("monthYy" , monthYy);
|
|
|
+ map.put("todayYy" , todayYy);
|
|
|
//todo 今日参观人数
|
|
|
- map.put("todayVisit",10);
|
|
|
+ map.put("todayVisit" , 10);
|
|
|
|
|
|
- Map<String,Object> sevenMap = new HashMap<>();
|
|
|
+ Map<String, Object> sevenMap = new HashMap<>();
|
|
|
//获取近7天的数组
|
|
|
List<String> sevenDate = getSevenDate();
|
|
|
//获取7天中最早的一天
|
|
|
String first = sevenDate.get(0);
|
|
|
//查询七天中的数据
|
|
|
- List<BomanReservat> bomanReservatSevenList = bomanReservatMapper.selectBomanReservatbySeven(first,time);
|
|
|
+ List<BomanReservat> bomanReservatSevenList = bomanReservatMapper.selectBomanReservatbySeven(first, time);
|
|
|
List<Long> zrsList = new ArrayList<>();
|
|
|
List<Long> skList = new ArrayList<>();
|
|
|
List<Long> tdList = new ArrayList<>();
|
|
|
- Long zrs = 0l;
|
|
|
- Long sk = 0l;
|
|
|
- Long td = 0l;
|
|
|
+ Long zrs = 0L;
|
|
|
+ Long sk = 0L;
|
|
|
+ Long td = 0L;
|
|
|
for (int i = 0; i < sevenDate.size(); i++) {
|
|
|
for (BomanReservat bomanReservat : bomanReservatSevenList) {
|
|
|
- if(bomanReservat.getVisitDate().equals(sevenDate.get(i))){
|
|
|
+ if (bomanReservat.getVisitDate().equals(sevenDate.get(i))) {
|
|
|
zrs = zrs + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
- if("1".equals(bomanReservat.getReservatType())){
|
|
|
+ if ("1".equals(bomanReservat.getReservatType())) {
|
|
|
td = td + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
sk = sk + Long.parseLong(bomanReservat.getVisitNum());
|
|
|
}
|
|
|
}
|
|
@@ -231,17 +271,17 @@ public class BomanReservatServiceImpl implements IBomanReservatService
|
|
|
skList.add(sk);
|
|
|
tdList.add(td);
|
|
|
//循环完一轮之后重置
|
|
|
- zrs = 0l;
|
|
|
- sk = 0l;
|
|
|
- td = 0l;
|
|
|
+ zrs = 0L;
|
|
|
+ sk = 0L;
|
|
|
+ td = 0L;
|
|
|
}
|
|
|
|
|
|
- sevenMap.put("date",sevenDate);
|
|
|
- sevenMap.put("zrs",zrsList);
|
|
|
- sevenMap.put("sk",skList);
|
|
|
- sevenMap.put("td",tdList);
|
|
|
+ sevenMap.put("date" , sevenDate);
|
|
|
+ sevenMap.put("zrs" , zrsList);
|
|
|
+ sevenMap.put("sk" , skList);
|
|
|
+ sevenMap.put("td" , tdList);
|
|
|
|
|
|
- map.put("sevenMap",sevenMap);
|
|
|
+ map.put("sevenMap" , sevenMap);
|
|
|
return AjaxResult.success(map);
|
|
|
}
|
|
|
|