This commit is contained in:
韩鹏辉
2024-03-21 10:17:54 +08:00
parent c7e46f3504
commit b96a251fd8
296 changed files with 34548 additions and 0 deletions

View File

@@ -0,0 +1,176 @@
package com.chaozhanggui.system.cashierservice.cache;
import cn.hutool.core.util.ObjectUtil;
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
import com.chaozhanggui.system.cashierservice.dao.TbShopOnlineMapper;
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
import com.chaozhanggui.system.cashierservice.entity.TbShopOnline;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
@Component
@Slf4j
public class DataCache {
@Autowired
private TbShopInfoMapper tbShopInfoMapper;
@Autowired
TbShopOnlineMapper tbShopOnlineMapper;
public static ConcurrentHashMap<String,TbShopInfo> concurrentHashMap=new ConcurrentHashMap<>();
@Bean
public void init(){
log.info("加载店铺信息");
shopInfo();
}
public void shopInfo(){
List<TbShopInfo> tbShopInfos= tbShopInfoMapper.selectAll();
if(ObjectUtil.isNotEmpty(tbShopInfos)&&tbShopInfos.size()>0){
tbShopInfos.parallelStream().forEach(it->{
TbShopOnline online= tbShopOnlineMapper.selectByPrimaryKey(it.getId());
if(ObjectUtil.isEmpty(online)){
online=new TbShopOnline();
online.setShopId(it.getId());
if(it.getBusinessTime()!=null&&ObjectUtil.isNotEmpty(it.getBusinessTime())&&it.getBusinessTime().contains("-")){
String[] times=it.getBusinessTime().split("-");
String startTimestr=times[0];
String entTimestr=times[1];
Date startTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(startTimestr).concat(":00"));
Date entTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(entTimestr).concat(":00"));
if(entTime.getTime()<startTime.getTime()){
try {
entTime=DateUtils.getNewDate(entTime,3,1);
} catch (ParseException e) {
e.printStackTrace();
}
}
online.setStartTime(startTime);
online.setEndTime(entTime);
online.setStatus(it.getStatus().toString());
online.setCreateTime(new Date());
}
tbShopOnlineMapper.insert(online);
}else {
if(it.getBusinessTime()!=null&&ObjectUtil.isNotEmpty(it.getBusinessTime())&&it.getBusinessTime().contains("-")){
String[] times=it.getBusinessTime().split("-");
String startTimestr=times[0];
String entTimestr=times[1];
Date startTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(startTimestr).concat(":00"));
Date entTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(entTimestr).concat(":00"));
if(entTime.getTime()<startTime.getTime()){
try {
entTime=DateUtils.getNewDate(entTime,3,1);
} catch (ParseException e) {
e.printStackTrace();
}
}
online.setStartTime(startTime);
online.setEndTime(entTime);
online.setStatus(it.getStatus().toString());
}
online.setUpdateTime(new Date());
tbShopOnlineMapper.updateByPrimaryKey(online);
}
concurrentHashMap.put(it.getId().toString(),it);
});
}
}
@Scheduled(initialDelay = 1000,fixedDelay = 600000)
public void shopTask(){
List<TbShopInfo> tbShopInfos=tbShopInfoMapper.selectAllByCreateTime();
if(ObjectUtil.isNotEmpty(tbShopInfos)&&tbShopInfos.size()>0){
tbShopInfos.parallelStream().forEach(it->{
TbShopOnline online= tbShopOnlineMapper.selectByPrimaryKey(it.getId());
if(ObjectUtil.isEmpty(online)){
online=new TbShopOnline();
online.setShopId(it.getId());
if(it.getBusinessTime()!=null&&ObjectUtil.isNotEmpty(it.getBusinessTime())&&it.getBusinessTime().contains("-")){
String[] times=it.getBusinessTime().split("-");
String startTimestr=times[0];
String entTimestr=times[1];
Date startTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(startTimestr).concat(":00"));
Date entTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(entTimestr).concat(":00"));
if(entTime.getTime()<startTime.getTime()){
try {
entTime=DateUtils.getNewDate(entTime,3,1);
} catch (ParseException e) {
e.printStackTrace();
}
}
online.setStartTime(startTime);
online.setEndTime(entTime);
online.setStatus(it.getStatus().toString());
online.setCreateTime(new Date());
}
tbShopOnlineMapper.insert(online);
}else {
if(it.getBusinessTime()!=null&&ObjectUtil.isNotEmpty(it.getBusinessTime())&&it.getBusinessTime().contains("-")){
String[] times=it.getBusinessTime().split("-");
String startTimestr=times[0];
String entTimestr=times[1];
Date startTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(startTimestr).concat(":00"));
Date entTime= DateUtils.fomatDateTime(DateUtils.getDay().concat(" ").concat(entTimestr).concat(":00"));
if(entTime.getTime()<startTime.getTime()){
try {
entTime=DateUtils.getNewDate(entTime,3,1);
} catch (ParseException e) {
e.printStackTrace();
}
}
online.setStartTime(startTime);
online.setEndTime(entTime);
online.setStatus(it.getStatus().toString());
}
online.setUpdateTime(new Date());
tbShopOnlineMapper.updateByPrimaryKey(online);
}
concurrentHashMap.put(it.getId().toString(),it);
});
}
}
}