Compare commits

...

2 Commits

Author SHA1 Message Date
ssl 6bf0743a23 主要是一些备注 2 years ago
ssl 8924ed49e7 主要是一些备注 2 years ago
  1. 3
      vote-vue/src/components/Home.vue
  2. 2
      vote-vue/src/components/admin/vote/VoteItem.vue
  3. 11
      vote/src/main/java/com/votesystem/ssl/config/MyWebConfiguration.java
  4. 1
      vote/src/main/java/com/votesystem/ssl/controller/user/CandidateController.java
  5. 1
      vote/src/main/java/com/votesystem/ssl/service/IVoteRecordService.java
  6. 2
      vote/src/main/java/com/votesystem/ssl/service/impl/ActivityServiceImpl.java
  7. 30
      vote/src/main/java/com/votesystem/ssl/service/impl/CandidateServiceImpl.java
  8. 25
      vote/src/main/java/com/votesystem/ssl/service/impl/VoteRecordServiceImpl.java
  9. 6
      vote/src/main/resources/application.yml

3
vote-vue/src/components/Home.vue

@ -53,8 +53,9 @@
</div>
<div style="padding: 14px;color: #999; font-size: 12px;">
<span>{{ item.title }}</span><br>
</div>
</el-card>
</el-col>

2
vote-vue/src/components/admin/vote/VoteItem.vue

@ -88,7 +88,7 @@
<el-dropdown-item @click.native="setCurCandidate(scope.row)">
<el-upload
ref="upload"
action="http://localhost:8080/api/admin/candidate/covers"
action="http://localhost:8443/api/admin/candidate/covers"
with-credentials
:show-file-list="false"
:on-success="handleSuccess"

11
vote/src/main/java/com/votesystem/ssl/config/MyWebConfiguration.java

