|
|
@@ -1,6 +1,9 @@
|
|
|
package com.mokamrp.privates.controller.pangu;
|
|
|
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.model.PutObjectRequest;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.mokamrp.privates.config.OSSConfiguration;
|
|
|
import com.mokamrp.privates.constant.HttpMsg;
|
|
|
import com.mokamrp.privates.constant.HttpStatus;
|
|
|
import com.mokamrp.privates.entity.PostBasePageHandle;
|
|
|
@@ -8,10 +11,14 @@ import com.mokamrp.privates.entity.ResHandle;
|
|
|
import com.mokamrp.privates.entity.VoltaHandle;
|
|
|
import com.mokamrp.privates.entity.pangu.AddFosterwxMobileHandle;
|
|
|
import com.mokamrp.privates.help.AjaxResult;
|
|
|
+import com.mokamrp.privates.help.Analysis;
|
|
|
+import com.mokamrp.privates.interceptor.AuthUser;
|
|
|
import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobile;
|
|
|
import com.mokamrp.privates.mapper.pangu.pojo.FosterwxStation;
|
|
|
+import com.mokamrp.privates.mapper.pojo.User;
|
|
|
import com.mokamrp.privates.service.pangu.FosterwxMobileService;
|
|
|
import com.mokamrp.privates.service.pangu.FosterwxStationService;
|
|
|
+import com.mokamrp.privates.utils.OssFile;
|
|
|
import org.aspectj.weaver.loadtime.Aj;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -21,12 +28,13 @@ import com.mokamrp.privates.service.pangu.FosterwxMobileWxfriendService;
|
|
|
import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobileWxfriend;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import com.mokamrp.privates.controller.BaseController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@@ -50,6 +58,11 @@ public class FosterwxMobileWxfriendController extends BaseController<FosterwxMob
|
|
|
|
|
|
@Autowired
|
|
|
public FosterwxMobileService fosterwxMobileService;
|
|
|
+ @Autowired
|
|
|
+ private OSSConfiguration ossConfiguration;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OSS ossClient;
|
|
|
/*
|
|
|
* @fast
|
|
|
* 默认生成的控制器所继承的父类中有index/add/edit/del四个基础方法,均为post json请求
|
|
|
@@ -65,6 +78,16 @@ public class FosterwxMobileWxfriendController extends BaseController<FosterwxMob
|
|
|
return AjaxResult.success(res);
|
|
|
}
|
|
|
|
|
|
+ @PostMapping("/listPro")
|
|
|
+ public Object listPro(@Valid @RequestBody PostBasePageHandle postBasePageHandle, BindingResult bindingResult){
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
|
|
|
+ }
|
|
|
+ ResHandle<List<FosterwxMobileWxfriend>> res = fosterwxMobileWxfriendService.getListPro(postBasePageHandle);
|
|
|
+ return AjaxResult.success(res);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 新增好友,会加入seq
|
|
|
* @param addFosterwxMobileHandle
|
|
|
@@ -120,5 +143,60 @@ public class FosterwxMobileWxfriendController extends BaseController<FosterwxMob
|
|
|
fosterwxMobileWxfriendService.removeAndAdd(addFosterwxMobileHandle);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/import")
|
|
|
+ public Object uploadFile(@RequestBody MultipartFile file, @AuthUser User authUser) {
|
|
|
+ Map<String, Object> map = new HashMap<>(16);
|
|
|
+ Map<Integer, String> feild = new HashMap<>(5);
|
|
|
+ feild.put(0, "stationName");
|
|
|
+ feild.put(1, "mobileCode");
|
|
|
+ feild.put(2, "friendId");
|
|
|
+ List<Map<String, String>> row = new ArrayList<>();
|
|
|
+ VoltaHandle<ArrayList<Map<String, String>>> voltaRes = Analysis.analysis(file, feild);
|
|
|
+ if (voltaRes.getErr() != null) {
|
|
|
+ return AjaxResult.error(voltaRes.getErr());
|
|
|
+ }
|
|
|
+ row = voltaRes.getData();
|
|
|
+ try {
|
|
|
+ VoltaHandle<Boolean> res = fosterwxMobileWxfriendService.importData(row, authUser);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return AjaxResult.error(e.getMessage());
|
|
|
+ }
|
|
|
+ return AjaxResult.success(HttpMsg.importSuccess);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/export")
|
|
|
+ public Object export(@Valid @RequestBody PostBasePageHandle postBasePageHandle, BindingResult bindingResult){
|
|
|
+ if (bindingResult.hasErrors()) {
|
|
|
+ return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
|
|
|
+ }
|
|
|
+ ResHandle<List<FosterwxMobileWxfriend>> res = fosterwxMobileWxfriendService.export(postBasePageHandle);
|
|
|
+ List<Object> tempObj;
|
|
|
+ List<List<Object>> resList = new ArrayList<List<Object>>();
|
|
|
+ Object[] head = {"站点编号","账号编号","好友ID"};
|
|
|
+ List<Object> headList = Arrays.asList(head);
|
|
|
+ Date currentTime = new Date();
|
|
|
+ String fileName = "账号绑定好友数据.csv";
|
|
|
+ resList.add(headList);
|
|
|
+ for (FosterwxMobileWxfriend fosterwxMobileWxfriend : res.getList()){
|
|
|
+ tempObj = new ArrayList<Object>() {
|
|
|
+ {
|
|
|
+ this.add(fosterwxMobileWxfriend.getStationName());
|
|
|
+ this.add(fosterwxMobileWxfriend.getMobileCode());
|
|
|
+ this.add(fosterwxMobileWxfriend.getFriendId());
|
|
|
+ }
|
|
|
+ };
|
|
|
+ resList.add(tempObj);
|
|
|
+ }
|
|
|
+ StringBuffer content = OssFile.createCSV(resList);
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String dateString = formatter.format(currentTime);
|
|
|
+ String randNum = Integer.toString((int)(10000+Math.random()*(99999-10000+1)));
|
|
|
+ String filePath = OSSConfiguration.PAN_DIR + dateString + "/" + randNum + "_" + fileName;
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(ossConfiguration.getBucketName(), filePath,
|
|
|
+ new ByteArrayInputStream(content.toString().getBytes()));
|
|
|
+ ossClient.putObject(putObjectRequest);
|
|
|
+ return AjaxResult.success(ossConfiguration.getHost() + filePath);
|
|
|
+ }
|
|
|
}
|
|
|
|