diff --git a/luoo_cms/README.md b/luoo_cms/README.md new file mode 100644 index 0000000..2191e6f --- /dev/null +++ b/luoo_cms/README.md @@ -0,0 +1,3 @@ +# luoo_cms + +通用CMS (BANNER,协议,文章等,意见反馈) diff --git a/luoo_cms/pom.xml b/luoo_cms/pom.xml new file mode 100644 index 0000000..a723fc9 --- /dev/null +++ b/luoo_cms/pom.xml @@ -0,0 +1,62 @@ + + + 4.0.0 + + com.luoo + luoo_parent + 1.0-SNAPSHOT + + + luoo_cms + 通用CMS (BANNER,协议,文章等,意见反馈) + + + 8 + 8 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-data-redis + + + mysql + mysql-connector-java + + + com.luoo + luoo_common + 1.0-SNAPSHOT + + + org.projectlombok + lombok + true + + + org.springframework.cloud + spring-cloud-starter-netflix-eureka-client + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + + com.github.xiaoymin + knife4j-spring-boot-starter + 2.0.5 + + + + + \ No newline at end of file diff --git a/luoo_cms/src/main/java/com/luoo/cms/CmsApplication.java b/luoo_cms/src/main/java/com/luoo/cms/CmsApplication.java new file mode 100644 index 0000000..2c836ba --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/CmsApplication.java @@ -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); + } + +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/config/SwaggerConfig.java b/luoo_cms/src/main/java/com/luoo/cms/config/SwaggerConfig.java new file mode 100644 index 0000000..1cf190a --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/config/SwaggerConfig.java @@ -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; + } + +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/controller/BannerController.java b/luoo_cms/src/main/java/com/luoo/cms/controller/BannerController.java new file mode 100644 index 0000000..4fa7299 --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/controller/BannerController.java @@ -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 findById(@PathVariable String id){ + return Result.success(bannerService.findById(id)); + } + + @ApiOperation("banner列表") + @GetMapping("/list") + public Result> findById(){ + return Result.success(bannerService.bannerList()); + } + + @ApiOperation("添加一个banner") + @PostMapping + public Result add(@RequestBody Banner banner){ + bannerService.add(banner); + return Result.success(); + } + + @ApiOperation("通过id删除banner") + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id ){ + bannerService.deleteById(id); + return Result.success(); + } + +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/controller/CmsController.java b/luoo_cms/src/main/java/com/luoo/cms/controller/CmsController.java new file mode 100644 index 0000000..8f5a21b --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/controller/CmsController.java @@ -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 findById(@PathVariable String key){ + return Result.success(agreementService.findByKey(key)); + } + +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/dao/AgreementDao.java b/luoo_cms/src/main/java/com/luoo/cms/dao/AgreementDao.java new file mode 100644 index 0000000..ae3297d --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/dao/AgreementDao.java @@ -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 { + + @Query("select a from Agreement a where a.key = ?1") + Optional findByKey(String key); + + Optional findByKeyAndState(@NonNull String key, int state); +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/dao/BannerDao.java b/luoo_cms/src/main/java/com/luoo/cms/dao/BannerDao.java new file mode 100644 index 0000000..fc278e2 --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/dao/BannerDao.java @@ -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 { + +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/pojo/Agreement.java b/luoo_cms/src/main/java/com/luoo/cms/pojo/Agreement.java new file mode 100644 index 0000000..c1bc9bc --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/pojo/Agreement.java @@ -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(); +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/pojo/Banner.java b/luoo_cms/src/main/java/com/luoo/cms/pojo/Banner.java new file mode 100644 index 0000000..962e20a --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/pojo/Banner.java @@ -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(); +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/service/AgreementService.java b/luoo_cms/src/main/java/com/luoo/cms/service/AgreementService.java new file mode 100644 index 0000000..4a4e9ca --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/service/AgreementService.java @@ -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 example = Example.of(agreement); + return agreementDao.findOne(example).get(); + } + + + public Agreement findByKey(String key) { + //agreementDao.findByKeyAndState(key,0); + return agreementDao.findByKey(key).get(); + } +} diff --git a/luoo_cms/src/main/java/com/luoo/cms/service/BannerService.java b/luoo_cms/src/main/java/com/luoo/cms/service/BannerService.java new file mode 100644 index 0000000..580624e --- /dev/null +++ b/luoo_cms/src/main/java/com/luoo/cms/service/BannerService.java @@ -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 bannerList() { + return bannerDao.findAll(); + } +} diff --git a/luoo_cms/src/main/resources/application.yml b/luoo_cms/src/main/resources/application.yml new file mode 100644 index 0000000..b65eeba --- /dev/null +++ b/luoo_cms/src/main/resources/application.yml @@ -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 \ No newline at end of file diff --git a/luoo_cms/src/main/resources/bootstrap.yml b/luoo_cms/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..4ae74e2 --- /dev/null +++ b/luoo_cms/src/main/resources/bootstrap.yml @@ -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 \ No newline at end of file diff --git a/pom.xml b/pom.xml index fe2da0b..d0cb7f9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,7 @@ luoo_sms luoo_config luoo_tag + luoo_cms pom luoo_parent