leon 4 년 전
부모
커밋
2fb6b7c07c

+ 38 - 4
src/main/java/com/mokamrp/privates/controller/pangu/FosterwxCashOasBoxController.java

@@ -2,13 +2,17 @@ package com.mokamrp.privates.controller.pangu;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.mokamrp.privates.constant.Constants;
+import com.mokamrp.privates.constant.HttpMsg;
 import com.mokamrp.privates.constant.HttpStatus;
 import com.mokamrp.privates.entity.*;
 import com.mokamrp.privates.entity.pangu.GetFosterwxCashOasBoxMobileGroupHandle;
 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.Custservice;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashMobileGroup;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBoxMobileGroup;
+import com.mokamrp.privates.mapper.pojo.User;
 import com.mokamrp.privates.service.pangu.FosterwxCashMobileGroupService;
 import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxMobileGroupService;
 import io.swagger.annotations.Api;
@@ -22,9 +26,12 @@ import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxService;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBox;
 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.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.List;
 
@@ -69,9 +76,9 @@ public class FosterwxCashOasBoxController extends BaseController<FosterwxCashOas
             return AjaxResult.error(HttpStatus.ERROR, bindingResult.getFieldError().getDefaultMessage());
         }
         this.onUpdate(editHandle);
-        if (editHandle.getRaw().getMobileGroupIds() != null || editHandle.getRaw().getMobileGroupIds().size() > 0){
-            fosterwxCashOasBoxMobileGroupService.remove(new QueryWrapper<FosterwxCashOasBoxMobileGroup>().eq("oas_box_id",editHandle.getIds()));
-            for (Integer groupId: editHandle.getRaw().getMobileGroupIds()){
+        if (editHandle.getRaw().getMobileGroupIds() != null || editHandle.getRaw().getMobileGroupIds().size() > 0) {
+            fosterwxCashOasBoxMobileGroupService.remove(new QueryWrapper<FosterwxCashOasBoxMobileGroup>().eq("oas_box_id", editHandle.getIds()));
+            for (Integer groupId : editHandle.getRaw().getMobileGroupIds()) {
                 FosterwxCashOasBoxMobileGroup add = new FosterwxCashOasBoxMobileGroup();
                 add.setOasBoxId(Integer.parseInt(editHandle.getIds()));
                 add.setCashMobileGroupId(groupId);
@@ -135,7 +142,7 @@ public class FosterwxCashOasBoxController extends BaseController<FosterwxCashOas
         handle.setOasBoxId(res.getId());
         handle.setPage(1);
         handle.setPagesize(999999);
-        ResHandle<List<FosterwxCashOasBoxMobileGroup>> list =  fosterwxCashOasBoxMobileGroupService.getList(handle);
+        ResHandle<List<FosterwxCashOasBoxMobileGroup>> list = fosterwxCashOasBoxMobileGroupService.getList(handle);
         res.setMobileGroups(list.getList());
         return AjaxResult.success(Constants.SUCCESS, res);
     }
@@ -155,6 +162,33 @@ public class FosterwxCashOasBoxController extends BaseController<FosterwxCashOas
         return AjaxResult.success(Constants.SUCCESS, true);
     }
 
+    @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, "groupId");
+        feild.put(2, "mobileGroupId");
+        feild.put(3, "type");
+        feild.put(4, "boxType");
+        feild.put(5, "boxLocation");
+        feild.put(6, "ghId");
+        feild.put(7, "name");
+        feild.put(8, "scope");
+        feild.put(9, "remark");
+        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 = fosterwxCashOasBoxService.importData(row, authUser);
+        } catch (Exception e) {
+            return AjaxResult.error(e.getMessage());
+        }
+        return AjaxResult.success(HttpMsg.importSuccess);
+    }
 
 }
 

+ 1 - 1
src/main/java/com/mokamrp/privates/entity/PostBasePageHandle.java

