|
|
@@ -1,23 +1,33 @@
|
|
|
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.constant.HttpMsg;
|
|
|
+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.mapper.pangu.pojo.FosterwxMobile;
|
|
|
import com.mokamrp.privates.mapper.pangu.pojo.FosterwxMobileWxfriend;
|
|
|
import com.mokamrp.privates.mapper.pangu.FosterwxMobileWxfriendMapper;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxStation;
|
|
|
+import com.mokamrp.privates.mapper.pangu.pojo.FosterwxWxfriend;
|
|
|
+import com.mokamrp.privates.mapper.pojo.Corp;
|
|
|
+import com.mokamrp.privates.mapper.pojo.User;
|
|
|
import com.mokamrp.privates.service.pangu.FosterwxMobileService;
|
|
|
import com.mokamrp.privates.service.pangu.FosterwxMobileWxfriendService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.mokamrp.privates.service.pangu.FosterwxStationService;
|
|
|
+import com.mokamrp.privates.service.pangu.FosterwxWxfriendService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.mokamrp.privates.entity.PostBasePageHandle;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -37,20 +47,71 @@ public class FosterwxMobileWxfriendServiceImpl extends ServiceImpl<FosterwxMobil
|
|
|
|
|
|
@Autowired
|
|
|
public FosterwxMobileService fosterwxMobileService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public FosterwxStationService fosterwxStationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public FosterwxWxfriendService fosterwxWxfriendService;
|
|
|
/**
|
|
|
* 获取数据列表 支持分页
|
|
|
* @param handle
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map<String, Object> getList(PostBasePageHandle handle) {
|
|
|
+ public ResHandle<List<FosterwxMobileWxfriend>> getList(PostBasePageHandle handle) {
|
|
|
Integer pagesize = handle.getPagesize();
|
|
|
Integer page = handle.getPage();
|
|
|
Page<FosterwxMobileWxfriend> pageObj = new Page<FosterwxMobileWxfriend>(page, pagesize);
|
|
|
- List<FosterwxMobileWxfriend> list = fosterwxMobileWxfriendMapper.getList(pageObj);
|
|
|
- Map<String, Object> resMap = new HashMap<String, Object>();
|
|
|
- resMap.put("list", list);
|
|
|
- resMap.put("total", pageObj.getTotal());
|
|
|
- return resMap;
|
|
|
+ List<FosterwxMobileWxfriend> list = fosterwxMobileWxfriendMapper.getList(pageObj,handle);
|
|
|
+ ResHandle<List<FosterwxMobileWxfriend>> res = new ResHandle<>();
|
|
|
+ res.setList(list);
|
|
|
+ res.setTotal(pageObj.getTotal());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取数据列表 支持分页 加强版
|
|
|
+ * @param handle
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResHandle<List<FosterwxMobileWxfriend>> getListPro(PostBasePageHandle handle) {
|
|
|
+ Integer pagesize = handle.getPagesize();
|
|
|
+ Integer page = handle.getPage();
|
|
|
+ Page<FosterwxMobileWxfriend> pageObj = new Page<FosterwxMobileWxfriend>(page, pagesize);
|
|
|
+ List<FosterwxMobileWxfriend> list = fosterwxMobileWxfriendMapper.getListPro(pageObj,handle);
|
|
|
+ ResHandle<List<FosterwxMobileWxfriend>> res = new ResHandle<>();
|
|
|
+ res.setList(list);
|
|
|
+ res.setTotal(pageObj.getTotal());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResHandle<List<FosterwxMobileWxfriend>> export(PostBasePageHandle handle) {
|
|
|
+ Integer pagesize = handle.getPagesize();
|
|
|
+ Integer page = handle.getPage();
|
|
|
+ Page<FosterwxMobileWxfriend> pageObj = new Page<FosterwxMobileWxfriend>(page, pagesize);
|
|
|
+ List<FosterwxMobileWxfriend> list = fosterwxMobileWxfriendMapper.export(pageObj,handle);
|
|
|
+ ResHandle<List<FosterwxMobileWxfriend>> res = new ResHandle<>();
|
|
|
+ res.setList(list);
|
|
|
+ res.setTotal(pageObj.getTotal());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取可被替换的解封好友
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<FosterwxWxfriend> getCanSwtichFriendList() {
|
|
|
+ List<FosterwxWxfriend> list = fosterwxMobileWxfriendMapper.getCanSwtichFriendList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取可被绑定的解封好友
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<FosterwxWxfriend> getCanBindFriendList() {
|
|
|
+ List<FosterwxWxfriend> list = fosterwxMobileWxfriendMapper.getCanBindFriendList();
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -62,8 +123,10 @@ public class FosterwxMobileWxfriendServiceImpl extends ServiceImpl<FosterwxMobil
|
|
|
Integer i = 1;
|
|
|
this.remove(new QueryWrapper<FosterwxMobileWxfriend>().eq("mobile_id",addFosterwxMobileHandle.getMobileId()));
|
|
|
List<FosterwxMobileWxfriend> add = new ArrayList<>();
|
|
|
- for (FosterwxMobileWxfriend fosterwxMobileWxfriend : addFosterwxMobileHandle.getFriends()){
|
|
|
+ for (Integer friendId : addFosterwxMobileHandle.getFriendIds()){
|
|
|
+ FosterwxMobileWxfriend fosterwxMobileWxfriend = new FosterwxMobileWxfriend();
|
|
|
fosterwxMobileWxfriend.setSeq(i);
|
|
|
+ fosterwxMobileWxfriend.setFriendId(friendId);
|
|
|
fosterwxMobileWxfriend.setMobileId(addFosterwxMobileHandle.getMobileId());
|
|
|
fosterwxMobileWxfriend.setCreateAt(LocalDateTime.now());
|
|
|
fosterwxMobileWxfriend.setUpdateAt(LocalDateTime.now());
|
|
|
@@ -88,26 +151,28 @@ public class FosterwxMobileWxfriendServiceImpl extends ServiceImpl<FosterwxMobil
|
|
|
List<FosterwxMobileWxfriend> friends = this.list(new QueryWrapper<FosterwxMobileWxfriend>()
|
|
|
.in("mobile_id",mobileIds)
|
|
|
);
|
|
|
- Map<String,Boolean> friendsNames = new HashMap<>();
|
|
|
- for (FosterwxMobileWxfriend add :addFosterwxMobileHandle.getFriends()){
|
|
|
- if(friendsNames.get(add.getWxName()) != null){
|
|
|
- res.setErr(HttpMsg.wxFriendResume+add.getWxName());
|
|
|
+
|
|
|
+ Map<Integer,Boolean> friendsNames = new HashMap<>();
|
|
|
+ for (Integer friendId :addFosterwxMobileHandle.getFriendIds()){
|
|
|
+ if(friendsNames.get(friendId) != null){
|
|
|
+ res.setErr(HttpMsg.wxFriendResume+friendId.toString());
|
|
|
return res;
|
|
|
}
|
|
|
- friendsNames.put(add.getWxName(),true);
|
|
|
- Boolean findRes = this.checkWxFriendCnt(friends,add.getWxName());
|
|
|
+ friendsNames.put(friendId,true);
|
|
|
+ Boolean findRes = this.checkWxFriendCnt(friends,friendId);
|
|
|
if (!findRes){
|
|
|
- res.setErr(HttpMsg.wxFriendCntMax3+add.getWxName());
|
|
|
+ res.setErr(HttpMsg.wxFriendCntMax3+friendId.toString());
|
|
|
+
|
|
|
return res;
|
|
|
}
|
|
|
}
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- public Boolean checkWxFriendCnt(List<FosterwxMobileWxfriend> row,String wxName){
|
|
|
+ public Boolean checkWxFriendCnt(List<FosterwxMobileWxfriend> row,Integer friendId){
|
|
|
Integer findCnt = 0;
|
|
|
for (FosterwxMobileWxfriend fosterwxMobileWxfriend : row){
|
|
|
- if (fosterwxMobileWxfriend.getWxName().equals(wxName)){
|
|
|
+ if (fosterwxMobileWxfriend.getFriendId().equals(friendId)){
|
|
|
findCnt++;
|
|
|
}
|
|
|
if (findCnt >= 3){
|
|
|
@@ -116,4 +181,84 @@ public class FosterwxMobileWxfriendServiceImpl extends ServiceImpl<FosterwxMobil
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+ @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++) {
|
|
|
+ FosterwxStation stationInfo = fosterwxStationService.getOne(new QueryWrapper<FosterwxStation>()
|
|
|
+ .eq("station_name", row.get(i).get("stationName")));
|
|
|
+ if (stationInfo == null) {
|
|
|
+ throw new Exception("站点编号不存在");
|
|
|
+ }
|
|
|
+ String mobileCode = String.format("%03d", Integer.parseInt(row.get(i).get("mobileCode")));
|
|
|
+ FosterwxMobile mobileInfo = fosterwxMobileService.getOne(new QueryWrapper<FosterwxMobile>()
|
|
|
+ .eq("station_id", stationInfo.getId())
|
|
|
+ .eq("mobile_code", mobileCode)
|
|
|
+ );
|
|
|
+ if (mobileInfo == null) {
|
|
|
+ throw new Exception("第" + (i + 1) + "行,手机编号:" + mobileCode + ",不存在");
|
|
|
+ }
|
|
|
+ FosterwxWxfriend friendInfo = fosterwxWxfriendService.getOne(new QueryWrapper<FosterwxWxfriend>()
|
|
|
+ .eq("station_id",stationInfo.getId())
|
|
|
+ .eq("id",row.get(i).get("friendId"))
|
|
|
+ );
|
|
|
+ if (friendInfo == null){
|
|
|
+ throw new Exception("第" + (i + 1) + "行,好友编号:"+row.get(i).get("friendId") + "不是"+stationInfo.getStationName()+"站点下的微信好友,请检查后录入");
|
|
|
+ }
|
|
|
+ //.判断是否同账号下重复绑定好友
|
|
|
+ Integer hasRecord = this.count(new QueryWrapper<FosterwxMobileWxfriend>()
|
|
|
+ .eq("mobile_id",mobileInfo.getId())
|
|
|
+ .eq("friend_id",row.get(i).get("friendId")));
|
|
|
+ if(hasRecord > 0){
|
|
|
+ throw new Exception("第" + (i + 1) + "行,好友编号:"+row.get(i).get("friendId") + "已经和账号绑定不可重复绑定");
|
|
|
+ }
|
|
|
+ //.判断账号下是否已经绑满3个好友
|
|
|
+ VoltaHandle<String> checkBindRes = this.checkOneFriendInMobile(mobileInfo.getId());
|
|
|
+ if (checkBindRes.getErr() != null){
|
|
|
+ throw new Exception("第" + (i + 1) + "行,站点编号:"+row.get(i).get("mobileCode") + "已经绑定3个好友,无法再次绑定了");
|
|
|
+ }
|
|
|
+ //.判断好友ID是否在站点下已经被绑定了3次
|
|
|
+ VoltaHandle<String> checkRes = this.checkOneFriend(stationInfo.getId(),Integer.parseInt(row.get(i).get("friendId")));
|
|
|
+ if (checkRes.getErr() != null){
|
|
|
+ throw new Exception("第" + (i + 1) + "行,好友编号:"+row.get(i).get("friendId") + "已经绑定3次,无法再次绑定了");
|
|
|
+ }
|
|
|
+ FosterwxMobileWxfriend add = new FosterwxMobileWxfriend();
|
|
|
+ add.setMobileId(mobileInfo.getId());
|
|
|
+ add.setFriendId(Integer.parseInt(row.get(i).get("friendId")));
|
|
|
+ add.setCreateAt(LocalDateTime.now());
|
|
|
+ add.setUpdateAt(LocalDateTime.now());
|
|
|
+ this.save(add);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public VoltaHandle<String> checkOneFriendInMobile(Integer mobileId){
|
|
|
+ VoltaHandle<String> res = new VoltaHandle<>();
|
|
|
+ Integer mobileBindCnt = this.count(new QueryWrapper<FosterwxMobileWxfriend>().eq("mobile_id",mobileId));
|
|
|
+ if (mobileBindCnt >= 3){
|
|
|
+ res.setErr("账号id:"+mobileId + "已经绑定了3个好友");
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ //.判断某个好友是否已经在站点下呗绑定了3次
|
|
|
+ public VoltaHandle<String> checkOneFriend(Integer stationId,Integer friendId){
|
|
|
+ VoltaHandle<String> res = new VoltaHandle<>();
|
|
|
+ List<FosterwxMobile> mobileList = fosterwxMobileService.list(new QueryWrapper<FosterwxMobile>()
|
|
|
+ .eq("station_id", stationId)
|
|
|
+ );
|
|
|
+ List<Integer> mobileIds = mobileList.stream().map(FosterwxMobile::getId).collect(Collectors.toList());
|
|
|
+ List<FosterwxMobileWxfriend> friends = this.list(new QueryWrapper<FosterwxMobileWxfriend>()
|
|
|
+ .in("mobile_id",mobileIds)
|
|
|
+ .eq("friend_id",friendId)
|
|
|
+ );
|
|
|
+ if (friends.size() >= 3){
|
|
|
+ res.setErr("好友id:"+friendId + "已经被绑定3个无法再绑定");
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|