Compare commits

..

7 Commits

13 changed files with 168 additions and 34 deletions

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48084:9090 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48084:9090 --name ${app_name} --memory 512m ${app_name}:${app_version}

View File

@ -1,6 +1,6 @@
app_name='ludu-module-datacenter'
app_name='ludu-module-datacenter2'
# 定义应用版本
app_version='1.0.0'
app_version='2.0.0'
# 定义应用环境
#profile_active='prod'
echo '----stop container----'
@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48092:48092 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 9091:48092 --name ${app_name} --memory 800m ${app_name}:${app_version}

View File

@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
@ -51,14 +54,26 @@ public class SaleDataApi {
@GetMapping("/gender")
@Operation(summary = "获得所有数据的男女数量")
public List<Map<String, String>> findByGender() {
return saleDataService.findByGender();
public List<Map<String, String>> findByGender(String starTime, String endTime) {
if (starTime != null && endTime != null){
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return saleDataService.findByGender(replace, replace1);
}else{
return saleDataService.findByGender(starTime, endTime);
}
}
@GetMapping("/age")
@Operation(summary = "获得所有数据的年龄分段和数量")
public List<Map<String, String>> findByage() {
return saleDataService.findByAge();
public List<Map<String, String>> findByage(String starTime, String endTime) {
if (starTime != null && endTime != null){
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return saleDataService.findByAge(replace, replace1);
}else{
return saleDataService.findByAge(starTime, endTime);
}
}
@GetMapping("/lastyear/region")
@ -75,14 +90,26 @@ public class SaleDataApi {
@GetMapping("/salemethod")
@Operation(summary = "查询各个销售渠道的购票人数")
public List<Map<String, String>> findBysaleMethod() {
return saleDataService.findBySaleMethod();
public List<Map<String, String>> findBysaleMethod(String starTime, String endTime) {
if (starTime != null && endTime != null){
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return saleDataService.findBySaleMethod(replace, replace1);
}else{
return saleDataService.findBySaleMethod(starTime, endTime);
}
}
@GetMapping("/itemType")
@Operation(summary = "查询各个产品类型的购票人数")
public List<Map<String, String>> findByItemType() {
return saleDataService.findByDoItemType();
public List<Map<String, String>> findByItemType(String starTime, String endTime) {
if (starTime != null && endTime != null){
String replace = starTime.replace("-", "");
String replace1 = endTime.replace("-", "");
return saleDataService.findByDoItemType(replace, replace1);
}else{
return saleDataService.findByDoItemType(starTime, endTime);
}
}
@GetMapping("/wuyi/{x}")

View File

@ -10,6 +10,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.List;
@Repository
public interface SaleDataRepository extends MongoRepository<SaleData,String> {
@ -30,6 +31,15 @@ public interface SaleDataRepository extends MongoRepository<SaleData,String> {
AggregationVO findAllByCertificateno();
@Aggregation(pipeline = {
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
"{$project: {certLength: {$strLenCP: '$certificateno'}, secondLastChar: {$substrCP: ['$certificateno', {$subtract: [{$strLenCP: '$certificateno'}, 2]}, 1]}}}",
"{$group: {_id: null, maleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 1]}, then: 1, else: 0}}}, femaleCount: {$sum: {$cond: {if: {$eq: [{$mod: [{$toInt: '$secondLastChar'}, 2]}, 0]}, then: 1, else: 0}}}, totalCount: {$sum: 1}}}",
"{$project: {_id: 0, maleCount: 1, femaleCount: 1, maleRatio: {$divide: ['$maleCount', '$totalCount']}}}"
})
AggregationVO findAllByCertificatenoSDTime(String starTime, String endTime);
@Aggregation(pipeline = {
"{$match: {sddate: { $gte: ?0, $lte: ?1 }}}",
"{$match: {certificateno: {$regex: '^.{18}$'}}}",
"{$project: {birthYear: {$toInt: {$substr: ['$certificateno', 6, 4]}}, currentYear: {$year: '$$NOW'}}}",
"{$addFields: {age: {$subtract: ['$currentYear', '$birthYear']}}}",
@ -40,9 +50,15 @@ public interface SaleDataRepository extends MongoRepository<SaleData,String> {
"five: {$sum: {$cond: [{$and: [{$gt: ['$age', 50]}, {$lte: ['$age', 60]}]}, 1, 0]}}, " +
"six: {$sum: {$cond: [{$gt: ['$age', 60]}, 1, 0]}}}}"
})
AgeVo findByAge();
AgeVo findByAge(String starTime, String endTime);
@Query(value = "{}", fields = "{ 'itemtypename': 1 }")
List<SaleDataItemTypeVo> findAllByItemtypename();
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'itemtypename': 1 }")
List<SaleDataItemTypeVo> findAllByItemtypenameTime(String starTime, String endTime);
@Query(value = "{'sddate': { $gte: ?0, $lt: ?1 }}", fields = "{ 'transactiontypeno': 1 }")
List<String> findAllByTransactiontypenoTime(String starTime, String endTime);
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.datacenter.framework.nacos.config;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.net.InetAddress;
import java.net.UnknownHostException;
@Configuration
public class BeanInit {
/**
* 用于改变程序自动获取的本机ip
*/
@Bean
@Primary
public NacosDiscoveryProperties nacosProperties() throws UnknownHostException {
NacosDiscoveryProperties nacosDiscoveryProperties = new NacosDiscoveryProperties();
// 直接指定域名
String customIp = "120.46.37.243"; // 替换为你的域名
int customPort = 9091; // 替换为你的端口
nacosDiscoveryProperties.setIp(customIp );
nacosDiscoveryProperties.setPort(customPort);
return nacosDiscoveryProperties;
}
}

View File

@ -31,13 +31,13 @@ public interface SaleDataService {
* 查询男女人数
* @return 男女人数
*/
public List<Map<String, String>> findByGender();
public List<Map<String, String>> findByGender(String starTime, String endTime);
/**
* 查询各个年龄段的人数
* @return 各个年龄段的人数
*/
public List<Map<String, String>> findByAge();
public List<Map<String, String>> findByAge(String starTime, String endTime);
/**
* 查询去年1月1日到12月31日的全部数据
@ -63,13 +63,13 @@ public interface SaleDataService {
* 查询销售渠道
* @return
*/
public List<Map<String, String>> findBySaleMethod();
public List<Map<String, String>> findBySaleMethod(String starTime, String endTime);
/**
* 查询各个产品类型的购票人数
* @return
*/
public List<Map<String, String>> findByDoItemType();
public List<Map<String, String>> findByDoItemType(String starTime, String endTime);
/**
* 查询最近前x年五一期间的数据

View File

@ -16,6 +16,8 @@ import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@ -62,8 +64,20 @@ public class SaleDataServiceImpl implements SaleDataService {
}
@Override
public List<Map<String, String>> findByGender() {
AggregationVO allByCertificateno = saleDataRepository.findAllByCertificateno();
public List<Map<String, String>> findByGender(String starTime, String endTime) {
AggregationVO allByCertificateno;
if (starTime == null || endTime == null){
// 获取当前日期
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String formattedDate = currentDate.format(formatter);
// 将当前日期加一天
LocalDate nextDay = currentDate.plusDays(1);
String nextDayFormatter = nextDay.format(formatter);
allByCertificateno = saleDataRepository.findAllByCertificatenoSDTime(formattedDate, nextDayFormatter);
}else {
allByCertificateno = saleDataRepository.findAllByCertificatenoSDTime(starTime, endTime);
}
List<Map<String, String>> map = new ArrayList<>();
Map<String,String>map1=new HashMap<>();
Map<String,String>map2=new HashMap<>();
@ -77,8 +91,20 @@ public class SaleDataServiceImpl implements SaleDataService {
}
@Override
public List<Map<String, String>> findByAge() {
AgeVo byAge = saleDataRepository.findByAge();
public List<Map<String, String>> findByAge(String starTime, String endTime) {
AgeVo byAge;
if (starTime == null || endTime == null){
// 获取当前日期
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String formattedDate = currentDate.format(formatter);
// 将当前日期加一天
LocalDate nextDay = currentDate.plusDays(1);
String nextDayFormatter = nextDay.format(formatter);
byAge = saleDataRepository.findByAge(formattedDate,nextDayFormatter);
}else {
byAge = saleDataRepository.findByAge(starTime,endTime);
}
List<Map<String,String>>map=new ArrayList<>();
Map<String,String>map1=new LinkedHashMap<>();
Map<String,String>map2=new LinkedHashMap<>();
@ -171,13 +197,25 @@ public class SaleDataServiceImpl implements SaleDataService {
@Override
public List<Map<String, String>> findBySaleMethod() {
List<SaleData> saleDataList = saleDataRepository.findAll();
public List<Map<String, String>> findBySaleMethod(String starTime, String endTime) {
List<String> saleDataList;
if (starTime == null || endTime == null){
// 获取当前日期
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String formattedDate = currentDate.format(formatter);
// 将当前日期加一天
LocalDate nextDay = currentDate.plusDays(1);
String nextDayFormatter = nextDay.format(formatter);
saleDataList = saleDataRepository.findAllByTransactiontypenoTime(formattedDate, nextDayFormatter);
}else {
saleDataList = saleDataRepository.findAllByTransactiontypenoTime(starTime, endTime);
}
int[] saleMethodCounts = new int[5];
Map<String,String>map=new LinkedHashMap<>();
for (SaleData saleData : saleDataList) {
String transactiontypeno = saleData.getTransactiontypeno();
switch (transactiontypeno){
for (String saleData : saleDataList) {
// String transactiontypeno = saleData.getTransactiontypeno();
switch (saleData){
case "SD01":
saleMethodCounts[0]++;
break;
@ -213,8 +251,20 @@ public class SaleDataServiceImpl implements SaleDataService {
}
@Override
public List<Map<String, String>> findByDoItemType() {
List<SaleDataItemTypeVo> list = saleDataRepository.findAllByItemtypename();
public List<Map<String, String>> findByDoItemType(String starTime, String endTime) {
List<SaleDataItemTypeVo> list;
if (starTime == null || endTime == null){
// 获取当前日期
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
String formattedDate = currentDate.format(formatter);
// 将当前日期加一天
LocalDate nextDay = currentDate.plusDays(1);
String nextDayFormatter = nextDay.format(formatter);
list = saleDataRepository.findAllByItemtypenameTime(formattedDate, nextDayFormatter);
}else {
list = saleDataRepository.findAllByItemtypenameTime(starTime, endTime);
}
Map<String, Long> countMap = list.stream()
.collect(Collectors.groupingBy(SaleDataItemTypeVo::getItemtypename, Collectors.counting()));
List<Map<String, String>> mapArrayList = new ArrayList<>();
@ -225,6 +275,20 @@ public class SaleDataServiceImpl implements SaleDataService {
mapArrayList.add(map);
// map.clear();
}
if (mapArrayList.size() == 0){
HashMap<String, String> map = new HashMap<>();
map.put("TypeName","景点");
map.put("count","0");
mapArrayList.add(map);
HashMap<String, String> map1 = new HashMap<>();
map1.put("TypeName","公园");
map1.put("count","0");
mapArrayList.add(map1);
HashMap<String, String> map2 = new HashMap<>();
map2.put("TypeName","遗迹");
map2.put("count","0");
mapArrayList.add(map2);
}
return mapArrayList;
}

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48090:48090 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48090:48090 --name ${app_name} --memory 600m ${app_name}:${app_version}

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48088:48088 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48088:48088 --name ${app_name} --memory 600m ${app_name}:${app_version}

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48083:48080 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48083:48080 --name ${app_name} --memory 512m ${app_name}:${app_version}

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48082:48082 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48082:48082 --name ${app_name} --memory 700m ${app_name}:${app_version}

View File

@ -66,7 +66,7 @@ spring:
username: root
password: 123456
ticketing:
url: jdbc:mysql://120.46.37.243:3306/ludu_ticketing?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
url: jdbc:mysql://101.43.112.107:3306/ludu_ticketing?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
username: root
password: xpower1234

View File

@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version}
echo '----build image----'
docker buildx build -f Dockerfile -t ${app_name}:${app_version} .
echo '----start container----'
docker run -d -p 48081:48081 --name ${app_name} ${app_name}:${app_version}
docker run -d -p 48081:48081 --name ${app_name} --memory 700m ${app_name}:${app_version}