@@ -11,7 +11,7 @@ public class PostBasePageHandle {
     private Integer stationId;
     private Integer mobileId;
     private Integer createUid;
-    private Integer title;
+    private String title;
     private String name;
     public Integer getPage() {
         return page;

+ 5 - 0
src/main/java/com/mokamrp/privates/service/pangu/FosterwxCashOasBoxService.java

@@ -1,9 +1,12 @@
 package com.mokamrp.privates.service.pangu;
 
+import com.mokamrp.privates.entity.VoltaHandle;
 import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBox;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.mokamrp.privates.entity.PostBasePageHandle;
 import com.mokamrp.privates.entity.ResHandle;
+import com.mokamrp.privates.mapper.pojo.User;
+
 import java.util.List;
 import java.util.Map;
 /**
@@ -23,4 +26,6 @@ public interface FosterwxCashOasBoxService extends IService<FosterwxCashOasBox>
     public FosterwxCashOasBox getRandBox(Integer groupId);
     //.@leon 获取一个正常状态的公众号
     public FosterwxCashOasBox getRandOas(Integer groupId);
+
+    public VoltaHandle<Boolean> importData(List<Map<String, String>> row, User authUser) throws Exception;
 }

+ 74 - 4
src/main/java/com/mokamrp/privates/service/pangu/impl/FosterwxCashOasBoxServiceImpl.java

@@ -1,13 +1,16 @@
 package com.mokamrp.privates.service.pangu.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBox;
+import com.mokamrp.privates.entity.VoltaHandle;
+import com.mokamrp.privates.mapper.pangu.pojo.*;
 import com.mokamrp.privates.mapper.pangu.FosterwxCashOasBoxMapper;
-import com.mokamrp.privates.mapper.pangu.pojo.FosterwxCashOasBoxMobileGroup;
-import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxMobileGroupService;
-import com.mokamrp.privates.service.pangu.FosterwxCashOasBoxService;
+import com.mokamrp.privates.mapper.pojo.Corp;
+import com.mokamrp.privates.mapper.pojo.User;
+import com.mokamrp.privates.service.pangu.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.mokamrp.privates.utils.StringUtils;
+import org.apache.tomcat.jni.Local;
 import org.springframework.stereotype.Service;
 import com.mokamrp.privates.entity.PostBasePageHandle;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,6 +20,8 @@ import com.mokamrp.privates.entity.ResHandle;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -35,8 +40,17 @@ public class FosterwxCashOasBoxServiceImpl extends ServiceImpl<FosterwxCashOasBo
     public FosterwxCashOasBoxMapper fosterwxCashOasBoxMapper;
 
     @Autowired
+    public FosterwxCashMobileService fosterwxCashMobileService;
+
+    @Autowired
+    public FosterwxCashMobileGroupService fosterwxCashMobileGroupService;
+
+    @Autowired
     public FosterwxCashOasBoxMobileGroupService fosterwxCashOasBoxMobileGroupService;
 
+    @Autowired
+    public FosterwxStationService fosterwxStationService;
+
     /**
      * 获取数据列表 支持分页
      *
@@ -119,4 +133,60 @@ public class FosterwxCashOasBoxServiceImpl extends ServiceImpl<FosterwxCashOasBo
         int i = random.nextInt(max) % (max - min + 1) + min;
         return list.get(i);
     }
+
+    /**
+     * 导入数据
+     *
+     * @param row
+     * @return
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public VoltaHandle<Boolean> importData(List<Map<String, String>> row, User authUser) throws Exception {
+        VoltaHandle<Boolean> res = new VoltaHandle<>();
+        if (row.size() <= 0) {
+            throw new Exception("表格读取完成后,没有获取到任何数据");
+        }
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        for (int i = 0; i < row.size(); i++) {
+            LocalDateTime nowDate = LocalDateTime.now();
+            Map<String, String> cell = row.get(i);
+            FosterwxCashOasBox fosterwxCashOasBox = new FosterwxCashOasBox();
+            FosterwxStation stationInfo = fosterwxStationService.getOne(new QueryWrapper<FosterwxStation>()
+                    .eq("station_name", row.get(i).get("stationName")));
+            if (stationInfo == null) {
+                throw new Exception("站点编号不存在");
+            }
+            FosterwxCashMobileGroup fosterwxCashMobileGroup = fosterwxCashMobileGroupService.getOne(new QueryWrapper<FosterwxCashMobileGroup>().eq("id",Integer.parseInt(row.get(i).get("mobileGroupId"))));
+            if (fosterwxCashMobileGroup == null){
+                throw new Exception("第"+i+"行:账号分组ID不存在");
+            }
+            fosterwxCashOasBox.setStationId(stationInfo.getId());
+            fosterwxCashOasBox.setGroupId(Integer.parseInt(row.get(i).get("groupId")));
+            fosterwxCashOasBox.setType(Integer.parseInt(row.get(i).get("type")));
+            fosterwxCashOasBox.setBoxType(Integer.parseInt(row.get(i).get("boxType")));
+            fosterwxCashOasBox.setBoxLocation(Integer.parseInt(row.get(i).get("boxLocation")));
+            fosterwxCashOasBox.setGhId(row.get(i).get("ghId"));
+            fosterwxCashOasBox.setName(row.get(i).get("name"));
+            fosterwxCashOasBox.setScope(row.get(i).get("scope"));
+            fosterwxCashOasBox.setRemark(row.get(i).get("remark"));
+            fosterwxCashOasBox.setCreateAt(LocalDateTime.now());
+            fosterwxCashOasBox.setUploadUid(authUser.getId());
+            fosterwxCashOasBox.setUpdateAt(LocalDateTime.now());
+            this.save(fosterwxCashOasBox);
+
+            FosterwxCashOasBoxMobileGroup fosterwxCashOasBoxMobileGroup = fosterwxCashOasBoxMobileGroupService.getOne(new QueryWrapper<FosterwxCashOasBoxMobileGroup>()
+                    .eq("oas_box_id",fosterwxCashOasBox.getId())
+            .eq("cash_mobile_group_id",Integer.parseInt(row.get(i).get("mobileGroupId"))));
+            if (fosterwxCashOasBoxMobileGroup != null){
+                throw new Exception("第"+i+"行:账号分组ID与当前公众号ID绑定关系已经存在");
+            }
+            FosterwxCashOasBoxMobileGroup addBoxOasBindMobileGroup = new FosterwxCashOasBoxMobileGroup();
+            addBoxOasBindMobileGroup.setOasBoxId(fosterwxCashOasBox.getId());
+            addBoxOasBindMobileGroup.setCashMobileGroupId(Integer.parseInt(row.get(i).get("mobileGroupId")));
+            addBoxOasBindMobileGroup.setUpdateAt(LocalDateTime.now());
+            addBoxOasBindMobileGroup.setCreateAt(LocalDateTime.now());
+            fosterwxCashOasBoxMobileGroupService.save(addBoxOasBindMobileGroup);
+        }
+        return res;
+    }
 }

BIN
src/main/resources/static/盘古变现公众号小程序账号导入.xls