Commit f0eba736 authored by Quxl's avatar Quxl

x

parents
Pipeline #122 canceled with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/target/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>xplayer</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.egolm</groupId>
<artifactId>xplayer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<start-class>com.egolm.xplayer.XPlayerApplication</start-class>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<repositories>
<repository>
<id>pubmaven</id>
<name>pubmaven</name>
<url>http://git.egolm.com:9003/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<dependency>
<groupId>com.egolm</groupId>
<artifactId>common</artifactId>
<version>0.0.1-RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-vod</artifactId>
<version>2.11.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package com.egolm.xplayer;
import org.apache.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.egolm.xplayer.config.ExceptionHandler;
@EnableCaching
@SpringBootApplication
@EnableTransactionManagement
public class XPlayerApplication {
private static final Logger logger = Logger.getLogger(ExceptionHandler.class);
private static ApplicationContext applicationContext;
public static void main(String[] args) {
logger.info("XPlayerApplication start");
applicationContext = SpringApplication.run(XPlayerApplication.class, args);
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public static Object getBean(String name){
return getApplicationContext().getBean(name);
}
public static <T> T getBean(Class<T> clazz){
return getApplicationContext().getBean(clazz);
}
public static <T> T getBean(String name, Class<T> clazz){
return getApplicationContext().getBean(name, clazz);
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
@Entity(name="enum_type")
public class Enum_type implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10)")
private Integer id;
@Column(columnDefinition="varchar(255) COMMENT '类型名'")
private String name;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="s_logs")
public class S_logs implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10) COMMENT '日志ID'")
private Integer id;
@Column(columnDefinition="int(10)")
private Integer admin_id;
@Column(columnDefinition="int(10)")
private Integer user_id;
@Column(columnDefinition="varchar(255) COMMENT '连接前缀'")
private String prefix;
@Column(columnDefinition="varchar(255) COMMENT '访问连接地址'")
private String path;
@Column(columnDefinition="varchar(255) COMMENT '客户端IP'")
private String ip;
@Column(columnDefinition="longtext COMMENT '请求内容'")
private String content;
@Column(columnDefinition="longtext COMMENT '浏览器信息'")
private String user_agent;
@Column(columnDefinition="datetime COMMENT '记录时间'")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setAdmin_id(Integer admin_id) {
this.admin_id = admin_id;
}
public Integer getAdmin_id() {
return admin_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public Integer getUser_id() {
return user_id;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getPrefix() {
return prefix;
}
public void setPath(String path) {
this.path = path;
}
public String getPath() {
return path;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getIp() {
return ip;
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setUser_agent(String user_agent) {
this.user_agent = user_agent;
}
public String getUser_agent() {
return user_agent;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="s_logs_error")
public class S_logs_error implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10)")
private Integer id;
@Column(columnDefinition="varchar(255)")
private String path;
@Column(columnDefinition="varchar(255)")
private String title;
@Column(columnDefinition="longtext")
private String error;
@Column(columnDefinition="longtext")
private String params;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setPath(String path) {
this.path = path;
}
public String getPath() {
return path;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setError(String error) {
this.error = error;
}
public String getError() {
return error;
}
public void setParams(String params) {
this.params = params;
}
public String getParams() {
return params;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="t_admin")
public class T_admin implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10)")
private Integer id;
@Column(columnDefinition="varchar(255)")
private String username;
@Column(columnDefinition="varchar(255)")
private String password;
@Column(columnDefinition="varchar(255)")
private String token;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setToken(String token) {
this.token = token;
}
public String getToken() {
return token;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name="t_licence")
public class T_licence implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10) COMMENT '许可证ID'")
private Integer id;
@Column(columnDefinition="int(10) COMMENT '视频ID'")
private Integer video_id;
@Column(columnDefinition="int(10) COMMENT '许可观看时长'")
private Integer expire_hours;
@Column(columnDefinition="decimal(10,2) COMMENT '许可证售价'")
private BigDecimal price;
@Column(columnDefinition="int(1) COMMENT '是否在售 0否 1是'")
private Integer is_sales;
@Column(columnDefinition="int(1) COMMENT '是否关闭 0否 1是'")
private Integer is_close;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setVideo_id(Integer video_id) {
this.video_id = video_id;
}
public Integer getVideo_id() {
return video_id;
}
public void setExpire_hours(Integer expire_hours) {
this.expire_hours = expire_hours;
}
public Integer getExpire_hours() {
return expire_hours;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getPrice() {
return price;
}
public void setIs_sales(Integer is_sales) {
this.is_sales = is_sales;
}
public Integer getIs_sales() {
return is_sales;
}
public void setIs_close(Integer is_close) {
this.is_close = is_close;
}
public Integer getIs_close() {
return is_close;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="t_licence_user")
public class T_licence_user implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10)")
private Integer id;
@Column(columnDefinition="int(10)")
private Integer user_id;
@Column(columnDefinition="int(10)")
private Integer licence_id;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public Integer getUser_id() {
return user_id;
}
public void setLicence_id(Integer licence_id) {
this.licence_id = licence_id;
}
public Integer getLicence_id() {
return licence_id;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.math.BigDecimal;
@Entity(name="t_licence_user_payment")
public class T_licence_user_payment implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10) COMMENT '支付流水'")
private Integer id;
@Column(columnDefinition="int(10) COMMENT '用户ID'")
private Integer user_id;
@Column(columnDefinition="int(10) COMMENT '许可证ID'")
private Integer licence_id;
@Column(columnDefinition="decimal(10,2) COMMENT '支付金额'")
private BigDecimal pay_amount;
@Column(columnDefinition="int(1) COMMENT '支付状态: 0未支付 1支付成功 2支付失败'")
private Integer pay_status;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public Integer getUser_id() {
return user_id;
}
public void setLicence_id(Integer licence_id) {
this.licence_id = licence_id;
}
public Integer getLicence_id() {
return licence_id;
}
public void setPay_amount(BigDecimal pay_amount) {
this.pay_amount = pay_amount;
}
public BigDecimal getPay_amount() {
return pay_amount;
}
public void setPay_status(Integer pay_status) {
this.pay_status = pay_status;
}
public Integer getPay_status() {
return pay_status;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="t_user")
public class T_user implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10)")
private Integer id;
@Column(columnDefinition="varchar(255)")
private String username;
@Column(columnDefinition="varchar(255)")
private String password;
@Column(columnDefinition="varchar(255)")
private String display_name;
@Column(columnDefinition="varchar(255)")
private String token;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setDisplay_name(String display_name) {
this.display_name = display_name;
}
public String getDisplay_name() {
return display_name;
}
public void setToken(String token) {
this.token = token;
}
public String getToken() {
return token;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity(name="t_video")
public class T_video implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10) COMMENT '视频ID '")
private Integer id;
@Column(columnDefinition="varchar(255) COMMENT '视频名称'")
private String name;
@Column(columnDefinition="varchar(255) COMMENT '一句话简介'")
private String desc;
@Column(columnDefinition="longtext COMMENT '剧情简介'")
private String profiles;
@Column(columnDefinition="int(4) COMMENT '年份'")
private Integer year;
@Column(columnDefinition="varchar(255) COMMENT '国家'")
private String country;
@Column(columnDefinition="varchar(255) COMMENT '封面图片'")
private String cover;
@Column(columnDefinition="int(1) COMMENT '是否免费 0否 1是'")
private Integer is_free;
@Column(columnDefinition="int(1) COMMENT '是否显示 0否 1是'")
private Integer is_show;
@Column(columnDefinition="int(1) COMMENT '影片来源 0管理员添加 1电影节导入'")
private Integer source;
@Column(columnDefinition="varchar(255) COMMENT '影片识别ID'")
private String source_key;
@Column(columnDefinition="decimal(10,2)")
private BigDecimal base_score;
@Column(columnDefinition="datetime")
private Date create_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
public void setProfiles(String profiles) {
this.profiles = profiles;
}
public String getProfiles() {
return profiles;
}
public void setYear(Integer year) {
this.year = year;
}
public Integer getYear() {
return year;
}
public void setCountry(String country) {
this.country = country;
}
public String getCountry() {
return country;
}
public void setCover(String cover) {
this.cover = cover;
}
public String getCover() {
return cover;
}
public void setIs_free(Integer is_free) {
this.is_free = is_free;
}
public Integer getIs_free() {
return is_free;
}
public void setIs_show(Integer is_show) {
this.is_show = is_show;
}
public Integer getIs_show() {
return is_show;
}
public void setSource(Integer source) {
this.source = source;
}
public Integer getSource() {
return source;
}
public void setSource_key(String source_key) {
this.source_key = source_key;
}
public String getSource_key() {
return source_key;
}
public void setBase_score(BigDecimal base_score) {
this.base_score = base_score;
}
public BigDecimal getBase_score() {
return base_score;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
}
package com.egolm.xplayer.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
@Entity(name="t_video_source")
public class T_video_source implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(10) COMMENT '视频源ID'")
private Integer id;
@Column(columnDefinition="int(10) COMMENT '视频ID '")
private Integer video_id;
@Column(columnDefinition="varchar(255) COMMENT '视频源名称'")
private String name;
@Column(columnDefinition="varchar(255) COMMENT '播放地址'")
private String play_key;
@Column(columnDefinition="varchar(255) COMMENT '预览播放地址'")
private String preview_play_key;
@Column(columnDefinition="int(1) COMMENT '1正片 2预告 3片花'")
private Integer type;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setVideo_id(Integer video_id) {
this.video_id = video_id;
}
public Integer getVideo_id() {
return video_id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPlay_key(String play_key) {
this.play_key = play_key;
}
public String getPlay_key() {
return play_key;
}
public void setPreview_play_key(String preview_play_key) {
this.preview_play_key = preview_play_key;
}
public String getPreview_play_key() {
return preview_play_key;
}
public void setType(Integer type) {
this.type = type;
}
public Integer getType() {
return type;
}
}
This diff is collapsed.
package com.egolm.xplayer.bean.model;
import java.io.Serializable;
public class XToken implements Serializable {
private static final long serialVersionUID = 1L;
private final Object id;
public XToken(Object id) {
this.id = id;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
public Object getId() {
return id;
}
}
package com.egolm.xplayer.config;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
@Component
public class AliyunUtil {
private DefaultAcsClient aliyunClient;
@Value("${aliyun.sts.accessKeyId}")
private String accessKeyId;
@Value("${aliyun.sts.accessKeySecret}")
private String accessKeySecret;
@PostConstruct
public void init() {
this.aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile("cn-shanghai", accessKeyId, accessKeySecret));
}
public GetVideoPlayAuthResponse getVideoPlayAuth(String videoId) throws Exception {
GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
request.setVideoId(videoId);
return aliyunClient.getAcsResponse(request);
}
}
package com.egolm.xplayer.config;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import com.alibaba.druid.pool.DruidDataSource;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.dialect.MySqlDialect;
import com.egolm.common.jdbc.dialect.MysqlTo;
@Configuration
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource getDataSource() {
return DataSourceBuilder.create().type(DruidDataSource.class).build();
}
@Bean
@Primary
public PlatformTransactionManager getTransactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Bean
@Primary
public JdbcTemplate getJdbcTemplate(DataSource dataSource) {
JdbcTemplate jdbcTemplate = new JdbcTemplate();
jdbcTemplate.setDataSource(dataSource);
jdbcTemplate.setDialect(new MySqlDialect());
jdbcTemplate.setSql_level(3);
return jdbcTemplate;
}
public static void main(String[] args) throws SQLException {
MysqlTo mysqlTo = new MysqlTo(
"D:\\eclipse-workspace\\egolm.com\\default\\xplayer\\src\\main\\java",
"com.egolm.xplayer.bean",
"曲欣亮", "10.10.0.111",
"xplayer",
"root",
"egolm#2018");
mysqlTo.execute();
}
}
\ No newline at end of file
package com.egolm.xplayer.config;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;
import com.alibaba.fastjson.JSON;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.xplayer.bean.S_logs_error;
@Component
public class ExceptionHandler implements HandlerExceptionResolver {
private static final Logger logger = Logger.getLogger(ExceptionHandler.class);
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
boolean displayInLog = true;
ModelAndView mav = new ModelAndView(new MappingJackson2JsonView());
try {
response.setContentType("application/json");
if (ex instanceof XException) {
Rjx rjx = ((XException) ex).getRjx();
mav.addAllObjects(rjx);
if(ex instanceof XRException) {
displayInLog = false;
logger.debug(ex.getMessage());
}
} else {
mav.addAllObjects(Rjx.jsonErr().setMessage("未处理异常"));
}
} catch (Exception e) {
mav.addAllObjects(Rjx.jsonErr().setMessage("异常处理失败"));
} finally {
if(displayInLog) {
logger.error("", ex);
try {
this.saveErrorLog(request.getRequestURI().replace(request.getContextPath(), ""), request.getParameterMap(), ex);
} catch (Exception e) {
logger.error("错误日志保存失败", e);
}
}
}
return mav;
}
private void saveErrorLog(String path, Object params, Throwable ex) {
S_logs_error error = new S_logs_error();
error.setTitle(ex.getMessage());
error.setPath(path);
error.setParams(JSON.toJSONString(params));
error.setError(this.toStackString(ex).toString());
error.setCreate_time(new Date());
jdbcTemplate.save(error);
}
private StringBuffer toStackString(Throwable ex) {
StringBuffer stack = new StringBuffer();
if(ex != null) {
stack.append(ex.getClass().getName()).append(ex.getMessage());
StackTraceElement[] elms = ex.getStackTrace();
for(StackTraceElement elm : elms) {
stack.append("\t").append(elm.getClassName()).append(".").append(elm.getMethodName()).append("(").append(elm.getFileName()).append(" ").append(elm.getLineNumber()).append(")\n");
}
stack.append("\n\n").append("Cause By: \n").append(this.toStackString(ex.getCause()));
for(Throwable e : ex.getSuppressed()) {
stack.append("\n\n").append("Suppressed By: \n").append(this.toStackString(e));
}
}
return stack;
}
}
package com.egolm.xplayer.config;
import java.util.ArrayList;
import java.util.List;
import com.egolm.common.StringUtil;
public class SqlWhere {
private List<String> strList;
private List<Object> objList;
public SqlWhere() {
this.strList = new ArrayList<String>();
this.objList = new ArrayList<Object>();
}
public SqlWhere where(String where, Object... obj) {
if(StringUtil.isNotBlank(where)) {
this.strList.add(where);
if(obj != null){
for(Object o : obj) {
this.objList.add(o);
}
}
}
return this;
}
public SqlWhere nn(String name) {
if(StringUtil.isNotBlank(name)) {
this.strList.add(name + " is not null");
}
return this;
}
public SqlWhere eq(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " = ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere ne(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " != ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere gt(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " > ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere lt(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " < ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere ge(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " >= ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere le(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " <= ?");
this.objList.add(obj);
}
return this;
}
public SqlWhere lk(String name, Object obj) {
if(StringUtil.isNotBlank(obj)) {
this.strList.add(name + " like ?");
this.objList.add("%" + obj + "%");
}
return this;
}
public SqlWhere lk(String[] name, Object obj) {
if(name != null && name.length > 0 && StringUtil.isNotBlank(obj)) {
StringBuffer sb = new StringBuffer();
sb.append("(");
for(int i = 0; i < name.length; i++) {
if(i > 0) {
sb.append(" or ");
}
sb.append(name[i] + " like ?");
this.objList.add("%" + obj + "%");
}
sb.append(")");
this.strList.add(sb.toString());
}
return this;
}
public SqlWhere in(String name, Object[] obj) {
if(obj != null && obj.length > 0) {
String str = name + " in (";
for(int i = 0; i < obj.length; i++) {
if(i > 0) {
str += ", ";
}
str += "?";
this.objList.add(obj[i]);
}
str += ")";
this.strList.add(str);
}
return this;
}
public List<String> getStringList() {
return strList;
}
public Object[] getObjectArray() {
return objList.toArray();
}
public List<Object> getObjectList() {
return objList;
}
}
package com.egolm.xplayer.config;
import java.text.SimpleDateFormat;
import java.util.EventListener;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import com.egolm.common.StringUtil;
import com.egolm.xplayer.config.interceptor.LogInterceptor;
import com.fasterxml.jackson.databind.ObjectMapper;
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Autowired
private LogInterceptor logInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(logInterceptor).addPathPatterns("/**").excludePathPatterns("/*.html").excludePathPatterns("/assets/**");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/page/");
}
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(false).setUseTrailingSlashMatch(false);
}
@Bean
public ServletListenerRegistrationBean<EventListener> getDemoListener(){
ServletListenerRegistrationBean<EventListener> registrationBean = new ServletListenerRegistrationBean<>();
registrationBean.setListener(new RequestContextListener());
return registrationBean;
}
@Bean
public ObjectMapper getObjectMapper(){
return new ObjectMapper().setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
}
public static HttpServletRequest getRequest() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes != null) {
return servletRequestAttributes.getRequest();
}
return null;
}
public static HttpServletResponse getResponse() {
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes != null) {
return servletRequestAttributes.getResponse();
}
return null;
}
public static HttpSession getSession() {
HttpServletRequest request = WebMvcConfig.getRequest();
if(request != null) {
return request.getSession();
}
return null;
}
public static Cookie getCookie(String name) {
HttpServletRequest request = WebMvcConfig.getRequest();
if(request != null) {
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(name)) {
return cookie;
}
}
}
}
return null;
}
public static Cookie getOrCreateUUIDCookie(String name, String path, int expiry, boolean httpOnly) {
HttpServletRequest request = WebMvcConfig.getRequest();
if(request != null) {
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(name)) {
return cookie;
}
}
}
}
Cookie cookie = new Cookie(name, StringUtil.getUid().toLowerCase());
cookie.setPath(path);
cookie.setHttpOnly(httpOnly);
cookie.setMaxAge(expiry);
getResponse().addCookie(cookie);
return cookie;
}
public static void removeCookie(String name) {
HttpServletRequest request = WebMvcConfig.getRequest();
HttpServletResponse response = WebMvcConfig.getResponse();
if(request != null) {
Cookie[] cookies = request.getCookies();
if(cookies != null) {
for(Cookie cookie : cookies) {
if(cookie.getName().equals(name)) {
cookie.setMaxAge(0);
cookie.setValue(null);
response.addCookie(cookie);
}
}
}
}
}
public static String getRemoteIp() {
HttpServletRequest request = WebMvcConfig.getRequest();
String ip = request.getHeader("X-Real_IP");
if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
ip = request.getHeader("X-Forwarded-For");
}
if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
ip = request.getHeader("Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if (ip == null || ip.length() == 0 || ip.equalsIgnoreCase("unknown")) {
ip = request.getRemoteAddr();
}
String[] ips = ip.trim().split(", ");
return ips[ips.length - 1].trim();
}
}
package com.egolm.xplayer.config;
import com.egolm.common.bean.Rjx;
public class XException extends RuntimeException {
private static final long serialVersionUID = 1L;
protected Rjx rjx = Rjx.jsonErr().setCode(500).setMessage("operation failed");
public XException(String msg) {
super(msg);
rjx.setMessage(msg);
}
public XException(String msg, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
}
public XException(String msg, int code) {
super(msg);
rjx.setMessage(msg);
rjx.setCode(code);
}
public XException(String msg, int code, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
rjx.setCode(code);
}
public Rjx getRjx() {
return rjx;
}
public static void assertNotBlank(String message, Object... objs) {
for(Object obj : objs) {
if(obj == null || obj.toString().trim().equals("")) {
throw new XException((message == null || message.trim().equals("")) ? "对象不能为空" : message);
}
}
}
}
package com.egolm.xplayer.config;
import com.egolm.common.bean.Rjx;
public class XRException extends XException {
private static final long serialVersionUID = 1L;
public XRException(String msg) {
super(msg);
rjx.setMessage(msg);
}
public XRException(String msg, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
}
public XRException(String msg, int code) {
super(msg);
rjx.setMessage(msg);
rjx.setCode(code);
}
public XRException(String msg, int code, Throwable e) {
super(msg, e);
rjx.setMessage(msg);
rjx.setCode(code);
}
public Rjx getRjx() {
return rjx;
}
public static void assertNotBlank(String message, Object... objs) {
for(Object obj : objs) {
if(obj == null || obj.toString().trim().equals("")) {
throw new XException((message == null || message.trim().equals("")) ? "对象不能为空" : message);
}
}
}
}
package com.egolm.xplayer.config.interceptor;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import com.alibaba.fastjson.JSON;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.web.ServletUtil;
import com.egolm.xplayer.bean.S_logs;
import com.egolm.xplayer.web.service.UserTokenService;
@Component
public class LogInterceptor extends HandlerInterceptorAdapter {
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
UserTokenService userTokenService;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Date now = new Date();
String path = request.getRequestURI().replace(request.getContextPath(), "");
String prefix = path.split("/")[1];
Integer userId = userTokenService.getLoginId();
String content = JSON.toJSONString(request.getParameterMap());
String ip = ServletUtil.remoteIp(request);
String user_agent = request.getHeader("User-Agent");
S_logs log = new S_logs();
log.setUser_id(userId);
log.setCreate_time(now);
log.setContent(content);
log.setIp(ip);
log.setPath(path);
log.setPrefix(prefix);
log.setUser_agent(user_agent);
jdbcTemplate.save(log);
return super.preHandle(request, response, handler);
}
}
package com.egolm.xplayer.web;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.xplayer.config.SqlWhere;
@Controller
@RequestMapping("mv")
public class MvController {
@Autowired
JdbcTemplate jdbcTemplate;
@ResponseBody
@RequestMapping("getMvList")
public Rjx getMvList(String keyword, String year, String[] country, String[] category, Page page) {
if(page == null) {
page = new Page();
}
Integer year_start = null;
Integer year_end = null;
if(StringUtil.isNotBlank(year) && !"全部".equals(year)) {
if(year.contains("-")) {
String[] years = year.split("-");
year_start = Integer.valueOf(years[0]);
year_end = Integer.valueOf(years[1]);
} else {
year_start = year_end = Integer.valueOf(year);
}
}
SqlWhere where = new SqlWhere().eq("is_show", 1).ge("year", year_start).le("year", year_end).lk(new String[]{"name"}, keyword);
String sql = "select * from t_video" + StringUtil.join(" and ", " where ", where.getStringList());
List<Map<String, Object>> list = jdbcTemplate.limit(sql, page, where.getObjectArray());
return Rjx.jsonOk().setData(list);
}
}
package com.egolm.xplayer.web;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.PreparedStatementCreator;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.egolm.common.DateUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.xplayer.bean.T_video_source;
@Controller
@RequestMapping("admin/mvDownload")
public class MvDownloadController {
@Autowired
JdbcTemplate jdbcTemplate;
public void initMv() {
List<Map<String, Object>> list = jdbcTemplate.queryForList("select * from x_mvlist where upload_id is not null and upload_state = 2");
for(Map<String, Object> map : list) {
String name = (String)map.get("cn_name");
Integer is_show = 1;
String profiles = (String)map.get("intro");
String country = (String)map.get("film_country");
String upload_id = (String)map.get("upload_id");
String completion_date = (String)map.get("completion_date");
Integer year = null;
try {
Date date = DateUtil.parse(completion_date, "yyyy-MM");
year = Integer.valueOf(DateUtil.format(date, "yyyy"));
} catch (Exception e) {}
String cover = null;
Integer source = 1;
String source_key = map.get("id") + "";
Object[] argArray = new Object[] {name, is_show, profiles, country, year, cover, source, source_key, source, source_key};
String sql = "insert into t_video (name, is_show, profiles, country, year, cover, source, source_key) select ?, ?, ?, ?, ?, ?, ?, ? from dual where not exists(select 1 from t_video where source = ? and source_key = ?)";
KeyHolder keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
for(int i = 0; i <argArray.length; i++) {
ps.setObject(i+1, argArray[i]);
}
return ps;
}
}, keyHolder);
Long id = (Long)keyHolder.getKey();
if(id != null) {
T_video_source vs = new T_video_source();
vs.setVideo_id(id.intValue());
vs.setName(name);
vs.setPlay_key(upload_id);
jdbcTemplate.save(vs);
}
}
}
}
package com.egolm.xplayer.web;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.xplayer.bean.T_licence_user;
import com.egolm.xplayer.bean.T_video;
import com.egolm.xplayer.bean.T_video_source;
import com.egolm.xplayer.config.AliyunUtil;
import com.egolm.xplayer.config.XRException;
import com.egolm.xplayer.web.service.CommonService;
import com.egolm.xplayer.web.service.UserTokenService;
@Controller
@RequestMapping("player")
public class PlayerController {
@Autowired
AliyunUtil aliyun;
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
UserTokenService userTokenService;
@Autowired
CommonService common;
public Rjx getAuthCodeById(Integer id) {
T_video_source vs = common.queryById(id, T_video_source.class);
T_video video = common.queryById(vs.getVideo_id(), T_video.class);
String vid = vs.getPlay_key();
String authCode = null;
return Rjx.jsonOk().set("vid", vid).set("authCode", authCode).setData(video);
}
@ResponseBody
@PostMapping("getPlayList")
public Rjx getPlayList(Integer id) {
String sql = "select * from t_video_source where video_id = ?";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, id);
return Rjx.jsonOk().setData(list);
}
@ResponseBody
@PostMapping("getPlayAuth")
public Object getPlayAuth(String vsid) throws Exception {
XRException.assertNotBlank("视频ID不能为空", vsid);
T_video_source vs = common.queryById(vsid, T_video_source.class);
T_video v = common.queryById(vs.getVideo_id(), T_video.class);
boolean boo = false;
boolean isLogin = false;
if(v.getIs_free() != null && v.getIs_free() == 1) {
boo = true;
} else {
Integer userId = userTokenService.getLoginId();
if(userId != null) {
isLogin = true;
Integer vid = vs.getVideo_id();
List<Map<String, Object>> licenceList = jdbcTemplate.queryForList("select l.*, lu.create_time effectiv_time from t_licence l, t_licence_user lu where l.video_id = ? and l.is_close = 0 and l.id = lu.licence_id and lu.user_id = ?", vid, userId);
if(licenceList != null && licenceList.size() > 0) {
for(Map<String, Object> licenceMap : licenceList) {
Date effectiv_time = (Date)licenceMap.get("effectiv_time");
Integer expire_hours = (Integer) licenceMap.get("expire_hours");
Long expireTime = effectiv_time.getTime() + (expire_hours.longValue() * 60 * 60 * 1000);
if(expireTime >= System.currentTimeMillis()) {
boo = true;
break;
}
}
}
}
}
if(boo) {
GetVideoPlayAuthResponse response = aliyun.getVideoPlayAuth(vs.getPlay_key());
return Rjx.jsonOk().set("vid", vs.getPlay_key()).set("playAuth", response.getPlayAuth()).set("videoMeta", response.getVideoMeta());
} else {
if(isLogin) {
return Rjx.jsonErr().setMessage("没有播放权限");
} else {
return Rjx.json().setCode(300).setMessage("没有登陆");
}
}
}
@ResponseBody
@PostMapping("getLicenceByVideoId")
public Rjx getLicenceByVideoId(Integer id) {
String sql = "select * from t_licence where video_id = ? and is_close = 0 and is_sales = 1";
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql, id);
return Rjx.jsonOk().setData(list);
}
@ResponseBody
@PostMapping("createUserLicence")
public Rjx createUserLicence(Integer id) {
Integer userId = userTokenService.getLoginId();
if(userId == null) {
return Rjx.json().setCode(300).setMessage("没有登陆");
} else {
T_licence_user lu = new T_licence_user();
lu.setLicence_id(id);
lu.setCreate_time(new Date());
lu.setUser_id(userId);
jdbcTemplate.save(lu);
return Rjx.jsonOk();
}
}
}
package com.egolm.xplayer.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.xplayer.bean.T_user;
import com.egolm.xplayer.web.service.UserTokenService;
@Controller
@RequestMapping("user")
public class UserLoginController {
@Autowired
private UserTokenService tokenService;
@ResponseBody
@RequestMapping("doLogin")
public Rjx login(String username, String password) {
if(StringUtil.isBlank(username) || StringUtil.isBlank(password)) {
T_user loginAdmin = tokenService.getLoginBean();
if(loginAdmin != null) {
return Rjx.jsonOk().setMessage("会话已存在");
} else {
return Rjx.jsonErr().setMessage("登陆失败:用户名或密码不能为空");
}
} else {
T_user user = tokenService.doLogin();
if(user != null) {
return Rjx.jsonOk();
} else {
return Rjx.jsonErr().setMessage("登陆失败:用户名或密码错误");
}
}
}
@ResponseBody
@RequestMapping("getUpk")
public Rjx getUpk() {
Integer loginId = tokenService.getLoginId();
return Rjx.jsonOk().setData(loginId);
}
@ResponseBody
@RequestMapping("doLogout")
public Rjx logout() {
tokenService.doLogout();
return Rjx.jsonOk();
}
}
package com.egolm.xplayer.web.service;
import java.util.List;
import java.util.Map;
import com.egolm.common.jdbc.Page;
public interface CommonService {
void merge(Object obj);
void save(Object obj);
void update(Object obj);
void deleteById(Object id, Class<?> type);
<T> T queryById(Object id, Class<T> type);
void batchSave(List<Object> objs);
<T> List<T> queryAll(Class<T> requiredType);
List<Map<String, Object>> limit(Object bean, Page page);
<T> List<T> queryList(T bean);
}
package com.egolm.xplayer.web.service;
import com.egolm.xplayer.bean.T_user;
public interface UserTokenService {
String SESSION_LOGIN_TOKEN = "SESSION_USER_LOGIN_TOKEN";
String COOKIE_LOGIN_TOKEN = "COOKIE_USER_LOGIN_TOKEN";
T_user getLoginBean();
Integer getLoginId();
T_user doLogin();
void doLogout();
}
package com.egolm.xplayer.web.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.Util;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.common.jdbc.dialect.bean.Desc;
import com.egolm.common.jdbc.dialect.bean.Sql;
import com.egolm.xplayer.config.XRException;
import com.egolm.xplayer.web.service.CommonService;
@Service
public class CommonServiceImpl implements CommonService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public void merge(Object obj) {
this.jdbcTemplate.merge(obj);
}
@Override
public void save(Object obj) {
this.jdbcTemplate.save(obj);
}
@Override
public void deleteById(Object id, Class<?> type) {
Desc desc = new Desc(type);
String[] pks = desc.getColumnPkNames();
if(pks != null && pks.length == 1) {
String sql = "delete from " + desc.getName() + " where " + pks[0] + " = ?";
this.jdbcTemplate.executeUpdate(sql, id);
}
}
@Override
public <T> T queryById(Object id, Class<T> type) {
Desc desc = new Desc(type);
String tableName = desc.getName();
String[] pkNames = desc.getColumnPkNames();
if(pkNames.length != 1) {
throw new XRException("不存在唯一主键");
}
return jdbcTemplate.queryForBean("select * from " + tableName + " where " + pkNames[0] + " = ?", type, id);
}
@Override
public void update(Object obj) {
this.jdbcTemplate.update(obj);
}
@Override
public void batchSave(List<Object> objs) {
this.jdbcTemplate.batchSave(objs);
}
@Override
public <T> List<T> queryAll(Class<T> requiredType) {
Desc desc = new Desc(requiredType);
String sql = "select * from " + desc.getName();
return jdbcTemplate.queryForBeans(sql, requiredType);
}
@Override
public List<Map<String, Object>> limit(Object bean, Page page) {
Class<?> requiredType = bean.getClass();
Desc desc = new Desc(requiredType);
Map<String, Object> map = Util.toMap(bean);
Map<String, Object> byFields = new HashMap<String, Object>();
for(String key : map.keySet()) {
if(map.get(key) != null) {
byFields.put(key, map.get(key));
}
}
Map<String, Object> byColumns = jdbcTemplate.getDialect().fieldsToColumns(requiredType, byFields);
Sql sql = jdbcTemplate.getDialect().argsQuery(desc.getName(), byColumns);
return jdbcTemplate.limit(sql.getSql(), page, sql.getArgs());
}
@Override
public <T> List<T> queryList(T bean) {
@SuppressWarnings("unchecked")
Class<T> requiredType = (Class<T>)bean.getClass();
Desc desc = new Desc(requiredType);
Map<String, Object> map = Util.toMap(bean);
Map<String, Object> byFields = new HashMap<String, Object>();
for(String key : map.keySet()) {
if(map.get(key) != null) {
byFields.put(key, map.get(key));
}
}
Map<String, Object> byColumns = jdbcTemplate.getDialect().fieldsToColumns(requiredType, byFields);
Sql sql = jdbcTemplate.getDialect().argsQuery(desc.getName(), byColumns);
return jdbcTemplate.queryForBeans(sql.getSql(),requiredType , sql.getArgs());
}
}
package com.egolm.xplayer.web.service.impl;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.xplayer.bean.T_user;
import com.egolm.xplayer.config.WebMvcConfig;
import com.egolm.xplayer.config.XException;
import com.egolm.xplayer.web.service.UserTokenService;
@Service
public class UserTokenServiceImpl implements UserTokenService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Override
public T_user getLoginBean() {
HttpSession session = WebMvcConfig.getSession();
return (T_user)session.getAttribute(SESSION_LOGIN_TOKEN);
}
@Override
public Integer getLoginId() {
T_user user = this.getLoginBean();
if(user != null) {
return user.getId();
}
return null;
}
@Override
public T_user doLogin() {
HttpServletRequest request = WebMvcConfig.getRequest();
String username = request.getParameter("username");
String password = request.getParameter("password");
String pwdMd5Str = StringUtil.toMD5HexString(password);
try {
String sql = "select * from t_user where username = ? and password = ?";
T_user user = jdbcTemplate.queryForBean(sql, T_user.class, username, pwdMd5Str);
HttpSession session = request.getSession();
session.setAttribute(SESSION_LOGIN_TOKEN, user);
Cookie cookie = WebMvcConfig.getOrCreateUUIDCookie(COOKIE_LOGIN_TOKEN, "/", 60*60*24*5, true);
if(cookie != null) {
jdbcTemplate.executeUpdate("update t_user set token = ? where id = ?", cookie.getValue(), user.getId());
}
return user;
} catch (Exception e) {
throw new XException("用户名或密码错误", e);
}
}
@Override
public void doLogout() {
HttpSession session = WebMvcConfig.getSession();
session.removeAttribute(SESSION_LOGIN_TOKEN);
session.invalidate();
}
public static void main(String[] args) {
System.out.println(StringUtil.toMD5HexString("linkfern#2019"));
}
}
server.port=60001
server.context-path=/xplayer
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
server.session.timeout=90000
spring.datasource.url=jdbc:mysql://10.10.0.111:3306/xplayer?useSSL=false&useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=egolm#2018
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=false
spring.datasource.test-on-return=false
spring.datasource.validation-query=select 1 from dual
spring.datasource.time-between-eviction-runs-millis=300000
spring.datasource.min-evictable-idle-time-millis=1800000
spring.datasource.max-wait=10000
spring.datasource.initial-size=10
spring.datasource.max-active=100
spring.datasource.min-idle=10
aliyun.sts.accessKeyId=LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
\ No newline at end of file
server.port=60001
server.context-path=/xplayer
server.tomcat.max-threads=1000
server.tomcat.min-spare-threads=30
server.tomcat.uri-encoding=utf-8
spring.http.multipart.maxFileSize=5MB
spring.http.multipart.maxRequestSize=5MB
spring.http.encoding.force=true
spring.http.encoding.enabled=true
spring.http.encoding.charset=utf-8
server.session.timeout=90000
spring.datasource.url=jdbc:mysql://10.10.0.111:3306/xplayer?useSSL=false&useUnicode=true&characterEncoding=utf8
spring.datasource.username=root
spring.datasource.password=egolm#2018
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.test-while-idle=true
spring.datasource.test-on-borrow=false
spring.datasource.test-on-return=false
spring.datasource.validation-query=select 1 from dual
spring.datasource.time-between-eviction-runs-millis=300000
spring.datasource.min-evictable-idle-time-millis=1800000
spring.datasource.max-wait=10000
spring.datasource.initial-size=10
spring.datasource.max-active=100
spring.datasource.min-idle=10
aliyun.sts.accessKeyId=LTAIOtHCCpDLXYp8
aliyun.sts.accessKeySecret=9XTHW7P9TTRvCsBHBSclOue2tdWOoa
\ No newline at end of file
spring.profiles.active=dev
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="siftingAppender" class="ch.qos.logback.classic.sift.SiftingAppender">
<discriminator>
<key>context</key>
<DefaultValue>logback</DefaultValue>
</discriminator>
<sift>
<appender name="rollingFileAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/data/logs/xplayer/${context}-%d{yyyy-MM-dd}.log</FileNamePattern>
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
</sift>
</appender>
<root level="INFO">
<appender-ref ref="siftingAppender" />
</root>
<springProfile name="dev">
<root level="DEBUG">
<appender-ref ref="siftingAppender" />
</root>
</springProfile>
<springProfile name="pro">
<root level="INFO">
<appender-ref ref="siftingAppender" />
</root>
</springProfile>
<logger name="springfox" level="ERROR" />
<logger name="javax" level="ERROR" />
<logger name="java" level="ERROR" />
<logger name="net" level="ERROR" />
<logger name="org" level="INFO" />
</configuration>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="assets/favicon/favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>404</title>
<style type="text/css">
body,div,h3,h4,li,ol{margin:0;padding:0}
body{font:14px/1.5 'Microsoft YaHei','微软雅黑',Helvetica,Sans-serif;min-width:1200px;background:#f0f1f3;}
:focus{outline:0}
h3,h4,strong{font-weight:700}
a{color:#428bca;text-decoration:none}
a:hover{text-decoration:underline}
.error-page{background:#f0f1f3;padding:80px 0 180px}
.error-page-container{position:relative;z-index:1}
.error-page-main{position:relative;background:#f9f9f9;margin:0 auto;width:617px;-ms-box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:50px 50px 70px}
.error-page-main:before{content:'';display:block;background:url(img/errorPageBorder.png?1427783409637);height:7px;position:absolute;top:-7px;width:100%;left:0}
.error-page-main h3{font-size:24px;font-weight:400;border-bottom:1px solid #d0d0d0}
.error-page-main h3 strong{font-size:54px;font-weight:400;margin-right:20px}
.error-page-main h4{font-size:20px;font-weight:400;color:#333}
.error-page-actions{font-size:0;z-index:100}
.error-page-actions div{font-size:14px;display:inline-block;padding:30px 0 0 10px;width:50%;-ms-box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;color:#838383}
.error-page-actions ol{list-style:decimal;padding-left:20px}
.error-page-actions li{line-height:2.5em}
.error-page-actions:before{content:'';display:block;position:absolute;z-index:-1;bottom:17px;left:50px;width:200px;height:10px;-moz-box-shadow:4px 5px 31px 11px #999;-webkit-box-shadow:4px 5px 31px 11px #999;box-shadow:4px 5px 31px 11px #999;-moz-transform:rotate(-4deg);-webkit-transform:rotate(-4deg);-ms-transform:rotate(-4deg);-o-transform:rotate(-4deg);transform:rotate(-4deg)}
.error-page-actions:after{content:'';display:block;position:absolute;z-index:-1;bottom:17px;right:50px;width:200px;height:10px;-moz-box-shadow:4px 5px 31px 11px #999;-webkit-box-shadow:4px 5px 31px 11px #999;box-shadow:4px 5px 31px 11px #999;-moz-transform:rotate(4deg);-webkit-transform:rotate(4deg);-ms-transform:rotate(4deg);-o-transform:rotate(4deg);transform:rotate(4deg)}
</style>
</head>
<body>
<div class="error-page">
<div class="error-page-container">
<div class="error-page-main">
<h3>
<strong>404</strong>很抱歉,您要访问的页面不存在!
</h3>
<div class="error-page-actions">
<div>
<h4>可能原因:</h4>
<ol>
<li>网站正在维护</li>
<li>功能正在开发</li>
</ol>
</div>
<div>
<h4>可以尝试:</h4>
<ol>
<li><a href="index.html">返回首页</a></li>
<li><a href="javascript:window.close();">关闭本页</a></li>
</ol>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
\ No newline at end of file
$.extend({
getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r != null){
return unescape(r[2]);
}
return null;
},
toQueryString(args) {
var keys = [];
for(var key in args) {
keys.push(key);
}
keys.sort();
var string = "";
for(var i = 0; i < keys.length; i++) {
var key = keys[i];
var vals = args[key];
if(!Array.isArray(vals)) {
vals = [vals];
}
for(var k = 0; k < vals.length; k++) {
var val = vals[k];
string += (key + "=" + (val ? val : ""));
string += (i == (keys.length-1) && k == (vals.length-1)) ? "" : "&";
}
}
return string;
},
showLoading(options) {
var defaults = {
"text":"",
"z-index": 999
};
var settings = $.extend({},defaults, options);
if(!$("body > div.ajax_overlay")[0]) {
$("body").append("<div class='ajax_overlay' style='background: #000; display: none; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; z-index: " + settings["z-index"] + ";'>" + settings["text"] + "</div>");
}
$("body > div.ajax_overlay").height(document.innerHeight);
$("body > div.ajax_overlay").width(document.innerWidth);
$("body > div.ajax_overlay").fadeTo(200, 0.2);
},
hideLoading() {
$("body > div.ajax_overlay").fadeOut(200);
},
getUuid() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23] = "";
var uuid = s.join("");
return uuid;
},
canMove(head, content){
$(head).mousedown(function (ex) {
var isMove = true;
var x = ex.pageX - $(content).position().left;
var y = ex.pageY - $(content).position().top;
var w = $(content).width();
var h = $(content).height();
var iw = window.innerWidth;
var ih = window.innerHeight;
$(document).mousemove(function (e) {
var left = e.pageX - x;
var top = e.pageY - y;
var right = left + w + 2;
var bottom = top + h + 2;
if (isMove && left > 0 && top > 0 && right < iw && bottom < ih) {
$(content).css({"transform": "none", "left":left, "top":top});
}
}).mouseup(
function () {
isMove = false;
});
});
},
getContextPath() {
var pathName = document.location.pathname;
var index = pathName.substr(1).indexOf("/");
return pathName.substr(0,index+1);
}
});
$.ajaxSetup({
type: "post",
dataType: "json",
scriptCharset: "utf-8",
contentType: "application/x-www-form-urlencoded",
cache: false,
timeout: 5000
});
$(document).ajaxStart(function() {
$.showLoading();
});
$(document).ajaxStop(function() {
$.hideLoading();
});
/*!
* jquery.base64.js 0.1 - https://github.com/yckart/jquery.base64.js
* Makes Base64 en & -decoding simpler as it is.
*
* Based upon: https://gist.github.com/Yaffle/1284012
*
* Copyright (c) 2012 Yannick Albert (http://yckart.com)
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php).
* 2013/02/10
**/
;(function($) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
a256 = '',
r64 = [256],
r256 = [256],
i = 0;
var UTF8 = {
/**
* Encode multi-byte Unicode string into utf-8 multiple single-byte characters
* (BMP / basic multilingual plane only)
*
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
*
* @param {String} strUni Unicode string to be encoded as UTF-8
* @returns {String} encoded string
*/
encode: function(strUni) {
// use regular expressions & String.replace callback function for better efficiency
// than procedural approaches
var strUtf = strUni.replace(/[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
function(c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
})
.replace(/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
function(c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3F, 0x80 | cc & 0x3f);
});
return strUtf;
},
/**
* Decode utf-8 encoded string back into multi-byte Unicode characters
*
* @param {String} strUtf UTF-8 string to be decoded back to Unicode
* @returns {String} decoded string
*/
decode: function(strUtf) {
// note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
var strUni = strUtf.replace(/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
function(c) { // (note parentheses for precence)
var cc = ((c.charCodeAt(0) & 0x0f) << 12) | ((c.charCodeAt(1) & 0x3f) << 6) | (c.charCodeAt(2) & 0x3f);
return String.fromCharCode(cc);
})
.replace(/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
function(c) { // (note parentheses for precence)
var cc = (c.charCodeAt(0) & 0x1f) << 6 | c.charCodeAt(1) & 0x3f;
return String.fromCharCode(cc);
});
return strUni;
}
};
while(i < 256) {
var c = String.fromCharCode(i);
a256 += c;
r256[i] = i;
r64[i] = b64.indexOf(c);
++i;
}
function code(s, discard, alpha, beta, w1, w2) {
s = String(s);
var buffer = 0,
i = 0,
length = s.length,
result = '',
bitsInBuffer = 0;
while(i < length) {
var c = s.charCodeAt(i);
c = c < 256 ? alpha[c] : -1;
buffer = (buffer << w1) + c;
bitsInBuffer += w1;
while(bitsInBuffer >= w2) {
bitsInBuffer -= w2;
var tmp = buffer >> bitsInBuffer;
result += beta.charAt(tmp);
buffer ^= tmp << bitsInBuffer;
}
++i;
}
if(!discard && bitsInBuffer > 0) result += beta.charAt(buffer << (w2 - bitsInBuffer));
return result;
}
var Plugin = $.base64 = function(dir, input, encode) {
return input ? Plugin[dir](input, encode) : dir ? null : this;
};
Plugin.btoa = Plugin.encode = function(plain, utf8encode) {
plain = Plugin.raw === false || Plugin.utf8encode || utf8encode ? UTF8.encode(plain) : plain;
plain = code(plain, false, r256, b64, 8, 6);
return plain + '===='.slice((plain.length % 4) || 4);
};
Plugin.atob = Plugin.decode = function(coded, utf8decode) {
coded = String(coded).split('=');
var i = coded.length;
do {--i;
coded[i] = code(coded[i], true, r64, a256, 6, 8);
} while (i > 0);
coded = coded.join('');
return Plugin.raw === false || Plugin.utf8decode || utf8decode ? UTF8.decode(coded) : coded;
};
}(jQuery));
\ No newline at end of file
/**
* Cookie plugin
*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Create a cookie with the given name and value and other optional parameters.
*
* @example $.cookie('the_cookie', 'the_value');
* @desc Set the value of a cookie.
* @example $.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true});
* @desc Create a cookie with all available options.
* @example $.cookie('the_cookie', 'the_value');
* @desc Create a session cookie.
* @example $.cookie('the_cookie', null);
* @desc Delete a cookie by passing null as value.
*
* @param String name The name of the cookie.
* @param String value The value of the cookie.
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
* If set to null or omitted, the cookie will be a session cookie and will not be retained
* when the the browser exits.
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
* require a secure protocol (like HTTPS).
* @type undefined
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
/**
* Get the value of a cookie with the given name.
*
* @example $.cookie('the_cookie');
* @desc Get the value of a cookie.
*
* @param String name The name of the cookie.
* @return The value of the cookie.
* @type String
*
* @name $.cookie
* @cat Plugins/Cookie
* @author Klaus Hartl/klaus.hartl@stilbuero.de
*/
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment