|
@@ -8,12 +8,12 @@ import com.finikes.oc.vote.dto.*;
|
|
|
import com.finikes.oc.vote.service.VoteService;
|
|
import com.finikes.oc.vote.service.VoteService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 投票控制器
|
|
* 投票控制器
|
|
@@ -155,17 +155,45 @@ public class VoteController {
|
|
|
/**
|
|
/**
|
|
|
* 代理投票
|
|
* 代理投票
|
|
|
*
|
|
*
|
|
|
- * @param dto 代理投票数据传输对象
|
|
|
|
|
* @return 接口返回对象
|
|
* @return 接口返回对象
|
|
|
*/
|
|
*/
|
|
|
@PutMapping("/choice/delegation")
|
|
@PutMapping("/choice/delegation")
|
|
|
- public ApiResponse<SignCodeDTO> choiceDelegation(@RequestBody @Valid ChoiceDelegationDto dto) {
|
|
|
|
|
- int signCode = voteService.madeChoiceDelegation(dto);
|
|
|
|
|
|
|
+ public ApiResponse<SignCodeDTO> choiceDelegation(@RequestParam("photo") MultipartFile photo, @RequestParam("optionId") Integer optionId
|
|
|
|
|
+ , @RequestParam("houseId") Integer houseId, @RequestParam("signature") String signature) {
|
|
|
|
|
+ ChoiceDelegationDto dto = new ChoiceDelegationDto();
|
|
|
|
|
+ dto.setHouseId(houseId);
|
|
|
|
|
+ dto.setOptionId(optionId);
|
|
|
|
|
+ dto.setSignature(signature);
|
|
|
|
|
+ String extName = photo.getOriginalFilename().split("\\.")[1];
|
|
|
|
|
+ dto.setImgType(extName);
|
|
|
|
|
+ long[] insertResults = voteService.madeChoiceDelegation(dto);
|
|
|
|
|
+ int signCode = (int) insertResults[0];
|
|
|
|
|
+ long choiceId = insertResults[1];
|
|
|
|
|
+ try {
|
|
|
|
|
+ savePhoto(photo, choiceId, extName);
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ // fixme delete choice[choiceId] 模拟事务回滚
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
SignCodeDTO response = new SignCodeDTO();
|
|
SignCodeDTO response = new SignCodeDTO();
|
|
|
response.setSignCode(convertSignCode(signCode));
|
|
response.setSignCode(convertSignCode(signCode));
|
|
|
return ApiResponse.successful(response);
|
|
return ApiResponse.successful(response);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public String savePhoto(MultipartFile photo, long choiceId, String extName) throws IOException {//将文件保存到本地
|
|
|
|
|
+ String dir = "/home/ocv1-server";//建议这里写resources目录的绝对路径
|
|
|
|
|
+ File path = new File(dir + "/vote-photo/");
|
|
|
|
|
+ if (!path.exists()) {//如果当前目录不存在
|
|
|
|
|
+ path.mkdir();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ File file = new File(dir + "/vote-photo/" + choiceId + "." + extName);
|
|
|
|
|
+ photo.transferTo(file);//将此图像保存到file本地
|
|
|
|
|
+
|
|
|
|
|
+ return extName;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private String convertSignCode(int signCode) {
|
|
private String convertSignCode(int signCode) {
|
|
|
String code = Ten2Base36.decimalToBase36(signCode);
|
|
String code = Ten2Base36.decimalToBase36(signCode);
|
|
|
int diff = 6 - code.length();
|
|
int diff = 6 - code.length();
|