|
@@ -0,0 +1,166 @@
|
|
|
|
+package com.fdkankan.scene.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.math.MathUtil;
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
|
+import cn.hutool.http.ContentType;
|
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
+import cn.hutool.poi.word.Word07Writer;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.fdkankan.common.util.DateExtUtil;
|
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
|
+import com.fdkankan.web.controller.BaseController;
|
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import rx.internal.util.LinkedArrayList;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+@RestController
|
|
|
|
+@RequestMapping("/service/scene/math")
|
|
|
|
+public class MathController extends BaseController {
|
|
|
|
+
|
|
|
|
+ @PostMapping("aaa")
|
|
|
|
+ public void aaa(@RequestBody JSONObject params) throws IOException {
|
|
|
|
+
|
|
|
|
+ int add = params.getIntValue("+");
|
|
|
|
+ int sub = params.getIntValue("-");
|
|
|
|
+ LinkedHashSet<String> pool = new LinkedHashSet<>();
|
|
|
|
+ LinkedList<String> addPool = aaa("+", add);
|
|
|
|
+ LinkedList<String> subPool = aaa("-", sub);
|
|
|
|
+
|
|
|
|
+ int max = add > sub ? add : sub;
|
|
|
|
+ LinkedList<String> out = new LinkedList<>();
|
|
|
|
+ for (int i = 0; i < max; i++) {
|
|
|
|
+ String addStr = "";
|
|
|
|
+ if (i+1 <= add) {
|
|
|
|
+ addStr = addPool.get(i);
|
|
|
|
+ } else {
|
|
|
|
+ addStr = " ";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String subStr = null;
|
|
|
|
+ if (i+1 <= sub) {
|
|
|
|
+ subStr = subPool.get(i);
|
|
|
|
+ } else {
|
|
|
|
+ subStr = " ";
|
|
|
|
+ }
|
|
|
|
+ out.add(addStr + " " + subStr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String path = ConstantFilePath.EXCEL_PATH + DateUtil.format(new Date(), DateExtUtil.dateStyle11) + ".docx";
|
|
|
|
+ try (Word07Writer writer = new Word07Writer()){
|
|
|
|
+ // 添加段落(标题)
|
|
|
|
+ writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分");
|
|
|
|
+ // 添加段落(正文)
|
|
|
|
+ writer.addText(new Font("宋体", Font.PLAIN, 22), "我是正文第一部分", "我是正文第二部分");
|
|
|
|
+ for (String s : out) {
|
|
|
|
+ writer.addText(new Font("宋体", Font.PLAIN, 22), s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 写出到文件
|
|
|
|
+ writer.flush(FileUtil.file(path));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.response.setContentType(ContentType.OCTET_STREAM.getValue());
|
|
|
|
+ this.response.setHeader("Content-Disposition", "attachment;filename=" + FileUtil.getName(path));
|
|
|
|
+ ServletOutputStream outputStream = this.response.getOutputStream();
|
|
|
|
+ int read = FileUtil.getInputStream(path).read();
|
|
|
|
+ outputStream.write(read);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
|
+ params.put("+", 5);
|
|
|
|
+ params.put("-", 6);
|
|
|
|
+
|
|
|
|
+ int add = params.getIntValue("+");
|
|
|
|
+ int sub = params.getIntValue("-");
|
|
|
|
+ LinkedHashSet<String> pool = new LinkedHashSet<>();
|
|
|
|
+ LinkedList<String> addPool = aaa("+", add);
|
|
|
|
+ LinkedList<String> subPool = aaa("-", sub);
|
|
|
|
+
|
|
|
|
+ int max = add > sub ? add : sub;
|
|
|
|
+ LinkedList<String> out = new LinkedList<>();
|
|
|
|
+ for (int i = 0; i < max; i++) {
|
|
|
|
+ String addStr = "";
|
|
|
|
+ if (i+1 <= add) {
|
|
|
|
+ addStr = addPool.get(i);
|
|
|
|
+ } else {
|
|
|
|
+ addStr = " ";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String subStr = null;
|
|
|
|
+ if (i+1 <= sub) {
|
|
|
|
+ subStr = subPool.get(i);
|
|
|
|
+ } else {
|
|
|
|
+ subStr = " ";
|
|
|
|
+ }
|
|
|
|
+ out.add(addStr + " " + subStr);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ try (Word07Writer writer = new Word07Writer()){
|
|
|
|
+ // 添加段落(标题)
|
|
|
|
+ writer.addText(new Font("方正小标宋简体", Font.PLAIN, 22), "我是第一部分", "我是第二部分");
|
|
|
|
+ // 添加段落(正文)
|
|
|
|
+ writer.addText(new Font("宋体", Font.PLAIN, 22), "我是正文第一部分", "我是正文第二部分");
|
|
|
|
+ for (String s : out) {
|
|
|
|
+ writer.addText(new Font("宋体", Font.PLAIN, 22), s);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 写出到文件
|
|
|
|
+ writer.flush(FileUtil.file("D:\\test\\wordWrite.docx"));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static LinkedList<String> aaa(String method, int limit){
|
|
|
|
+ LinkedList<String> pool = new LinkedList<>();
|
|
|
|
+ for (int i = 0; i < limit; i++){
|
|
|
|
+ boolean gen = false;
|
|
|
|
+ do {
|
|
|
|
+ gen = gen(pool, method);
|
|
|
|
+ }while (!gen);
|
|
|
|
+ }
|
|
|
|
+ return pool;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static boolean gen(LinkedList<String> pool, String method){
|
|
|
|
+ int r1 = RandomUtil.randomInt(1, 100);
|
|
|
|
+ int r2 = RandomUtil.randomInt(1, 100);
|
|
|
|
+ String r1Str = r1 + "";
|
|
|
|
+ if(r1Str.length() == 1){
|
|
|
|
+ r1Str = " " + r1Str;
|
|
|
|
+ }
|
|
|
|
+ String r2Str = r2 + "";
|
|
|
|
+ if(r2Str.length() == 1){
|
|
|
|
+ r2Str = " " + r2Str;
|
|
|
|
+ }
|
|
|
|
+ int result = -1;
|
|
|
|
+ String statment = null;
|
|
|
|
+ if("+".equals(method)){
|
|
|
|
+ result = r1 + r2;
|
|
|
|
+ statment = r1Str + " + " + r2Str + " = ";
|
|
|
|
+ }else{
|
|
|
|
+ result = r1 - r2;
|
|
|
|
+ statment = r1Str + " - " + r2Str + " = ";
|
|
|
|
+ }
|
|
|
|
+ if(result < 0 || result >= 100 || pool.contains(statment)){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ pool.add(statment);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|