diff --git a/.gitignore b/.gitignore index 9acb04ae..b9d3f4d2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ */target/* */*.iml /.gradle/ -/application.pid \ No newline at end of file +/application.pid +.vscode/ \ No newline at end of file diff --git a/eladmin-fin/pom.xml b/eladmin-fin/pom.xml new file mode 100644 index 00000000..4daaab48 --- /dev/null +++ b/eladmin-fin/pom.xml @@ -0,0 +1,29 @@ + + + + eladmin + me.zhengjie + 2.6 + + 4.0.0 + + eladmin-fin + 理财模块 + + + 8 + 8 + UTF-8 + + + + + me.zhengjie + eladmin-tools + 2.6 + + + + \ No newline at end of file diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/domain/Stock.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/domain/Stock.java new file mode 100644 index 00000000..b088492d --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/domain/Stock.java @@ -0,0 +1,91 @@ +/* +* Copyright 2019-2020 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package me.zhengjie.fin.stock.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.sql.Timestamp; +import java.math.BigDecimal; +import java.io.Serializable; + +/** + * @website https://eladmin.vip + * @description / + * @author zhangjc + * @date 2023-02-07 + **/ +@Entity +@Data +@Table(name = "stock") +public class Stock implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Integer id; + + @Column(name = "`stock_code`", unique = true, nullable = false) + @NotBlank + @ApiModelProperty(value = "stockCode") + private String stockCode; + + @Column(name = "`stock_name`", unique = true, nullable = false) + @NotBlank + @ApiModelProperty(value = "stockName") + private String stockName; + + @Column(name = "`hold_amount`") + @ApiModelProperty(value = "holdAmount") + private Float holdAmount; + + @Column(name = "`hold_share`", nullable = false) + @NotNull + @ApiModelProperty(value = "holdShare") + private Float holdShare; + + @Column(name = "`current_price`") + @ApiModelProperty(value = "currentPrice") + private Float currentPrice; + + @Column(name = "`price_time`") + @ApiModelProperty(value = "priceTime") + private Timestamp priceTime; + + @Column(name = "`create_by`") + @ApiModelProperty(value = "createBy") + private String createBy; + + @Column(name = "`create_time`") + @ApiModelProperty(value = "createTime") + private Timestamp createTime; + + @Column(name = "`update_by`") + @ApiModelProperty(value = "updateBy") + private String updateBy; + + @Column(name = "`update_time`") + @ApiModelProperty(value = "updateTime") + private Timestamp updateTime; + + public void copy(Stock source) { + BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); + } +} \ No newline at end of file diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/repository/StockRepository.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/repository/StockRepository.java new file mode 100644 index 00000000..f19676e8 --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/repository/StockRepository.java @@ -0,0 +1,35 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.repository; + +import me.zhengjie.fin.stock.domain.Stock; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** + * @author zhangjc + * @date 2023-02-15 + */ +public interface StockRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据ID查询 + * + * @param id / + * @return / + */ + Stock findById(String id); +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/rest/StockController.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/rest/StockController.java new file mode 100644 index 00000000..af96a8f1 --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/rest/StockController.java @@ -0,0 +1,95 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.rest; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import me.zhengjie.annotation.Log; +import me.zhengjie.fin.stock.domain.Stock; +import me.zhengjie.fin.stock.service.StockService; +import me.zhengjie.fin.stock.service.dto.StockQueryCriteria; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Set; + +/** + * @author zhangjc + * @date 2023-02-14 + */ +@RestController +@Api(tags = "理财:股票") +@RequiredArgsConstructor +@RequestMapping("/api/stock") +public class StockController { + + private final StockService stockService; + + @ApiOperation("导出股票数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('stock:list')") + public void exportStock(HttpServletResponse response, StockQueryCriteria criteria) throws IOException { + stockService.download(stockService.queryAll(criteria), response); + } + + @ApiOperation(value = "查询服务器") + @GetMapping + @PreAuthorize("@el.check('Stock:list')") + public ResponseEntity queryStock(StockQueryCriteria criteria, Pageable pageable) { + return new ResponseEntity<>(stockService.queryAll(criteria, pageable), HttpStatus.OK); + } + + @Log("新增服务器") + @ApiOperation(value = "新增服务器") + @PostMapping + @PreAuthorize("@el.check('Stock:add')") + public ResponseEntity createStock(@Validated @RequestBody Stock resources) { + stockService.create(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @Log("修改服务器") + @ApiOperation(value = "修改服务器") + @PutMapping + @PreAuthorize("@el.check('Stock:edit')") + public ResponseEntity updateStock(@Validated @RequestBody Stock resources) { + stockService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除服务器") + @ApiOperation(value = "删除Server") + @DeleteMapping + @PreAuthorize("@el.check('Stock:del')") + public ResponseEntity deleteStock(@RequestBody Set ids) { + stockService.delete(ids); + return new ResponseEntity<>(HttpStatus.OK); + } + + @Log("测试连接服务器") + @ApiOperation(value = "测试连接服务器") + @PostMapping("/testConnect") + @PreAuthorize("@el.check('Stock:add')") + public ResponseEntity testConnectStock(@Validated @RequestBody Stock resources) { + return new ResponseEntity<>(stockService.testConnect(resources), HttpStatus.CREATED); + } +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/StockService.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/StockService.java new file mode 100644 index 00000000..8baa36e3 --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/StockService.java @@ -0,0 +1,104 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.service; + +import me.zhengjie.fin.stock.domain.Stock; +import me.zhengjie.fin.stock.service.dto.StockDto; +import me.zhengjie.fin.stock.service.dto.StockQueryCriteria; +import org.springframework.data.domain.Pageable; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Set; + +/** + * @author zhangjc + * @date 2023-02-15 + */ +public interface StockService { + + /** + * 分页查询 + * + * @param criteria 条件 + * @param pageable 分页参数 + * @return / + */ + Object queryAll(StockQueryCriteria criteria, Pageable pageable); + + /** + * 查询全部数据 + * + * @param criteria 条件 + * @return / + */ + List queryAll(StockQueryCriteria criteria); + + /** + * 根据ID查询 + * + * @param id / + * @return / + */ + StockDto findById(Long id); + + /** + * 创建 + * + * @param resources / + */ + void create(Stock resources); + + /** + * 编辑 + * + * @param resources / + */ + void update(Stock resources); + + /** + * 删除 + * + * @param ids / + */ + void delete(Set ids); + + /** + * 根据IP查询 + * + * @param ip / + * @return / + */ + StockDto findByIp(String ip); + + /** + * 测试登录服务器 + * + * @param resources / + * @return / + */ + Boolean testConnect(Stock resources); + + /** + * 导出数据 + * + * @param queryAll / + * @param response / + * @throws IOException / + */ + void download(List queryAll, HttpServletResponse response) throws IOException; +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockDto.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockDto.java new file mode 100644 index 00000000..4a736030 --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockDto.java @@ -0,0 +1,72 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.service.dto; + +import lombok.Getter; +import lombok.Setter; +import me.zhengjie.base.BaseDTO; +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.Objects; + +/** + * @author zhangjc + * @date 2023-02-15 + */ +@Getter +@Setter +public class StockDto extends BaseDTO implements Serializable { + + private Integer id; + + private String stockCode; + + private String stockName; + + private Float holdAmount; + + private Float holdShare; + + private Float currentPrice; + + private Timestamp priceTime; + + private String createBy; + + private Timestamp createTime; + + private String updateBy; + + private Timestamp updateTime; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + StockDto that = (StockDto) o; + return Objects.equals(id, that.id) && + Objects.equals(stockCode, that.stockCode); + } + + @Override + public int hashCode() { + return Objects.hash(id, stockCode); + } +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockQueryCriteria.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockQueryCriteria.java new file mode 100644 index 00000000..5d088ac4 --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/dto/StockQueryCriteria.java @@ -0,0 +1,38 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.service.dto; + +import lombok.Data; +import me.zhengjie.annotation.Query; +import java.sql.Timestamp; +import java.util.List; + +/** + * @author zhangjc + * @date 2023-02-14 + */ +@Data +public class StockQueryCriteria { + + /** + * 模糊 + */ + @Query(blurry = "name,ip,account") + private String blurry; + + @Query(type = Query.Type.BETWEEN) + private List createTime; +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/impl/StockServiceImpl.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/impl/StockServiceImpl.java new file mode 100644 index 00000000..8c5f641a --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/impl/StockServiceImpl.java @@ -0,0 +1,118 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.service.impl; + +import lombok.RequiredArgsConstructor; +import me.zhengjie.fin.stock.domain.Stock; +import me.zhengjie.fin.stock.repository.StockRepository; +import me.zhengjie.fin.stock.service.StockService; +import me.zhengjie.fin.stock.service.dto.StockDto; +import me.zhengjie.fin.stock.service.dto.StockQueryCriteria; +import me.zhengjie.fin.stock.service.mapstruct.StockMapper; +import me.zhengjie.utils.FileUtil; +import me.zhengjie.utils.PageUtil; +import me.zhengjie.utils.QueryHelp; +import me.zhengjie.utils.ValidationUtil; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.*; + +/** + * @author zhangjc + * @date 2023-02-15 + */ +@Service +@RequiredArgsConstructor +public class StockServiceImpl implements StockService { + + private final StockRepository stockRepository; + private final StockMapper stockMapper; + + @Override + public Object queryAll(StockQueryCriteria criteria, Pageable pageable) { + Page page = stockRepository.findAll( + (root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), + pageable); + return PageUtil.toPage(page.map(stockMapper::toDto)); + } + + @Override + public List queryAll(StockQueryCriteria criteria) { + return stockMapper.toDto(stockRepository.findAll( + (root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder))); + } + + @Override + public StockDto findById(Long id) { + Stock server = stockRepository.findById(id).orElseGet(Stock::new); + ValidationUtil.isNull(server.getId(), "Stock", "id", id); + return stockMapper.toDto(server); + } + + @Override + public StockDto findByIp(String ip) { + Stock deploy = stockRepository.findByIp(ip); + return stockMapper.toDto(deploy); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(Stock resources) { + stockRepository.save(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Stock resources) { + Stock stock = stockRepository.findById(resources.getId()).orElseGet(Stock::new); + ValidationUtil.isNull(stock.getId(), "Stock", "id", resources.getId()); + stock.copy(resources); + stockRepository.save(stock); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(Set ids) { + for (Long id : ids) { + stockRepository.deleteById(id); + } + } + + @Override + public void download(List queryAll, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (StockDto deployDto : queryAll) { + Map map = new LinkedHashMap<>(); + map.put("服务器名称", deployDto.getName()); + map.put("服务器IP", deployDto.getIp()); + map.put("端口", deployDto.getPort()); + map.put("账号", deployDto.getAccount()); + map.put("创建日期", deployDto.getCreateTime()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + public Boolean testConnect(Stock resources) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/mapstruct/StockMapper.java b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/mapstruct/StockMapper.java new file mode 100644 index 00000000..d825a6ba --- /dev/null +++ b/eladmin-fin/src/main/java/me/zhengjie/fin/stock/service/mapstruct/StockMapper.java @@ -0,0 +1,31 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package me.zhengjie.fin.stock.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.fin.stock.domain.Stock; +import me.zhengjie.fin.stock.service.dto.StockDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** + * @author zhangjc + * @date 2023-02-15 + */ +@Mapper(componentModel = "spring", uses = {}, unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface StockMapper extends BaseMapper { + +} diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index fc36c5c5..30fae235 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -19,6 +19,12 @@ + + me.zhengjie + eladmin-fin + 2.6 + + me.zhengjie diff --git a/eladmin-system/src/main/resources/config/application-dev.yml b/eladmin-system/src/main/resources/config/application-dev.yml index c96a9233..6708257c 100644 --- a/eladmin-system/src/main/resources/config/application-dev.yml +++ b/eladmin-system/src/main/resources/config/application-dev.yml @@ -5,8 +5,8 @@ spring: db-type: com.alibaba.druid.pool.DruidDataSource driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy url: jdbc:log4jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:eladmin}?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false - username: ${DB_USER:root} - password: ${DB_PWD:123456} + username: eladmin + password: Eladmin@12# # 初始连接数 initial-size: 5 # 最小连接数 diff --git a/pom.xml b/pom.xml index 7dc9a3c6..3cd4bb7b 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ eladmin-system eladmin-tools eladmin-generator + eladmin-fin ELADMIN 后台管理