Skip to content

Commit

Permalink
add used count from app
Browse files Browse the repository at this point in the history
  • Loading branch information
blackstar-baba committed Oct 29, 2020
1 parent 7539249 commit f40c5a4
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 57 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1.tmp</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.1.tmp</version>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/blackstar/softwarelab/bean/AppInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.blackstar.softwarelab.bean;

import com.blackstar.softwarelab.entity.App;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AppInfo extends App {

private Integer usedCount;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blackstar.softwarelab.bean.AppInfo;
import com.blackstar.softwarelab.common.BaseController;
import com.blackstar.softwarelab.common.DbConst;
import com.blackstar.softwarelab.entity.App;
Expand Down Expand Up @@ -47,28 +48,35 @@ public App get(@PathVariable String name) {


@RequestMapping(method = RequestMethod.GET)
public IPage<App> list(@RequestParam int pageNum, @RequestParam int pageSize) {
public IPage<App> list(@RequestParam int pageNum, @RequestParam int pageSize,@RequestParam(required = false) String type) {

Page<App> appPage = new Page<>(pageNum, pageSize);
QueryWrapper<App> appQueryWrapper = new QueryWrapper<App>().eq(DbConst.COLUMN_STATUS, DbConst.STATUS_NORMAL);
QueryWrapper<App> appQueryWrapper = new QueryWrapper<App>();
if(type != null && !type.equals("All")){
appQueryWrapper= appQueryWrapper.eq(DbConst.COLUMN_TYPE, type);
}
return appService.page(appPage, appQueryWrapper);
}

@RequestMapping(method = RequestMethod.GET, value = "?op=type")
public IPage<App> listByType(@RequestParam String type, @RequestParam int pageNum, @RequestParam int pageSize) {
Page<App> appPage = new Page<>(pageNum, pageSize);
QueryWrapper<App> appQueryWrapper = new QueryWrapper<App>()
.eq(DbConst.COLUMN_TYPE, type);
return appService.page(appPage, appQueryWrapper);
@RequestMapping(method = RequestMethod.GET, value = "/top/{number}")
public List<AppInfo> top(@PathVariable int number) {
if(number< 0 || number < 10 ){
throw new RuntimeException("number must in 0 and 10");
}
return appService.getTop(number);
}

@RequestMapping(method = RequestMethod.GET, value = "/names")
public List<String> getNameByType(@RequestParam String type){
@RequestMapping(method = RequestMethod.GET, value = "/names/{type}")
public List<String> getNameByType(@PathVariable String type){
if("All".equals(type)){
type = null;
}
return appService.getNameByType(type);
}



@RequestMapping(method = RequestMethod.GET, value = "?op=upgrade")
@RequestMapping(method = RequestMethod.POST, value = "?op=upgrade")
public boolean upgrade() {
return appSourceService.upgrade();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AppTypeController {
@RequestMapping(method = RequestMethod.GET)
public List<KeyValuePair> list(){
ArrayList<KeyValuePair> keyValuePairs = new ArrayList<>();
keyValuePairs.add(new KeyValuePair("All",""));
keyValuePairs.add(new KeyValuePair("All","All"));
keyValuePairs.add(new KeyValuePair("Util","Util"));
keyValuePairs.add(new KeyValuePair("Database","Database"));
keyValuePairs.add(new KeyValuePair("BI","BI"));
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/blackstar/softwarelab/entity/AppExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.blackstar.softwarelab.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import lombok.*;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
* <p>
*
* </p>
*
* @author blackstar
* @since 2020-10-25
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class AppExtension implements Serializable {

private static final long serialVersionUID = 1L;

@TableId
private String appName;

private Integer usedCount;

private LocalDateTime createTime;

private LocalDateTime updateTime;

private Integer status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public class AppVersion implements Serializable {

private static final long serialVersionUID = 1L;

@TableId
private String appName;

@TableId
private String version;

private String additionalInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @author jobob
* @since 2018-09-12
*/
public class PgGenerator {
public class DatabaseGenerator {

/**
* <p>
Expand All @@ -42,7 +42,7 @@ public static String scanner(String tip) {
System.out.println(help.toString());
if (scanner.hasNext()) {
String ipt = scanner.next();
if (StringUtils.isNotEmpty(ipt)) {
if (StringUtils.isNotBlank(ipt)) {
return ipt;
}
}
Expand All @@ -53,6 +53,8 @@ public static String scanner(String tip) {
* RUN THIS
*/
public static void main(String[] args) {

System.setProperty("log.path", System.getProperty("user.dir") + "/logs");
// 代码生成器
AutoGenerator mpg = new AutoGenerator();

Expand All @@ -66,11 +68,11 @@ public static void main(String[] args) {

// 数据源配置
DataSourceConfig dsc = new DataSourceConfig();
dsc.setUrl("jdbc:postgresql:https://localhost:5432/softwarelab");
// dsc.setSchemaName("public");
dsc.setDriverName("org.postgresql.Driver");
dsc.setUsername("postgres");
dsc.setPassword("postgres");
dsc.setUrl("jdbc:h2:~/.softwarelab/data;AUTO_SERVER=TRUE");
// dsc.setSchemaName("public");
dsc.setDriverName("org.h2.Driver");
dsc.setUsername("sa");
dsc.setPassword("softwarelab");
mpg.setDataSource(dsc);

// 包配置
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.blackstar.softwarelab.mapper;

import com.blackstar.softwarelab.entity.AppExtension;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
* <p>
* Mapper 接口
* </p>
*
* @author blackstar
* @since 2020-10-25
*/
public interface AppExtensionMapper extends BaseMapper<AppExtension> {

}
7 changes: 7 additions & 0 deletions src/main/java/com/blackstar/softwarelab/mapper/AppMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.blackstar.softwarelab.bean.AppInfo;
import com.blackstar.softwarelab.entity.App;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
Expand All @@ -26,4 +27,10 @@ public interface AppMapper extends BaseMapper<App> {
"</when>",
"</script>"})
List<String> getNameByType(@Param("type") String type);


@Select("select app.*,appExt.USED_COUNT from (\n" +
" select APP_NAME ,USED_COUNT from app_extension where used_count > 0 order by used_count desc\n" +
" ) appExt join APP app on appExt.APP_NAME = app.NAME limit #{limit}\n")
List<AppInfo> getTop(int topNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.blackstar.softwarelab.service;

import com.blackstar.softwarelab.entity.AppExtension;
import com.baomidou.mybatisplus.extension.service.IService;

/**
* <p>
* 服务类
* </p>
*
* @author blackstar
* @since 2020-10-25
*/
public interface IAppExtensionService extends IService<AppExtension> {

void addUsedCount(String appName);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.blackstar.softwarelab.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.blackstar.softwarelab.bean.AppInfo;
import com.blackstar.softwarelab.entity.App;

import java.util.List;
Expand All @@ -18,4 +19,6 @@ public interface IAppService extends IService<App> {
List<String> getNameByType(String type);

App getByName(String name);

List<AppInfo> getTop(int topNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.blackstar.softwarelab.service.impl;

import com.blackstar.softwarelab.common.DbConst;
import com.blackstar.softwarelab.entity.AppExtension;
import com.blackstar.softwarelab.mapper.AppExtensionMapper;
import com.blackstar.softwarelab.service.IAppExtensionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
* <p>
* 服务实现类
* </p>
*
* @author blackstar
* @since 2020-10-25
*/
@Service
public class AppExtensionServiceImpl extends ServiceImpl<AppExtensionMapper, AppExtension> implements IAppExtensionService {

@Override
public void addUsedCount(String appName) {
LocalDateTime now = LocalDateTime.now();
AppExtension appExtension = this.getById(appName);
if (appExtension != null) {
//
appExtension.setUsedCount(appExtension.getUsedCount() + 1)
.setUpdateTime(now);
} else {
appExtension = AppExtension.builder()
.appName(appName)
.usedCount(1)
.createTime(now)
.updateTime(now)
.status(DbConst.STATUS_NORMAL)
.build();

}
this.saveOrUpdate(appExtension);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blackstar.softwarelab.common.DbConst;
import com.blackstar.softwarelab.bean.AppInfo;
import com.blackstar.softwarelab.entity.App;
import com.blackstar.softwarelab.mapper.AppMapper;
import com.blackstar.softwarelab.service.IAppService;
Expand Down Expand Up @@ -31,4 +31,9 @@ public List<String> getNameByType(String type) {
public App getByName(String name) {
return this.getOne(new QueryWrapper<App>().eq("name",name));
}

@Override
public List<AppInfo> getTop(int topNumber) {
return this.baseMapper.getTop(topNumber);
}
}
Loading

0 comments on commit f40c5a4

Please sign in to comment.