Commit 7c3f9d19 by fudahua

同步优化初步

parent e8a24073
package com.gic.haoban.manage.api.dto;
import java.io.Serializable;
/**
* Created 2020/4/10.
*
* @author hua
*/
public class DealParamMqDTO implements Serializable {
private String taskId;
private String data;
private Integer type;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public Integer getType() {
return type;
}
public void setType(Integer type) {
this.type = type;
}
}
package com.gic.haoban.manage.api.dto;
/**
* Created 2020/4/9.
*
* @author hua
*/
public class SyncSingleDealDTO {
private String departmentId;
private String departmentName;
private String parentDepartmentId;
private String relatedId;
private Integer storeFlag;
private String enterpriseId;
public String getEnterpriseId() {
return enterpriseId;
}
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
public String getDepartmentId() {
return departmentId;
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getParentDepartmentId() {
return parentDepartmentId;
}
public void setParentDepartmentId(String parentDepartmentId) {
this.parentDepartmentId = parentDepartmentId;
}
public String getRelatedId() {
return relatedId;
}
public void setRelatedId(String relatedId) {
this.relatedId = relatedId;
}
public Integer getStoreFlag() {
return storeFlag;
}
public void setStoreFlag(Integer storeFlag) {
this.storeFlag = storeFlag;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by hua on 2020/4/10.
*/
public enum PreDealStatusEnum {
all(-1),
pre(0),
dealing(1),
computed(2),
exception(3);
private int val;
PreDealStatusEnum(int val) {
this.val = val;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by hua on 2020/4/10.
*/
public enum PreDealTypeEnum {
all(-1),
group(0),
store(1),
clerk(2);
private int val;
PreDealTypeEnum(int val) {
this.val = val;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
package com.gic.haoban.manage.api.enums;
/**
* Created by hua on 2020/4/10.
*/
public enum SyncTaskStatusEnum {
init(0),
group_sync(1),
store_sync(2),
clerk_sync(3),
compute(4);
private int val;
SyncTaskStatusEnum(int val) {
this.val = val;
}
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
package com.gic.haoban.manage.api.service;
import com.gic.haoban.manage.api.dto.SyncSingleDealDTO;
import java.util.List;
/**
* Created 2020/4/9.
*
* @author hua
*/
public interface DealSyncOperationApiService {
/**
* 其它处理通过任务
*
* @param params
*/
public void run(String params);
/**
* 部门同步处理
*
* @param params
*/
public void departmentDealMq(String params);
/**
* 处理前端数据
*
* @param addList
* @param editList
*/
public void dealDepartment(String taskId, String wxEnterpriseId, List<SyncSingleDealDTO> addList, List<SyncSingleDealDTO> editList);
// public void createTask()
}
package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import java.util.List;
/**
* Created 2020/4/9.
*
* @author hua
*/
public interface PreDealService {
/**
* 批量新增
*
* @param list
* @return
*/
public boolean insert(List<TabHaobanPreDealLog> list);
/**
* 获取单条数据
*
* @param dataId
* @return
*/
public TabHaobanPreDealLog getByDataId(String taskId, String dataId, int status);
/**
* 根据父数据id 获取子节点
*
* @param pDataId
* @param status
* @return
*/
public List<TabHaobanPreDealLog> listByPDataId(String taskId, String pDataId, int status);
/**
* 更新单条数据状态
*
* @param dataId
* @param status
* @return
*/
public boolean updateStatusByDataId(String taskId, String dataId, int status);
/**
* 获取任务是否有在同步中
*
* @param dataType
* @return
*/
public boolean checkTask(String taskId, int dataType);
/**
* 获取任务列表
*
* @param type
* @param status
* @return
*/
public List<TabHaobanPreDealLog> listByTaskId(String taskId, int dataType, int status);
}
package com.gic.haoban.manage.service.service;
import com.gic.haoban.manage.service.entity.TabHaobanSyncTask;
/**
* Created 2020/4/10.
*
* @author hua
*/
public interface SyncTaskService {
/**
* 创建任务
*
* @param tabHaobanSyncTask
*/
public void createTask(TabHaobanSyncTask tabHaobanSyncTask);
/**
* 更新任务状态
*
* @param taskId
* @param status
*/
public boolean updateTaskStatus(String taskId, int status);
/**
* 获取任务
*
* @param taskId
* @return
*/
public TabHaobanSyncTask getSyncTask(String taskId);
}
package com.gic.haoban.manage.service.service.impl;
import com.gic.haoban.manage.api.enums.PreDealStatusEnum;
import com.gic.haoban.manage.service.dao.mapper.PreDealLogMapper;
import com.gic.haoban.manage.service.entity.TabHaobanPreDealLog;
import com.gic.haoban.manage.service.service.PreDealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created 2020/4/9.
*
* @author hua
*/
@Service
public class PreDealServiceImpl implements PreDealService {
@Autowired
private PreDealLogMapper preDealLogMapper;
@Override
public boolean insert(List<TabHaobanPreDealLog> list) {
for (TabHaobanPreDealLog tab : list) {
preDealLogMapper.insert(tab);
}
return true;
}
@Override
public TabHaobanPreDealLog getByDataId(String taskId, String dataId, int status) {
TabHaobanPreDealLog byDataId = preDealLogMapper.getByDataId(taskId, dataId, status);
return byDataId;
}
@Override
public List<TabHaobanPreDealLog> listByPDataId(String taskId, String pDataId, int status) {
return preDealLogMapper.listByPDataId(taskId, pDataId, status);
}
@Override
public boolean updateStatusByDataId(String taskId, String dataId, int status) {
int i = preDealLogMapper.updateStatusByDataId(taskId, dataId, status);
return i >= 0;
}
@Override
public boolean checkTask(String taskId, int dataType) {
int i = preDealLogMapper.checkTask(taskId, dataType, PreDealStatusEnum.pre.getVal());
return i == 0;
}
@Override
public List<TabHaobanPreDealLog> listByTaskId(String taskId, int dataType, int status) {
return preDealLogMapper.listByTaskId(taskId, dataType, status);
}
}
package com.gic.haoban.manage.service.service.impl;
import com.gic.commons.util.ToolUtil;
import com.gic.haoban.manage.api.enums.SyncTaskStatusEnum;
import com.gic.haoban.manage.service.dao.mapper.SyncTaskMapper;
import com.gic.haoban.manage.service.entity.TabHaobanSyncTask;
import com.gic.haoban.manage.service.service.SyncTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created 2020/4/10.
*
* @author hua
*/
@Service
public class SyncTaskServiceImpl implements SyncTaskService {
@Autowired
private SyncTaskMapper syncTaskMapper;
@Override
public void createTask(TabHaobanSyncTask tabHaobanSyncTask) {
tabHaobanSyncTask.setTaskId(ToolUtil.randomUUID());
tabHaobanSyncTask.setStatusFlag(SyncTaskStatusEnum.init.getVal());
syncTaskMapper.insert(tabHaobanSyncTask);
}
@Override
public boolean updateTaskStatus(String taskId, int status) {
return false;
}
@Override
public TabHaobanSyncTask getSyncTask(String taskId) {
return syncTaskMapper.selectByPrimaryKey(taskId);
}
}
package com.gic.haoban.manage.service.task;
/**
* Created 2020/4/13.
*
* @author hua
*/
public abstract class BaseSyncOperation {
}
package com.gic.haoban.manage.service.task;
/**
* Created 2020/4/13.
*
* @author hua
*/
public class GroupSyncOperation extends BaseSyncOperation {
}
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.dto.SyncSingleDealDTO;
import com.gic.haoban.manage.api.service.DealSyncOperationApiService;
import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.wechat.api.dto.qywx.DepartmentDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class DealSyncTest {
@Autowired
private DealSyncOperationApiService dealSyncOperationApiService;
@Test
public void test() {
List<SyncSingleDealDTO> add = new ArrayList<>();
List<SyncSingleDealDTO> edit = new ArrayList<>();
{
SyncSingleDealDTO dealDTO = new SyncSingleDealDTO();
dealDTO.setDepartmentId("ff80808166c3a1050166c43175d9000e");
dealDTO.setParentDepartmentId("a101b3a51cd549e79f3daec1aa628301");
dealDTO.setDepartmentName("西溪花园");
dealDTO.setRelatedId("ff80808166c3a1050166c43175d9000e");
dealDTO.setStoreFlag(0);
dealDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
add.add(dealDTO);
}
{
SyncSingleDealDTO dealDTO = new SyncSingleDealDTO();
dealDTO.setDepartmentId("100333808083");
dealDTO.setParentDepartmentId("a101b3a51cd549e79f3daec1aa628301");
dealDTO.setDepartmentName("测试门店1003338");
dealDTO.setRelatedId("100333808083");
dealDTO.setStoreFlag(1);
dealDTO.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
add.add(dealDTO);
}
dealSyncOperationApiService.dealDepartment("111", "ca66a01b79474c40b3e7c7f93daf1a3b", add, edit);
}
}
//import com.gic.haoban.manage.api.service.MemberUnionidRelatedApiService;
//import com.gic.wechat.api.service.qywx.QywxUserApiService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.gic.api.base.commons.JSONResponse;
import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.wechat.api.dto.qywx.DepartmentDTO;
import com.gic.wechat.api.dto.qywx.QywxXcxSendMessageDTO;
import com.gic.wechat.api.dto.qywx.UserDTO;
import com.gic.wechat.api.service.qywx.QywxDepartmentApiService;
import com.gic.wechat.api.service.qywx.QywxSuiteApiService;
import com.gic.wechat.api.service.qywx.QywxUserApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
//import com.gic.haoban.manage.api.service.WxEnterpriseRelatedApiService;
import com.gic.redis.data.util.RedisUtil;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class ServiceTest {
// @Autowired
// private WxEnterpriseRelatedApiService wxEnterpriseRelatedApiService;
@Autowired
private WxEnterpriseRelatedApiService wxEnterpriseRelatedApiService;
// @Autowired
// private QywxUserApiService qywxUserApiService;
@Autowired
private QywxUserApiService qywxUserApiService;
@Autowired
private QywxDepartmentApiService qywxDepartmentApiService;
@Autowired
private QywxSuiteApiService qywxSuiteApiService;
@Test
public void test() {
//wxEnterpriseRelatedApiService.listEnterpriseByWxEnterpriseId("073e89a37eb14acabf258e59a57359b6");
RedisUtil.delCache("haoban-sync-department-ca66a01b79474c40b3e7c7f93daf1a3b");
}
// @Test
// public void test1() {
// String corpSelfExternalUseridInfo = qywxUserApiService.getCorpSelfExternalUseridInfo("ww50d418adce14b4a9"
// , "1azg6LG5Vj_YKFO-X27to4S4x_y-f6APR0fwE9YnQd8", "wm-0J8CQAAbGIhtnLd51B97OO_0gf3zw");
// System.out.println(corpSelfExternalUseridInfo);
// }
@Test
public void test1() {
String res = qywxUserApiService.leaveClerkExternal("ww9ede832a84b7ae5f"
, "01YQ-pcdYzF3K0So8uCFfkB5i8D5EBW7KcVB4qA8Ktk", 0, 1000);
JSONArray jsonArray = JSONArray.parseArray(res);
jsonArray.forEach(o -> {
JSONObject mid = (JSONObject) o;
qywxUserApiService.leaveClerkReTransfer("ww9ede832a84b7ae5f"
, "01YQ-pcdYzF3K0So8uCFfkB5i8D5EBW7KcVB4qA8Ktk", mid.getString("handover_userid")
, mid.getString("handover_userid"), mid.getString("external_userid"));
});
System.out.println(res);
}
@Test
public void test2() {
UserDTO userDTO = new UserDTO();
userDTO.setUserid("niweizhong");
userDTO.setName("空闻大师");
userDTO.setDepartment(new Integer[]{4});
userDTO.setMobile("17605628855");
userDTO.setCorpid("ww9ede832a84b7ae5f");
JSONResponse workWxUser = qywxUserApiService.createWorkWxUser(userDTO, "ww9ede832a84b7ae5f", "ww7d6566614055cf27");
System.out.println(JSONObject.toJSONString(workWxUser));
}
@Test
public void list() {
List<DepartmentDTO> list = qywxDepartmentApiService.listSelfDepartment("ww9ede832a84b7ae5f"
, "3aOw7jbcHlHkDmOi5TuG42Ta8NqskOhZxy5urrmaGl8", 1);
Iterator<DepartmentDTO> iterator = list.iterator();
// while (iterator.hasNext()) {
// DepartmentDTO next = iterator.next();
// if(!next.getParentid().equals("1")) {
// iterator.remove();
// }
// }
System.out.println(JSONObject.toJSONString(list));
}
@Test
public void addDepart() {
DepartmentDTO dto = new DepartmentDTO();
// dto.set
// JSONResponse department = qywxDepartmentApiService.createDepartment("ww9ede832a84b7ae5f"
// , "ww7d6566614055cf27", null);
// List<DepartmentDTO> list = (List<DepartmentDTO>) department;
// System.out.println(JSONObject.toJSONString(list));
}
@Test
public void getUser() {
DepartmentDTO dto = new DepartmentDTO();
// dto.set
UserDTO phonenumber = qywxUserApiService.getWxUserByPhonenumber("ww9ede832a84b7ae5f"
, "ww7d6566614055cf27", "13735457631");
// String phonenumber = phonenumber;
// UserDTO phonenumber = (UserDTO) useridBymobile;
System.out.println(JSONObject.toJSONString(phonenumber));
}
@Test
public void createSelfUser() {
UserDTO userDTO = new UserDTO();
userDTO.setUserid("niweizhong2");
userDTO.setName("空闻大师2");
userDTO.setDepartment(new Integer[]{5072});
userDTO.setMobile("17605628851");
userDTO.setCorpid("ww9ede832a84b7ae5f");
JSONResponse workWxUser = qywxUserApiService.createSelfWorkWxUser(userDTO, "ww9ede832a84b7ae5f",
"3aOw7jbcHlHkDmOi5TuG42Ta8NqskOhZxy5urrmaGl8");
System.out.println(JSONObject.toJSONString(workWxUser));
}
@Test
public void sendMessage() {
QywxXcxSendMessageDTO messageDTO = new QywxXcxSendMessageDTO();
messageDTO.setAppid("wx6054e7be35015afc");
ArrayList<String> userIDs = new ArrayList<>();
userIDs.add("9ae4c4f1277340a186b16a17d937c72c");
messageDTO.setUserIds(userIDs);
messageDTO.setTitle("我的测试test");
messageDTO.setDescription("我的测试test11111");
boolean ret = qywxSuiteApiService.sendMessage("ww9ede832a84b7ae5f",
"ww2c34dc56739bb105", messageDTO);
System.out.println(JSONObject.toJSONString(ret));
}
}
package com.gic.haoban.manage.web.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.gic.api.base.commons.Page;
import com.gic.clerk.api.dto.ClerkDTO;
import com.gic.clerk.api.dto.ClerkListDTO;
import com.gic.clerk.api.service.ClerkService;
import com.gic.enterprise.api.dto.EnterpriseDTO;
import com.gic.enterprise.api.dto.GicTreeDTO;
import com.gic.enterprise.api.dto.StoreDTO;
import com.gic.enterprise.api.service.EnterpriseService;
import com.gic.enterprise.api.service.StoreGroupService;
import com.gic.enterprise.api.service.StoreService;
import com.gic.haoban.base.api.common.BasePageInfo;
import com.gic.haoban.base.api.common.Constant;
import com.gic.haoban.base.api.common.PageResult;
import com.gic.haoban.base.api.common.ServiceResponse;
import com.gic.haoban.common.utils.EntityUtil;
import com.gic.haoban.common.utils.HaobanResponse;
import com.gic.haoban.manage.api.dto.DepartmentDTO;
import com.gic.haoban.manage.api.dto.StaffDTO;
import com.gic.haoban.manage.api.dto.StaffDepartmentRelatedDTO;
import com.gic.haoban.manage.api.service.DepartmentApiService;
import com.gic.haoban.manage.api.service.StaffApiService;
import com.gic.haoban.manage.api.service.StaffDepartmentRelatedApiService;
import com.gic.haoban.manage.web.auth.AuthRequestUtil;
import com.gic.haoban.manage.web.errCode.HaoBanErrCode;
import com.gic.haoban.manage.web.qo.DepartmentAddQO;
import com.gic.haoban.manage.web.qo.DepartmentEditQO;
import com.gic.haoban.manage.web.qo.SyncDealQO;
import com.gic.haoban.manage.web.qo.SyncDepartmentQO;
import com.gic.haoban.manage.web.thread.SyncDepartmentThread;
import com.gic.haoban.manage.web.vo.DepartmentVO;
import com.gic.haoban.manage.web.vo.LoginVO;
import com.gic.redis.data.util.RedisUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
@RestController
public class SyncDealContoller extends WebBaseController {
private static Logger logger = LoggerFactory.getLogger(SyncDealContoller.class);
@Autowired
private DepartmentApiService departmentApiService;
@Autowired
private StoreGroupService storeGroupService;
@Autowired
private StoreService storeService;
@Autowired
private StaffApiService staffApiService;
@Autowired
private EnterpriseService enterpriseService;
@Autowired
private ClerkService clerkService;
@Autowired
private StaffDepartmentRelatedApiService staffDepartmentRelatedApiService;
@RequestMapping("department-sync")
@ResponseBody
public HaobanResponse departmentBatchSync(@RequestBody SyncDealQO qo) {
LoginVO login = (LoginVO) AuthRequestUtil.getSessionUser();
String wxEnterpriseId = login.getWxEnterpriseId();
String key = "haoban-sync-department-" + wxEnterpriseId;
if (RedisUtil.getCache(key) != null) {
return resultResponse(HaoBanErrCode.ERR_10011);
}
Object editDepartmentObject = null;
Object addDepartmentObject = null;
String editDepartment = "";
String addDepartment = "";
String delDepartmentIds = "";
logger.info("【部门同步】args={}", JSON.toJSONString(args));
if (args != null) {
editDepartmentObject = args.getEditDepartment();
addDepartmentObject = args.getAddDepartment();
editDepartment = JSON.toJSONString(editDepartmentObject);
addDepartment = JSON.toJSONString(addDepartmentObject);
}
RedisUtil.setCache(key, 1, 3600l);
new SyncDepartmentThread(this, editDepartment, delDepartmentIds, addDepartment, key).start();
return resultResponse(HaoBanErrCode.ERR_1, key);
}
@RequestMapping("department-batch-sync-success")
public HaobanResponse syncSuccess(String syncKey) {
if (RedisUtil.getCache(syncKey) == null) {
return resultResponse(HaoBanErrCode.ERR_1, true);
} else {
return resultResponse(HaoBanErrCode.ERR_1, false);
}
}
}
package com.gic.haoban.manage.web.qo;
import com.gic.haoban.manage.api.dto.SyncSingleDealDTO;
import java.io.Serializable;
import java.util.List;
public class SyncDealQO implements Serializable {
private List<SyncSingleDealDTO> editDepartment;
private List<SyncSingleDealDTO> addDepartment;
public List<SyncSingleDealDTO> getEditDepartment() {
return editDepartment;
}
public void setEditDepartment(List<SyncSingleDealDTO> editDepartment) {
this.editDepartment = editDepartment;
}
public List<SyncSingleDealDTO> getAddDepartment() {
return addDepartment;
}
public void setAddDepartment(List<SyncSingleDealDTO> addDepartment) {
this.addDepartment = addDepartment;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment