Commit 94cdf8e4 by 刘宇峰

Merge branch 'develop' into 'master'

Develop

See merge request !2
2 parents e98ce664 ff870bf3
Showing 15 changed files with 461 additions and 153 deletions
......@@ -43,6 +43,36 @@
<skip>true</skip>
</configuration>
</plugin>
<!-- mybatis逆向工程插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- 允许移动生成的文件 -->
<verbose>true</verbose>
<!-- 是否覆盖 -->
<overwrite>true</overwrite>
<!-- 配置文件 -->
<configurationFile>
src/main/resources/config/generatorConfig.xml
</configurationFile>
</configuration>
<!--此处添加一个mysql-connector-java依赖可以防止找不到jdbc Driver-->
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.19</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>3.3.9</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package cn.com.glsx.datariskcon.constant;
/**
* @author zhouhaibao
* @date 2020-12-03
*/
public class Constants {
/**
* 半年
*/
public final static String HALF_YEAR = "halfyear";
/**
* 一年
*/
public final static String ONE_YEAR = "oneyear";
}
package cn.com.glsx.datariskcon.modules.controller;
package cn.com.glsx.report.modules.controller;
import cn.com.glsx.datariskcon.modules.model.ChannelRiskDataModel;
import cn.com.glsx.datariskcon.modules.model.param.ChannelRiskDataSearch;
import cn.com.glsx.datariskcon.modules.service.ChannelRiskDataService;
import cn.com.glsx.report.modules.model.ChannelRiskDataModel;
import cn.com.glsx.report.modules.model.param.ChannelRiskDataSearch;
import cn.com.glsx.report.modules.service.ChannelRiskDataService;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.context.utils.validator.AssertUtils;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -54,9 +55,7 @@ public class ChannelRiskDataController {
@GetMapping("/findChannelAllRiskData")
@ApiOperation(value = "查询渠道的所有数据(正常的或者疑似网点的)")
public R findChannelAllRiskData(@RequestParam(required = false) String channelName, @RequestParam(required = false) String isExcep) {
if (StringUtils.isEmpty(isExcep)) {
return R.error("请求参数错误,isExcep必传字段");
}
AssertUtils.isNull(isExcep, "参数有误");
List<ChannelRiskDataModel> channelAllRiskData = channelRiskDataService.findChannelAllRiskData(channelName, isExcep);
return R.ok().data(channelAllRiskData);
}
......@@ -64,30 +63,32 @@ public class ChannelRiskDataController {
/**
* 查询省市区的区域安装单数
*
* @param proviceName 省份名称
* @param cityName 城市名称
* @param channelName 渠道名称
* @param provinceName 省份名称
* @param cityName 城市名称
* @param channelName 渠道名称
* @return
*/
@GetMapping("/findRegInstallSheet")
@ApiOperation(value = "查询省市区的区域安装单数")
public R findRegInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String proviceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) {
List<Map<String, String>> map = channelRiskDataService.findRegInstallSheet(channelName, proviceName, cityName, timeRange);
public R findRegInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String provinceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) {
AssertUtils.isNull(timeRange, "参数有误");
List<Map<String, String>> map = channelRiskDataService.findRegInstallSheet(channelName, provinceName, cityName, timeRange);
return R.ok().data(map);
}
/**
* 查询省市区的每月安装单数
*
* @param proviceName 省份名称
* @param cityName 城市名称
* @param channelName 渠道名称
* @param provinceName 省份名称
* @param cityName 城市名称
* @param channelName 渠道名称
* @return
*/
@GetMapping("/findTimeInstallSheet")
@ApiOperation(value = "查询省市区的每月安装单数")
public R findTimeInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String proviceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) {
List<Map<String, String>> map = channelRiskDataService.findTimeInstallSheet(channelName, proviceName, cityName, timeRange);
public R findTimeInstallSheet(@RequestParam(required = false) String channelName, @RequestParam(required = false) String provinceName, @RequestParam(required = false) String cityName, @RequestParam(required = false) String timeRange) {
AssertUtils.isNull(timeRange, "参数有误");
List<Map<String, Object>> map = channelRiskDataService.findTimeInstallSheet(channelName, provinceName, cityName, timeRange);
return R.ok().data(map);
}
......@@ -100,7 +101,7 @@ public class ChannelRiskDataController {
@GetMapping("/findOutletsData")
@ApiOperation(value = "查询异常网点")
public R findOutletsData(ChannelRiskDataSearch channelRiskDataSearch) {
PageInfo<Map<String, String>> outletsData = channelRiskDataService.findOutletsData(channelRiskDataSearch);
PageInfo<Map<String, Object>> outletsData = channelRiskDataService.findOutletsData(channelRiskDataSearch);
return R.ok().data(outletsData);
}
......
package cn.com.glsx.datariskcon.modules.entity;
package cn.com.glsx.report.modules.entity;
import lombok.Data;
import lombok.experimental.Accessors;
......@@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
/**
......@@ -119,4 +120,13 @@ public class ChannelRiskData {
@Column(name = "type")
private Integer type;
@Transient
private String adcode;
@Column(name = "center_lat")
private Double center_lat;
@Column(name = "center_lng")
private Double center_lng;
}
package cn.com.glsx.datariskcon.modules.mapper;
package cn.com.glsx.report.modules.mapper;
import cn.com.glsx.datariskcon.modules.entity.ChannelRiskData;
import cn.com.glsx.datariskcon.modules.model.param.ChannelRiskDataSearch;
import cn.com.glsx.report.modules.entity.ChannelRiskData;
import cn.com.glsx.report.modules.model.param.ChannelRiskDataSearch;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -59,37 +59,17 @@ public interface ChannelRiskDataMapper extends CommonBaseMapper<ChannelRiskData>
*
* @param monthNum 时间范围
* @param channelName 渠道名称
* @return List<Map < String, String>>
*/
List<Map<String, String>> findTimeInstallSheet(@Param("monthNum") String monthNum, @Param("channelName") String channelName);
/**
* 查询某个省某个时间段的每月的安装单
*
* @param proviceName 省名称
* @param timeRange 时间范围
* @param channelName 渠道名称
* @return List<Map < String, String>>
* @return List<Map < String, Object>>
*/
List<Map<String, String>> findProTimeInstallSheet(@Param("proviceName") String proviceName, @Param("monthNum") String timeRange, @Param("channelName") String channelName);
/**
* 查询某个市某个时间段的每月的安装单
*
* @param cityName 市名称
* @param timeRange 时间范围
* @param channelName 渠道名称
* @return List<Map < String, String>>
*/
List<Map<String, String>> findCityTimeInstallSheet(@Param("cityName") String cityName, @Param("monthNum") String timeRange, @Param("channelName") String channelName);
List<Map<String, Object>> findTimeInstallSheet(@Param("monthNum") String monthNum, @Param("channelName") String channelName,@Param("proviceName") String proviceName,@Param("cityName") String cityName);
/**
* 查询网点数据
*
* @param shopName 搜索条件
* @return List<Map < String, String>>
* @return List<Map < String, Object>>
*/
List<Map<String, String>> findOutletsData(@Param("shopName") String shopName);
List<Map<String, Object>> findOutletsData(@Param("shopName") String shopName);
/**
* 查询区域安装单的详细数据
......
package cn.com.glsx.datariskcon.modules.model;
package cn.com.glsx.report.modules.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
......@@ -50,4 +50,9 @@ public class ChannelRiskDataModel {
* 激活地址
*/
private String address;
/**
* 省编码
*/
private String adcode;
}
package cn.com.glsx.datariskcon.modules.model.param;
package cn.com.glsx.report.modules.model.param;
import cn.hutool.db.Page;
import lombok.Data;
......
package cn.com.glsx.datariskcon.modules.model.view;
package cn.com.glsx.report.modules.model.view;
import lombok.Data;
import lombok.experimental.Accessors;
......
package cn.com.glsx.datariskcon.modules.service;
package cn.com.glsx.report.modules.service;
import cn.com.glsx.datariskcon.constant.Constants;
import cn.com.glsx.datariskcon.modules.entity.ChannelRiskData;
import cn.com.glsx.datariskcon.modules.mapper.ChannelRiskDataMapper;
import cn.com.glsx.datariskcon.modules.model.ChannelRiskDataModel;
import cn.com.glsx.datariskcon.modules.model.param.ChannelRiskDataSearch;
import cn.com.glsx.report.modules.entity.ChannelRiskData;
import cn.com.glsx.report.modules.mapper.ChannelRiskDataMapper;
import cn.com.glsx.report.modules.model.ChannelRiskDataModel;
import cn.com.glsx.report.modules.model.param.ChannelRiskDataSearch;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
......@@ -14,6 +13,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
......@@ -57,17 +59,17 @@ public class ChannelRiskDataService {
* @param channelName 渠道名称
* @param proviceName 省份名称
* @param cityName 城市名称
* @param timeRange 日期范围
* @return List<Map < String, String>>
*/
public List<Map<String, String>> findRegInstallSheet(String channelName, String proviceName, String cityName, String timeRange) {
List<Map<String, String>> map = new ArrayList<>();
String monthNum = converMonthNum(timeRange);
if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) {
map = channelRiskDataMapper.findProInstallSheet(monthNum, channelName);
} else if (StringUtils.isNotEmpty(proviceName)) {
map = channelRiskDataMapper.findCityInstallSheet(proviceName, monthNum, channelName);
map = channelRiskDataMapper.findProInstallSheet(timeRange, channelName);
} else if (StringUtils.isNotEmpty(cityName)) {
map = channelRiskDataMapper.findZoneInstallSheet(cityName, monthNum, channelName);
map = channelRiskDataMapper.findZoneInstallSheet(cityName, timeRange, channelName);
} else if (StringUtils.isNotEmpty(proviceName)) {
map = channelRiskDataMapper.findCityInstallSheet(proviceName, timeRange, channelName);
}
return map;
}
......@@ -78,31 +80,78 @@ public class ChannelRiskDataService {
* @param channelName 渠道名称
* @param proviceName 省份名称
* @param cityName 城市名称
* @return List<Map < String, String>>
* @param timeRange 日期范围
* @return List<Map < String, Object>>
*/
public List<Map<String, String>> findTimeInstallSheet(String channelName, String proviceName, String cityName, String timeRange) {
List<Map<String, String>> map = new ArrayList<>();
String monthNum = converMonthNum(timeRange);
if (StringUtils.isEmpty(proviceName) && StringUtils.isEmpty(cityName)) {
map = channelRiskDataMapper.findTimeInstallSheet(monthNum, channelName);
} else if (StringUtils.isNotEmpty(proviceName)) {
map = channelRiskDataMapper.findProTimeInstallSheet(proviceName, monthNum, channelName);
} else if (StringUtils.isNotEmpty(cityName)) {
map = channelRiskDataMapper.findCityTimeInstallSheet(cityName, monthNum, channelName);
public List<Map<String, Object>> findTimeInstallSheet(String channelName, String proviceName, String cityName, String timeRange) {
List<Map<String, Object>> finalMap = new ArrayList<>();
//获取当前月份前多少个月
List<String> list = getMonthList(timeRange);
List<Map<String, Object>> resultmap = channelRiskDataMapper.findTimeInstallSheet(timeRange, channelName, proviceName, cityName);
List<String> xAxislist = resultmap.stream().map(index -> index.get("xAxis") + "").collect(Collectors.toList());
//添加没有值的月份并排序
list.forEach(index -> {
Map<String, Object> defaultValue = new HashMap<>();
defaultValue.put("xAxis", index);
//如果不存在,则初始化0,存在就是原来值
if (!xAxislist.contains(index)) {
defaultValue.put("value", 0);
} else {
resultmap.forEach(item -> {
String xAxis = item.get("xAxis") + "";
if (xAxis.equals(index)) {
defaultValue.put("value", item.get("value"));
}
});
}
finalMap.add(defaultValue);
});
return finalMap;
}
/**
* 获取当前月份前多少个月
*
* @param timeRange
* @return
*/
public List<String> getMonthList(String timeRange) {
List<String> list = new ArrayList<>();
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1 + 1;
int year = cal.get(Calendar.YEAR);
for (int i = 0; i < Integer.parseInt(timeRange); i++) {
month--;
if (month > 0) {
list.add(year + "年" + month + "月");
} else {
month = 12;
year--;
list.add(year + "年" + month + "月");
}
}
return map;
Collections.reverse(list);
return list;
}
/**
* 查询网点数据
*
* @param channelRiskDataSearch 搜索条件
* @return PageInfo<Map < String, String>>
* @return PageInfo<Map < String, Object>>
*/
public PageInfo<Map<String, String>> findOutletsData(ChannelRiskDataSearch channelRiskDataSearch) {
public PageInfo<Map<String, Object>> findOutletsData(ChannelRiskDataSearch channelRiskDataSearch) {
Page page = PageHelper.startPage(channelRiskDataSearch.getPageNumber(), channelRiskDataSearch.getPageSize());
List<Map<String, String>> outletsData = channelRiskDataMapper.findOutletsData(channelRiskDataSearch.getShopName());
PageInfo<Map<String, String>> pageInfo = new PageInfo<>(outletsData);
List<Map<String, Object>> outletsData = channelRiskDataMapper.findOutletsData(channelRiskDataSearch.getShopName());
outletsData.forEach(index -> {
double center_lat = (double) index.get("center_lat");
double center_lng = (double) index.get("center_lng");
List<Double> doubles = new ArrayList<>();
doubles.add(center_lng);
doubles.add(center_lat);
index.put("lnglat", doubles);
});
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(outletsData);
pageInfo.setPages(page.getPages());//总页数
pageInfo.setTotal(page.getTotal());//总条数
return pageInfo;
......@@ -119,6 +168,10 @@ public class ChannelRiskDataService {
List<ChannelRiskData> list = channelRiskDataMapper.findOutletsDataDetail(channelRiskDataSearch);
List<ChannelRiskDataModel> channelRiskDataModelList = list.stream().map(index -> {
ChannelRiskDataModel channelRiskDataModel = new ChannelRiskDataModel();
List<Double> doubles = new ArrayList<>();
doubles.add(index.getLng());
doubles.add(index.getLat());
channelRiskDataModel.setLnglat(doubles);
BeanUtils.copyProperties(index, channelRiskDataModel);
return channelRiskDataModel;
}
......@@ -139,19 +192,4 @@ public class ChannelRiskDataService {
return list;
}
/**
* 转化日期
*
* @param timeRange 日期范围
* @return String
*/
public String converMonthNum(String timeRange) {
String monthNum = null;
if (Constants.ONE_YEAR.equals(timeRange)) {
monthNum = "12";
} else if (Constants.HALF_YEAR.equals(timeRange)) {
monthNum = "6";
}
return monthNum;
}
}
......@@ -50,7 +50,7 @@
</javaTypeResolver>
<!-- 生成实体类地址 -->
<javaModelGenerator targetPackage="com.glsx.neshield.modules.entity" targetProject="src/main/java">
<javaModelGenerator targetPackage="cn.com.glsx.report.modules.entity" targetProject="src/main/java">
<!-- 是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="true"/>
<!-- 从数据库返回的值去掉前后空格 -->
......@@ -63,11 +63,11 @@
</sqlMapGenerator>
<!-- 生成接口dao type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象 type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象 type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator targetPackage="com.glsx.neshield.modules.mapper" targetProject="src/main/java" type="XMLMAPPER">
<javaClientGenerator targetPackage="cn.com.glsx.report.modules.mapper" targetProject="src/main/java" type="XMLMAPPER">
<property name="enableSubPackages" value="false"/>
</javaClientGenerator>
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<table tableName="t_user_path" domainObjectName="UserPath" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
<table tableName="base_provinces" domainObjectName="baseProvinces" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.glsx.datariskcon.modules.mapper.ChannelRiskDataMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.datariskcon.modules.entity.ChannelRiskData">
<mapper namespace="cn.com.glsx.report.modules.mapper.ChannelRiskDataMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.report.modules.entity.ChannelRiskData">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="workorder_no" jdbcType="VARCHAR" property="workorder_no"/>
<result column="owner_name" jdbcType="VARCHAR" property="owner_name"/>
......@@ -19,6 +19,9 @@
<result column="shop_name" jdbcType="VARCHAR" property="shop_name"/>
<result column="labels" jdbcType="VARCHAR" property="labels"/>
<result column="type" jdbcType="INTEGER" property="type"/>
<result column="center_lat" jdbcType="DOUBLE" property="center_lat"/>
<result column="center_lng" jdbcType="DOUBLE" property="center_lng"/>
<result column="adcode" jdbcType="VARCHAR" property="adcode"/>
</resultMap>
<sql id="Base_Column_List">
id, workorder_no, owner_name,vin, sn, active_date, dev_type,gps_time, lng,
......@@ -30,7 +33,7 @@
active_date,owner_name,vin,sn,address,lng,lat,zone
FROM t_channel_risk_data
<if test="isExcep == 'true'">
where type=1
where type=1 and labels!=-1
</if>
<if test="isExcep == 'false'">
where type=0
......@@ -86,7 +89,7 @@
<select id="findTimeInstallSheet" resultType="java.util.Map">
select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis,
DATE_FORMAT(gps_time,'%Y年%c月') as xAxis,
count(id) as value
from t_channel_risk_data
where type=0
......@@ -96,56 +99,31 @@
<if test="channelName !=null and channelName !=''">
and shop_name=#{channelName}
</if>
group by xAxis
</select>
<select id="findProTimeInstallSheet" resultType="java.util.Map">
select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis,
count(id) as value
from t_channel_risk_data
where type=0
<if test="monthNum !=null and monthNum !=''">
and gps_time>=DATE_SUB(last_day(curdate()), INTERVAL #{monthNum} MONTH)+1
</if>
<if test="channelName !=null and channelName !=''">
and shop_name=#{channelName}
</if>
and prov=#{proviceName}
group by xAxis
</select>
<select id="findCityTimeInstallSheet" resultType="java.util.Map">
select
concat(DATE_FORMAT(gps_time,'%m'),'月份') as xAxis,
count(id) as value
from t_channel_risk_data
where type=0
<if test="monthNum !=null and monthNum !=''">
and gps_time>=DATE_SUB(last_day(curdate()), INTERVAL #{monthNum} MONTH)+1
<if test="proviceName !=null and proviceName !=''">
and prov=#{proviceName}
</if>
<if test="channelName !=null and channelName !=''">
and shop_name=#{channelName}
<if test="cityName !=null and cityName !=''">
and city=#{cityName}
</if>
and city=#{cityName}
group by xAxis
group by xAxis ORDER BY gps_time
</select>
<select id="findOutletsData" resultType="java.util.Map">
select
shop_name,address,count(shop_name) as orderCount
FROM t_channel_risk_data
where type=1
labels as shop_name,address,count(labels) as orderCount,center_lat,center_lng,t2.adcode
FROM t_channel_risk_data t1 left join base_provinces t2 on t1.prov=t2.name
where labels!=-1
<if test="shopName !=null and shopName !=''">
and shop_name like CONCAT('%',#{shopName},'%')
and labels like CONCAT('%',#{shopName},'%')
</if>
group by shop_name
group by labels
</select>
<select id="findOutletsDataDetail" resultMap="BaseResultMap">
select active_date,owner_name,vin,sn,address
from t_channel_risk_data
where type=1
select active_date,owner_name,vin,sn,address,lng,t2.adcode,
lat
from t_channel_risk_data t1 left join base_provinces t2 on t1.prov=t2.name
where type=1 and labels!=-1
<if test="item.provinceName !=null and item.provinceName !=''">
and prov=#{item.provinceName}
</if>
......
#!/bin/bash
cd `dirname $0`
./stop.sh
if [ ! $? -eq 2 ];then
./start.sh
fi
\ No newline at end of file
#!/bin/bash
cd `dirname $0`
if [ "$1" = "start" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV
else
if [ "$1" = "stop" ]; then
./stop.sh
else
if [ "$1" = "debug" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./start.sh $ENV debug
else
if [ "$1" = "restart" ]; then
ENV=$2
if [ -z "$ENV" ]; then
echo "ERROR:PLEASE SPEC ENV ARGS,SUCH AS dev,test,beta,release.. "
echo "app exit"
exit 1
fi
./restart.sh $ENV
else
if [ "$1" = "dump" ]; then
./dump.sh
else
echo "ERROR: Please input argument: start or stop or debug or restart or dump"
exit 1
fi
fi
fi
fi
fi
#!/bin/bash
####################################
# #
# General shell v1.0.0.1 #
# #
# #
####################################
###########init variable#############
JAVA_HOME="/app/soft/jdk1.8.0_144"
SERVER_PORT="8090"
DUBBO_PORT=""
JMX_ARG="-Xmx1024m -Xms512m -Xmn256m"
MAIN="cn.com.glsx.Application"
SERVER_NAME="glsx-ne-shield-reportcenter"
###########end#######################
PID_DIR="/app/soft/java_project/pids"
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
if [ -d "classes" ];then
CONF_DIR="$(pwd)/classes"
LIB_DIR="$(pwd)/lib"
elif [ -d "conf" ];then
CONF_DIR="$(pwd)/conf"
LIB_DIR="$(pwd)/lib"
fi
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
export CLASSPATH=$CONF_DIR:$LIB_JARS
if [ -z "$CONF_DIR" ];then
echo "Configure dir not found"
exit 1
fi
PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The app is already started!"
echo "PID: $PIDS"
exit 1
fi
if [ ! -d "$PID_DIR" ];then
mkdir -p $PID_DIR
fi
CHECK_PORT=$2
if [ -n "$SERVER_PORT" ];then
SERVER_PORT_COUNT=`netstat -tln | grep -w $SERVER_PORT | wc -l`
if [ $SERVER_PORT_COUNT -gt 0 ]; then
echo "ERROR: The port $SERVER_PORT is already used!"
exit 1
fi
fi
if [ -n "$DUBBO_PORT" ];then
DUBBO_PORT_COUNT=`netstat -tln | grep -w $DUBBO_PORT | wc -l`
if [ $DUBBO_PORT_COUNT -gt 0 ]; then
echo "ERROR: The port $DUBBO_PORT already used!"
exit 1
fi
fi
if [[ -z "$SERVER_PORT" && -z "$DUBBO_PORT" ]];then
CHECK_PORT="skip"
fi
LOG_FILE="/data/java_log/jetty/${SERVER_NAME}/${SERVER_NAME}.log"
LOG_DIR=`dirname $LOG_FILE`
if [ ! -d $LOG_DIR ];then
mkdir -p $LOG_DIR
fi
############java args #######
#JAVA_OPTS="$PINPOINT -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Ddubbo.registry.file=/home/jdkapp/.dubbo/${SERVER_NAME}.cache"
JAVA_OPTS="$PINPOINT -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
#JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true"
JAVA_DEBUG_OPTS=""
if [ "$2" = "debug" ]; then
JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n "
fi
JAVA_JMX_OPTS=""
if [ "$2" = "jmx" ]; then
JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false "
fi
BITS=`file $JAVA_HOME/bin/java | grep 64-bit`
if [ -n "$BITS" ]; then
if [ -n "$JMX_ARG" ];then
JAVA_MEM_OPTS="-server $JMX_ARG -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70"
else
JAVA_MEM_OPTS=" -server -Xmx1g -Xms1g -Xmn256m -XX:PermSize=128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 "
fi
else
JAVA_MEM_OPTS=" -server -Xms1024m -Xmx1024m -XX:PermSize=128m -XX:SurvivorRatio=2 -XX:+UseParallelGC "
fi
echo -e "Starting $SERVER_NAME \c"
nohup $JAVA_HOME/bin/java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -DCLASS_DIR=$CONF_DIR:$LIB_DIR $MAIN > /dev/null 2>&1 &
PIDS=$!
if [ "$CHECK_PORT" != "skip" ];then
COUNT=0
ERROR=0
TIME_OUT=60
ctime=`date +"%s"`
while [ $COUNT -lt 1 ]; do
ctime2=`date +"%s"`
echo -e ".\c"
sleep 1
#PIDS=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" | awk '{print $2}'`
RESULT=`ps --no-heading -p $PIDS`
if [ -n "$RESULT" ];then
if [ -n "$DUBBO_PORT" ]; then
#COUNT=`echo status | nc 127.0.0.1 $DUBBO_PORT -i 1 | grep -c OK`
COUNT=`/usr/sbin/ss -lpn | grep "${DUBBO_PORT}.*$PIDS" | wc -l`
else
if [ -n "$SERVER_PORT" ]; then
#COUNT=`netstat -ntl | grep -w $SERVER_PORT | wc -l`
COUNT=`/usr/sbin/ss -lpn | grep "${SERVER_PORT}.*$PIDS" | wc -l`
fi
fi
if [ $COUNT -gt 0 ]; then
echo $PIDS > $PID_DIR/${SERVER_NAME}.pid
break
fi
dtime=$((ctime2 - ctime))
if [ "$dtime" -ge "$TIME_OUT" ];then
echo $PIDS > $PID_DIR/${SERVER_NAME}.pid
echo -e "\ncheck port status timeout"
exit 1
fi
else
ERROR=$((ERROR + 1))
if [ "$ERROR" -gt 3 ];then
echo -e "\nProgram startup failed"
exit 2
fi
fi
done
fi
#服务检测与注册
if [[ "x$SERVER_PORT" != "x" && -f ./bin/check.sh ]]
then
./bin/check.sh $SERVER_NAME $SERVER_PORT $PIDS &
fi
echo "PID: $PIDS"
echo "LOGFILE: $LOG_FILE"
\ No newline at end of file
#!/bin/bash
####################################
# #
# General shell v1.0.0.1 #
# #
# #
####################################
SERVER_NAME="glsx-ne-shield-reportcenter"
PID_DIR="/app/soft/java_project/pids"
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
if [ -d "classes" ];then
CONF_DIR="$(pwd)/classes"
elif [ -d "conf" ];then
CONF_DIR="$(pwd)/conf"
fi
#if [ -f "$PID_DIR/${SERVER_NAME}.pid" ];then
# PID=`cat $PID_DIR/${SERVER_NAME}.pid`
#else
PID=`ps --no-heading -C java -f --width 1000 | grep "$CONF_DIR" |awk '{print $2}'`
#fi
if [ -z "$PID" ];then
echo "The program is not running"
exit 1
fi
pcount=`ps --no-heading -p $PID | wc -l`
if [ "$pcount" -ne 1 ];then
echo "ERROR: $SERVER_NAME does not started!"
exit 1
fi
echo -e "Stopping $SERVER_NAME ...\c"
kill $PID > /dev/null 2>&1
COUNT=0
ctime=`date +"%s"`
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=1
PID_EXIST=`ps --no-heading -p $PID`
if [ -n "$PID_EXIST" ]; then
ctime2=`date +"%s"`
dtime=$((ctime2 - ctime))
if [ "$dtime" -ge 10 ];then
echo -e "\nstop program timeout, use kill -9 $PID"
kill -9 $PID >/dev/null 2>&1
if [ ! $? -eq 0 ];then
echo "No permissions"
exit 2
else
rm -rf $PID_DIR/${SERVER_NAME}.pid
fi
fi
COUNT=0
continue
fi
done
echo "OK!"
rm -rf $PID_DIR/${SERVER_NAME}.pid
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!