/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.vote.controller;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import com.google.common.reflect.TypeToken;
|
import com.google.gson.Gson;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.option.entity.Option;
|
import org.springblade.modules.option.service.IOptionService;
|
import org.springblade.modules.vote.entity.Vote;
|
import org.springblade.modules.vote.service.IVoteService;
|
import org.springblade.modules.vote.vo.VoteVO;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.lang.reflect.Type;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 控制器
|
*
|
* @author BladeX
|
* @since 2022-01-24
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("vote/vote")
|
@Api(value = "", tags = "接口")
|
public class VoteController extends BladeController {
|
|
private final IVoteService voteService;
|
private final IOptionService optionService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入vote")
|
public R<Vote> detail(Vote vote) {
|
Vote detail = voteService.getOne(Condition.getQueryWrapper(vote));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入vote")
|
public R<IPage<Vote>> list(Vote vote, Query query) {
|
IPage<Vote> pages = voteService.page(Condition.getPage(query), Condition.getQueryWrapper(vote));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入vote")
|
public R<IPage<VoteVO>> page(VoteVO vote, Query query) {
|
IPage<VoteVO> pages = voteService.selectVotePage(Condition.getPage(query), vote);
|
return R.data(pages);
|
}
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入vote")
|
public R save(@Valid @RequestBody Vote vote) {
|
return R.status(voteService.save(vote));
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入vote")
|
public R update(@Valid @RequestBody Vote vote) {
|
return R.status(voteService.updateById(vote));
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入vote")
|
public R submit(@Valid @RequestBody Vote vote) {
|
return R.status(voteService.saveOrUpdate(vote));
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
return R.status(voteService.removeByIds(Func.toLongList(ids)));
|
}
|
|
/**
|
* 投票新增
|
*
|
* @param param
|
* @return
|
*/
|
@PostMapping("/sav")
|
public R sav(@RequestBody Map<Object, Object> param) {
|
//获取数组GKEY
|
String g = param.get("G").toString();
|
List<Object> marshallingGKEYList;
|
Gson gson = new Gson();
|
Type types = new TypeToken<List<Object>>() {
|
}.getType();
|
marshallingGKEYList = gson.fromJson(g, types);
|
//投票标题
|
String votename = param.get("votename").toString();
|
//介绍
|
String introduce = param.get("introduce").toString();
|
//发起人
|
String uid = param.get("uid").toString();
|
//发起时间
|
Date date = new Date();
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
|
String time = dateFormat.format(date);
|
//类型
|
String type = param.get("type").toString();
|
//投票新增
|
Vote vote = new Vote();
|
vote.setVotename(votename);
|
vote.setIntroduce(introduce);
|
vote.setUid(uid);
|
vote.setTime(time);
|
vote.setType(type);
|
vote.setOpnum(marshallingGKEYList.size());
|
voteService.save(vote);
|
Option option = new Option();
|
int num = 0;
|
for (int i = 0; i < marshallingGKEYList.size(); i++) {
|
num++;
|
option.setOptionname(marshallingGKEYList.get(i).toString());
|
option.setVoteid(vote.getId());
|
option.setOptiontype(num);
|
optionService.save(option);
|
}
|
return R.success("成功");
|
}
|
|
|
/**
|
* 投票列表查询
|
*
|
* @return
|
*/
|
@PostMapping("/selectList")
|
public R selectList() {
|
return R.data(voteService.selectList());
|
}
|
}
|