@ -18,18 +18,19 @@ public class MyWebConfiguration implements WebMvcConfigurer {
.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
.allowedHeaders("*")
.maxAge(3600);
} @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/api/file/**").addResourceLocations("file:" + imagePath + "/");
// registry.addResourceHandler(imagePath).addResourceLocations("file:" + imagePath + "/");
}
@Value("${image.save-path}")
private String imagePath;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(imagePath).addResourceLocations("file:" + imagePath + "/");
}
// @Override
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/api/file/**").addResourceLocations("file:" + "E:/project/vote/vote/img/");
// registry.addResourceHandler("/api/file/**").addResourceLocations("file:" + "E:\\date\\tmp\\work\\Tomcat\\localhost\\ROOT\\images");
// }
}

1
vote/src/main/java/com/votesystem/ssl/controller/user/CandidateController.java

@ -130,6 +130,7 @@ public class CandidateController {
try {
file.transferTo(f);
String imgURL = "http://localhost:8443/api/file/" + f.getName();
// String imgURL = "http://localhost:8080/images/" + f.getName();
return imgURL;
} catch (IOException e) {
e.printStackTrace();

1
vote/src/main/java/com/votesystem/ssl/service/IVoteRecordService.java

@ -10,4 +10,5 @@ public interface IVoteRecordService {
Result singleVote(String captcha, String captchaKey, VoteRecord voteRecord, HttpServletRequest request);
Result multipleVote(String captcha,String captchaKey,JSONObject voteData, HttpServletRequest request);
//Result multipleVote(String captcha, String captchaKey, VoteRecord voteRecord, HttpServletRequest request);
}

2
vote/src/main/java/com/votesystem/ssl/service/impl/ActivityServiceImpl.java

@ -98,7 +98,7 @@ public Result listActivityByUser(String userName,int page, int size) {
page = checkPage(page);
size = checkSize(size);
//根据创建日期降序
Sort sort = Sort.by(Sort.Direction.DESC, "createTime");
Sort sort = Sort.by(Sort.Direction.DESC, "create_time");
// page-1 是因为Spring Data JPA的页码从0开始计算,而传入的参数使用的是从1开始计算的标准页码。因此,需要将传入参数减1以得到正确的Spring Data JPA页码
Pageable pageable = PageRequest.of(page - 1, size,sort);
org.springframework.data.domain.Page<Activity> all = activityDAO.findAllByAuthor(userName,pageable);

30
vote/src/main/java/com/votesystem/ssl/service/impl/CandidateServiceImpl.java

@ -101,6 +101,12 @@ public class CandidateServiceImpl extends BaseService implements ICandidateServ
return ResultFactory.buildSuccessResult(all);
}
/**
* 更新候选人状态
* @param candidateId
* @param state
* @return
*/
@Override
public Result updateState(String candidateId, boolean state) {
Candidate candidateInDb = candidateDAO.findOneById(candidateId);
@ -113,18 +119,34 @@ public class CandidateServiceImpl extends BaseService implements ICandidateServ
return ResultFactory.buildSuccessResult("状态更新成功");
}
/**
* 查询所有已经排名的候选人记录 打包到List中
* @param activityId
* @return
*/
@Override
public Result listRankCandidate(String activityId) {
List<Candidate> all = candidateDAO.listRankCandidate(activityId);
return ResultFactory.buildSuccessResult(all);
}
/**
* 查询所有状态为正常的候选人记录 打包到list中
* @param activityId
* @return
*/
@Override
public Result listAllNormalCandidate(String activityId) {
List<Candidate> all = candidateDAO.findAllNormal(activityId);
return ResultFactory.buildSuccessResult(all);
}
/**
* 添加候选人信息 idWorker.nextId()生成唯一id
*
* @param candidate
* @return
*/
@Override
public Result addCandidate(Candidate candidate) {
@ -136,6 +158,12 @@ public class CandidateServiceImpl extends BaseService implements ICandidateServ
return ResultFactory.buildSuccessResult(candidate);
}
/**
* 候选人的其他信息封面图片
* @param candidateId
* @param candidate
* @return
*/
@Override
public Result updateCandidate(String candidateId, Candidate candidate) {
Candidate candidateFromDb = candidateDAO.findOneById(candidateId);

25
vote/src/main/java/com/votesystem/ssl/service/impl/VoteRecordServiceImpl.java

@ -53,6 +53,8 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
@Autowired
UserDAO userDAO;
// @Autowired
// VoteRecord voteRecord;
// private boolean isInIpRestrictAddress(VoteRecord voteRecord,String ipAddress,long time){
// Map<String,Object> aidMap = (Map<String, Object>) redisUtils.get(ipAddress);
@ -72,7 +74,7 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
// }
private int isInIpRestrictAddress(String aid, String ipAddress){
Map<String,Object> aidMap = (Map<String,Object>) redisUtils.get(ipAddress);
Map<String,Integer> aidMap = (Map<String,Integer>) redisUtils.get(ipAddress);
// Map<String,Object> ipMap = (Map<String, Object>) redisUtils.get(ipAddress);
if (aidMap == null){
@ -85,7 +87,7 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
}
private void setCurrentIpuserTotalVotes(String aid, String ipAddress, int userTotalVotes,long time){
Map<String,Object> aidMap = new HashMap<>();
Map<String,Integer> aidMap = new HashMap<>();
aidMap.put(aid,userTotalVotes);
redisUtils.set(ipAddress,aidMap,time);
}
@ -184,7 +186,7 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
voteRecord.getAid(),
request.getRemoteAddr());
if(0 != result){
// userTotalVotes = result;
// userTotalVotes = result;
if(result >= totalVotes){
return ResultFactory.buildFailResult("你已投过票或该IP投票次数已达上限");
}
@ -221,6 +223,15 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
}
}
/**
* 多选
* @param captcha
* @param captchaKey
* @param voteData
* @param request
* @return
*/
@Override
public Result multipleVote(String captcha,String captchaKey,JSONObject voteData ,HttpServletRequest request) {
log.info("voteData ==== > ",voteData);
@ -264,12 +275,13 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
// }
//判断是否是周期性投票
//1.非周期性投票
if(typeMap.get("cycleType").equals("false")){
int userTotalVotes = voteRecordDAO.countByAidAndUid(activity.getId(),uid);
// ip验证
if(activity.isIpRestrict()){
int result = isInIpRestrictAddress(
voteRecord.getAid(),
aid,
request.getRemoteAddr());
if(0 != result){
userTotalVotes = result;
@ -314,11 +326,12 @@ public class VoteRecordServiceImpl implements IVoteRecordService {
// ip验证
if(activity.isIpRestrict()){
int result = isInIpRestrictAddress(
voteRecord.getAid(),
aid,
request.getRemoteAddr());
if(0 != result){
// userTotalVotes = result;
if(result >= totalVotes){
// if(result >= totalVotes){
if(result >= 0){
return ResultFactory.buildFailResult("你已投过票或该IP投票次数已达上限");
}
}

6
vote/src/main/resources/application.yml

@ -1,13 +1,15 @@
server:
port: 8443
tomcat:
basedir: /date/tmp
spring:
application:
name: blog_system
datasource:
url: jdbc:mysql://localhost:3306/vote?characterEncoding=utf-8&useSSL=false
url: jdbc:mysql://localhost:3306/ssl?characterEncoding=utf-8&useSSL=false
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 963852
password: Qww1151868461
hikari:
minimum-idle: 3

Loading…
Cancel
Save