parent
2a60412e4f
commit
cbac8c653f
@ -0,0 +1,54 @@
|
||||
package com.luoo.cms;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.env.Environment;
|
||||
import util.IdWorker;
|
||||
import util.JwtUtil;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableEurekaClient
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class CmsApplication {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CmsApplication.class);
|
||||
|
||||
public static void main(String[] args) throws UnknownHostException {
|
||||
ConfigurableApplicationContext application = SpringApplication.run(CmsApplication.class, args);
|
||||
|
||||
Environment env = application.getEnvironment();
|
||||
|
||||
logger.info("\n----------------------------------------------------------\n\t"
|
||||
+ "Application '{}' is running! Access URLs:\n\t" + "Local: \t\thttp://localhost:{}\n\t"
|
||||
+ "External: \thttp://{}:{}\n\t" + "Doc: \thttp://{}:{}/doc.html\n\t"
|
||||
+ "Version: \tversion={},profiles={}\n" + "----------------------------------------------------------",
|
||||
env.getProperty("spring.application.name"), env.getProperty("server.port"),
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),
|
||||
InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"),
|
||||
env.getProperty("api.version"),env.getProperty("spring.profiles.active"));
|
||||
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtUtil jwtUtil(){
|
||||
return new JwtUtil();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdWorker idWorkker(){
|
||||
return new IdWorker(1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.luoo.cms.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
@EnableSwagger2
|
||||
@Configuration
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableEnvironment configurableEnvironment;
|
||||
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.apiInfo(apiInfo())
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.luoo.cms"))
|
||||
.paths(PathSelectors.any())
|
||||
.build().directModelSubstitute(LocalTime.class, String.class)
|
||||
.directModelSubstitute(LocalDate.class, String.class);
|
||||
String appName = configurableEnvironment.getProperty("spring.application.name");
|
||||
if (appName != null){
|
||||
docket.pathMapping(String.format("/%s", appName));
|
||||
}
|
||||
return docket;
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
ApiInfo info = new ApiInfoBuilder()
|
||||
.title("通用CMS")
|
||||
.description("通用CMS")
|
||||
.version("0.0.1")
|
||||
.contact(new Contact("通用CMS", "", ""))
|
||||
.build();
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.luoo.cms.controller;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import com.luoo.cms.service.BannerService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Api(tags = "banner轮播图")
|
||||
@RestController
|
||||
@RequestMapping("/banner")
|
||||
public class BannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@ApiOperation("通过id查询一个banner")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Banner> findById(@PathVariable String id){
|
||||
return Result.success(bannerService.findById(id));
|
||||
}
|
||||
|
||||
@ApiOperation("banner列表")
|
||||
@GetMapping("/list")
|
||||
public Result<List<Banner>> findById(){
|
||||
return Result.success(bannerService.bannerList());
|
||||
}
|
||||
|
||||
@ApiOperation("添加一个banner")
|
||||
@PostMapping
|
||||
public Result<Void> add(@RequestBody Banner banner){
|
||||
bannerService.add(banner);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation("通过id删除banner")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> delete(@PathVariable String id ){
|
||||
bannerService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.luoo.cms.controller;
|
||||
|
||||
|
||||
import api.Result;
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import com.luoo.cms.service.AgreementService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Api(tags = "通用CMS")
|
||||
@RestController
|
||||
@RequestMapping("/cms")
|
||||
public class CmsController {
|
||||
|
||||
@Autowired
|
||||
private AgreementService agreementService;
|
||||
|
||||
@ApiOperation("通过key查询")
|
||||
@GetMapping("/agreement/{key}")
|
||||
public Result<Agreement> findById(@PathVariable String key){
|
||||
return Result.success(agreementService.findByKey(key));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.luoo.cms.dao;
|
||||
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface AgreementDao extends JpaRepository<Agreement,String> {
|
||||
|
||||
@Query("select a from Agreement a where a.key = ?1")
|
||||
Optional<Agreement> findByKey(String key);
|
||||
|
||||
Optional<Agreement> findByKeyAndState(@NonNull String key, int state);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.luoo.cms.dao;
|
||||
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface BannerDao extends JpaRepository<Banner,String> {
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.luoo.cms.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "tb_agreement")
|
||||
@ApiModel(value = "协议")
|
||||
public class Agreement implements Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "url别名")
|
||||
private String key;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "内容")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private int state = 0;
|
||||
|
||||
@Column(name = "create_time")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
protected LocalDateTime createTime = LocalDateTime.now();
|
||||
|
||||
@Column(name = "update_time")
|
||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
protected LocalDateTime updateTime = LocalDateTime.now();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.luoo.cms.pojo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "tb_banner")
|
||||
@ApiModel(value = "banner轮播图")
|
||||
public class Banner implements Serializable {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty(value = "标题")
|
||||
private String title;
|
||||
|
||||
@ApiModelProperty(value = "图片地址")
|
||||
private String imgUrl;
|
||||
|
||||
@ApiModelProperty(value = "点击跳转地址")
|
||||
private String url;
|
||||
|
||||
@ApiModelProperty(value = "状态")
|
||||
private int state = 0;
|
||||
|
||||
@Column(name = "create_time")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:dd")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
protected LocalDateTime createTime = LocalDateTime.now();
|
||||
|
||||
@Column(name = "update_time")
|
||||
@ApiModelProperty(value = "更新时间", hidden = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
protected LocalDateTime updateTime = LocalDateTime.now();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.luoo.cms.service;
|
||||
|
||||
import com.luoo.cms.dao.AgreementDao;
|
||||
import com.luoo.cms.pojo.Agreement;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class AgreementService {
|
||||
|
||||
@Autowired
|
||||
private AgreementDao agreementDao;
|
||||
|
||||
public Agreement findByKey1(String key) {
|
||||
Agreement agreement = new Agreement();
|
||||
agreement.setKey(key);
|
||||
Example<Agreement> example = Example.of(agreement);
|
||||
return agreementDao.findOne(example).get();
|
||||
}
|
||||
|
||||
|
||||
public Agreement findByKey(String key) {
|
||||
//agreementDao.findByKeyAndState(key,0);
|
||||
return agreementDao.findByKey(key).get();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.luoo.cms.service;
|
||||
|
||||
import com.luoo.cms.dao.BannerDao;
|
||||
import com.luoo.cms.pojo.Banner;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import util.IdWorker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class BannerService {
|
||||
|
||||
@Autowired
|
||||
private BannerDao bannerDao;
|
||||
|
||||
@Autowired
|
||||
private IdWorker idWorker;
|
||||
|
||||
public Banner findById(String id) {
|
||||
return bannerDao.findById(id).get();
|
||||
}
|
||||
|
||||
public void add(Banner banner) {
|
||||
banner.setId(idWorker.nextId()+"");
|
||||
bannerDao.save(banner);
|
||||
}
|
||||
|
||||
public void deleteById(String id) {
|
||||
bannerDao.deleteById(id);
|
||||
}
|
||||
|
||||
public List<Banner> bannerList() {
|
||||
return bannerDao.findAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
server:
|
||||
port: 9014
|
||||
spring:
|
||||
application:
|
||||
name: luoo-cms #指定服务名
|
||||
datasource:
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://8.134.98.47:3307/indie_cms?characterEncoding=UTF8&useSSL=false
|
||||
username: root
|
||||
password: 47084735abc
|
||||
jpa:
|
||||
database: MySQL
|
||||
show-sql: true
|
||||
redis:
|
||||
host: 8.134.98.47
|
||||
port: 36379
|
||||
eureka:
|
||||
client:
|
||||
service-url:
|
||||
defaultZone: http://127.0.0.1:6868/eureka/
|
||||
instance:
|
||||
prefer-ip-address: true
|
@ -0,0 +1,8 @@
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
name: cms
|
||||
profile: dev
|
||||
label: master
|
||||
uri: http://116.62.145.60:12000
|
||||
# uri: http://127.0.0.1:12000
|
Loading…
Reference in new issue