股票管理

pull/788/head
rebeyond1218 2023-02-17 10:41:42 +08:00
parent 164ce50bb0
commit 84d6f1587d
13 changed files with 624 additions and 3 deletions

3
.gitignore vendored
View File

@ -4,4 +4,5 @@
*/target/*
*/*.iml
/.gradle/
/application.pid
/application.pid
.vscode/

29
eladmin-fin/pom.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>eladmin</artifactId>
<groupId>me.zhengjie</groupId>
<version>2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-fin</artifactId>
<name>理财模块</name>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-tools</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>

View File

@ -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));
}
}

View File

@ -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<Stock, Long>, JpaSpecificationExecutor<Stock> {
/**
* ID
*
* @param id /
* @return /
*/
Stock findById(String id);
}

View File

@ -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<Object> 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<Object> createStock(@Validated @RequestBody Stock resources) {
stockService.create(resources);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@Log("修改服务器")
@ApiOperation(value = "修改服务器")
@PutMapping
@PreAuthorize("@el.check('Stock:edit')")
public ResponseEntity<Object> 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<Object> deleteStock(@RequestBody Set<Long> ids) {
stockService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("测试连接服务器")
@ApiOperation(value = "测试连接服务器")
@PostMapping("/testConnect")
@PreAuthorize("@el.check('Stock:add')")
public ResponseEntity<Object> testConnectStock(@Validated @RequestBody Stock resources) {
return new ResponseEntity<>(stockService.testConnect(resources), HttpStatus.CREATED);
}
}

View File

@ -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<StockDto> 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<Long> 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<StockDto> queryAll, HttpServletResponse response) throws IOException;
}

View File

@ -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);
}
}

View File

@ -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<Timestamp> createTime;
}

View File

@ -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<Stock> page = stockRepository.findAll(
(root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder),
pageable);
return PageUtil.toPage(page.map(stockMapper::toDto));
}
@Override
public List<StockDto> 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<Long> ids) {
for (Long id : ids) {
stockRepository.deleteById(id);
}
}
@Override
public void download(List<StockDto> queryAll, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (StockDto deployDto : queryAll) {
Map<String, Object> 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;
}
}

View File

@ -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<StockDto, Stock> {
}

View File

@ -19,6 +19,12 @@
</properties>
<dependencies>
<dependency>
<groupId>me.zhengjie</groupId>
<artifactId>eladmin-fin</artifactId>
<version>2.6</version>
</dependency>
<!-- 代码生成模块 -->
<dependency>
<groupId>me.zhengjie</groupId>

View File

@ -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
# 最小连接数

View File

@ -15,6 +15,7 @@
<module>eladmin-system</module>
<module>eladmin-tools</module>
<module>eladmin-generator</module>
<module>eladmin-fin</module>
</modules>
<name>ELADMIN 后台管理</name>