调整企业微信相关接口;调整微信支付返回与分账返回
This commit is contained in:
parent
8ec873a2b1
commit
2f4f481a24
@ -12,7 +12,7 @@ public enum OrderSource {
|
||||
/**
|
||||
* 商城
|
||||
*/
|
||||
MALL("Mall",0.06);
|
||||
MALL("Mall",0.002);
|
||||
|
||||
OrderSource(String name, Double rate) {
|
||||
this.rate = rate;
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>Cpop-Oam-Web</finalName>
|
||||
<finalName>Cpop-Mall-Web</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@ -10,9 +10,14 @@ import com.cpop.system.business.entity.Brand;
|
||||
import com.cpop.system.business.entity.ProfitSharing;
|
||||
import com.cpop.system.business.service.BrandService;
|
||||
import com.cpop.system.business.service.ProfitSharingService;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingFinishRequest;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingQueryRequest;
|
||||
import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingReceiverRequest;
|
||||
import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingResult;
|
||||
import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReturnRequest;
|
||||
import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingUnfreezeRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
@ -52,18 +57,18 @@ public class CpopWxPayTests {
|
||||
WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
|
||||
//退款金额(单位分)
|
||||
//int refund = order.getTotalAmount().scaleByPowerOfTen(2).intValue();
|
||||
int refund = 1;
|
||||
int refund = 100;
|
||||
amount.setRefund(refund)
|
||||
.setTotal(refund)
|
||||
.setCurrency("CNY");
|
||||
request.setSubMchid(wxPayService.getConfig().getSubMchId())
|
||||
.setTransactionId("4200002015202311095099886928")
|
||||
.setOutTradeNo("80137484138201088")
|
||||
.setTransactionId("4200002044202311178101861880")
|
||||
.setOutTradeNo("83081335475826688")
|
||||
//.setTransactionId(order.getOutOrderNo())
|
||||
//.setOutTradeNo(order.getId())
|
||||
.setNotifyUrl(wxPayProperties.getNotifyRefund())
|
||||
.setOutRefundNo(IdUtils.fastSimpleUUID())
|
||||
.setSubMchid(brand.getWxMchId())
|
||||
.setSubMchid("1659765332")
|
||||
.setReason("接口测试退款")
|
||||
.setAmount(amount);
|
||||
WxPayRefundV3Result result = wxPayService.refundV3(request);
|
||||
@ -82,10 +87,10 @@ public class CpopWxPayTests {
|
||||
//ProfitSharing profitSharing = SpringUtils.getBean(ProfitSharingService.class).getById("77860920238751744");
|
||||
//profitSharingReturnRequest.setOrderId(profitSharing.getOutProfitSharingId());
|
||||
//profitSharingReturnRequest.setOutReturnNo(profitSharing.getId());
|
||||
profitSharingReturnRequest.setOrderId("4200002037202311160917055414");
|
||||
profitSharingReturnRequest.setOutReturnNo("1725040884229472256");
|
||||
profitSharingReturnRequest.setOrderId("4200002013202311178836140400");
|
||||
profitSharingReturnRequest.setOutReturnNo("83058677266882560");
|
||||
profitSharingReturnRequest.setDescription("分账退款");
|
||||
profitSharingReturnRequest.setSubMchId("1650816616");
|
||||
profitSharingReturnRequest.setSubMchId("1659765332");
|
||||
profitSharingReturnRequest.setReturnMchid("1618884922");
|
||||
//profitSharingReturnRequest.setAmount(profitSharing.getAmount());
|
||||
profitSharingReturnRequest.setAmount(1L);
|
||||
@ -113,4 +118,45 @@ public class CpopWxPayTests {
|
||||
config.setSubMchId("1618925571");
|
||||
wxPayService.getProfitSharingService().addReceiver(profitSharingReceiver);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 获取订单信息
|
||||
* @author DB
|
||||
* @date 2023/11/17 17:14
|
||||
* @return: void
|
||||
*/
|
||||
@Test
|
||||
public void getOrderInfo() throws WxPayException {
|
||||
WxPayConfig config = wxPayService.getConfig();
|
||||
config.setSubMchId("1659795861");
|
||||
WxPayOrderQueryResult wxPayOrderQueryResult = wxPayService.queryOrder("4200002050202311175292231256", null);
|
||||
System.out.println(wxPayOrderQueryResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 查询分账结果
|
||||
* @author DB
|
||||
* @date 2023/11/17 17:56
|
||||
* @return: void
|
||||
*/
|
||||
@Test
|
||||
public void getRefundResult() throws WxPayException {
|
||||
ProfitSharingResult profitSharingResult = wxPayService.getProfitSharingV3Service().getProfitSharingResult("83081464408731648", "4200002044202311178101861880", "1659765332");
|
||||
System.out.println(profitSharingResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束分账
|
||||
* @throws WxPayException
|
||||
*/
|
||||
@Test
|
||||
public void profitSharingFinish() throws WxPayException {
|
||||
ProfitSharingFinishRequest profitSharingFinishRequest = new ProfitSharingFinishRequest();
|
||||
profitSharingFinishRequest.setTransactionId("4200002044202311178101861880");
|
||||
profitSharingFinishRequest.setOutOrderNo("83081335475826688");
|
||||
profitSharingFinishRequest.setDescription("结束分账");
|
||||
profitSharingFinishRequest.setSubMchId("1659765332");
|
||||
wxPayService.getProfitSharingService().profitSharingFinish(profitSharingFinishRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
String brandId = loginUserInfo.getString("brandId");
|
||||
Brand brand = SpringUtils.getBean(BrandService.class).getById(brandId);
|
||||
//需要分账
|
||||
if (order.getTotalAmount().scaleByPowerOfTen(2).intValue() >= 10) {
|
||||
if (order.getTotalAmount().scaleByPowerOfTen(2).intValue() >= 100) {
|
||||
//需要分账
|
||||
orderRequest.setProfitSharing("Y");
|
||||
}
|
||||
@ -517,6 +517,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
try {
|
||||
WxPayService wxPayService = wxPayHandler.getWxPayService();
|
||||
WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData);
|
||||
if(!StringUtils.equals(notifyResult.getResultCode(),"SUCCESS")){
|
||||
throw new ServiceException(notifyResult.getReturnMsg());
|
||||
}
|
||||
String orderId = notifyResult.getOutTradeNo();
|
||||
//修改订单状态
|
||||
this.updateChain().set(ORDER.OUT_ORDER_NO, notifyResult.getTransactionId())
|
||||
@ -528,10 +531,8 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
Map<String, Integer> orderNumMap = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber));
|
||||
//查询订单信息
|
||||
Order order = this.getById(orderId);
|
||||
//获取订单品牌信息
|
||||
Brand brand = SpringUtils.getBean(BrandService.class).getById(order.getBrandId());
|
||||
//需要分账
|
||||
if (notifyResult.getTotalFee() >= 10) {
|
||||
//需要分账(金额大于1元才分账)
|
||||
if (notifyResult.getTotalFee() >= 100) {
|
||||
wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService);
|
||||
}
|
||||
//异步更新
|
||||
|
||||
@ -2,6 +2,7 @@ package com.cpop.mall.business.task;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cpop.common.utils.StringUtils;
|
||||
import com.cpop.core.base.enums.OrderSource;
|
||||
import com.cpop.core.base.exception.ServiceException;
|
||||
import com.cpop.core.base.exception.UtilException;
|
||||
@ -118,12 +119,16 @@ public class WxPayAsyncTask {
|
||||
private void wxPayProfitSharing(ProfitSharingRequest profitSharingRequest, WxPayService wxPayService, Integer flag) {
|
||||
try {
|
||||
ProfitSharingResult profitSharingResult = wxPayService.getProfitSharingService().profitSharing(profitSharingRequest);
|
||||
if (StringUtils.equals(profitSharingResult.getResultCode(), "SUCCESS")) {
|
||||
//存入系统
|
||||
SpringUtils.getBean(ProfitSharingService.class).updateChain()
|
||||
.set(PROFIT_SHARING.OUT_PROFIT_SHARING_ID, profitSharingResult.getOrderId())
|
||||
.set(PROFIT_SHARING.PROFIT_SHARING_STATUS, 1)
|
||||
.where(PROFIT_SHARING.ID.eq(profitSharingResult.getOutOrderNo()))
|
||||
.update();
|
||||
} else {
|
||||
throw new ServiceException(profitSharingResult.getReturnMsg());
|
||||
}
|
||||
} catch (WxPayException e) {
|
||||
if (flag > 5) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
|
||||
@ -131,8 +131,15 @@ wx:
|
||||
#企业微信
|
||||
cp:
|
||||
corpId: ww9b83a363662f219f
|
||||
qConnectUrl: https://oam.jamboxsys.com/Cpop-Oam/wxCp/portal/1000024/authCode
|
||||
appConfigs:
|
||||
#通讯录
|
||||
- agentId: 1000000
|
||||
secret: YAvZS9i2Ccc3_arbH-qi3zTEDJfmEt_2L-k2LG_TTEw
|
||||
token: xKOLVqjOUklbQ
|
||||
aesKey: A71T8zPqzb5B2uPesyfRyuTEFpDjhinIRdHg65NuUFj
|
||||
# (某一具体应用的AgentId,如果是要配置通讯录同步的应用,可以随便配置一个)
|
||||
#自建应用
|
||||
- agentId: 1000024
|
||||
#(该应用的Secret)
|
||||
secret: VJFNBvZgK6oNEKpfrb5B9KQcm7yB0CacpWS2BfTln5Q
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.oam.business.service.DeptService;
|
||||
import com.cpop.oam.business.vo.DeptVo;
|
||||
@ -89,19 +89,6 @@ public class DeptController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return R<Void>
|
||||
* @Description: 同步企业微信部门
|
||||
* @Author DB
|
||||
* @Date: 2023/5/9 20:47
|
||||
*/
|
||||
@Deprecated
|
||||
@PreAuthorize("@aps.hasPermission('*:*:*')")
|
||||
@ApiOperation("同步企业微信部门")
|
||||
@PostMapping("/syncWxCpDept")
|
||||
public R<Void> syncWxCpDept() {
|
||||
deptService.syncWxCpDept();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.oam.business.bo.DutyBo;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.core.service.CoreService;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.system.business.service.RoleService;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
@ -192,18 +192,4 @@ public class StaffController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return R<Void>
|
||||
* @Description: 同步企业微信员工
|
||||
* @Author DB
|
||||
* @Date: 2023/5/9 20:47
|
||||
*/
|
||||
@Deprecated
|
||||
@PreAuthorize("@aps.hasPermission('*:*:*')")
|
||||
@ApiOperation("同步企业微信员工")
|
||||
@PostMapping("/syncWxCpStaff")
|
||||
public R<Void> syncWxCpStaff() {
|
||||
staffService.syncWxCpStaff();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.annontation.OperationLog;
|
||||
import com.cpop.core.base.R;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.cpop.core.annontation.OperationLog;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.oam.business.bo.TaskDemandBo;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.oam.business.bo.PauseWorkOrderBo;
|
||||
@ -0,0 +1,57 @@
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.cpop.core.base.R;
|
||||
import com.cpop.oam.business.service.OamWxCpService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/11/17 9:38
|
||||
* @description
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@Api(tags = "企业微信相关模块")
|
||||
@RequestMapping("/wxCp")
|
||||
public class WxCpController {
|
||||
|
||||
@Autowired
|
||||
private OamWxCpService oamWxCpService;
|
||||
|
||||
/**
|
||||
* @return R<Void>
|
||||
* @Description: 同步企业微信部门
|
||||
* @Author DB
|
||||
* @Date: 2023/5/9 20:47
|
||||
*/
|
||||
@Deprecated
|
||||
@PreAuthorize("@aps.hasPermission('*:*:*')")
|
||||
@ApiOperation("同步企业微信部门")
|
||||
@PostMapping("/syncWxCpDept")
|
||||
public R<Void> syncWxCpDept() {
|
||||
oamWxCpService.syncWxCpDept();
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return R<Void>
|
||||
* @Description: 同步企业微信员工
|
||||
* @Author DB
|
||||
* @Date: 2023/5/9 20:47
|
||||
*/
|
||||
@Deprecated
|
||||
@PreAuthorize("@aps.hasPermission('*:*:*')")
|
||||
@ApiOperation("同步企业微信员工")
|
||||
@PostMapping("/syncWxCpStaff")
|
||||
public R<Void> syncWxCpStaff() {
|
||||
oamWxCpService.syncWxCpStaff();
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaAuditMediaUploadResult;
|
||||
import com.cpop.common.utils.StringUtils;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.backstage;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cpop.common.utils.StringUtils;
|
||||
@ -1,9 +1,13 @@
|
||||
package com.cpop.oam.business.controller;
|
||||
package com.cpop.oam.business.controller.callback;
|
||||
|
||||
import com.cpop.common.utils.JsonUtils;
|
||||
import com.cpop.common.utils.StringUtils;
|
||||
import com.cpop.core.service.RedisService;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.oam.framework.config.wxCp.WxCpConfiguration;
|
||||
import com.cpop.oam.framework.constant.WxCpConstant;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlOutMessage;
|
||||
@ -75,4 +79,5 @@ public class WxCpPortalController {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -48,12 +48,4 @@ public interface DeptService extends IService<Dept> {
|
||||
*/
|
||||
void removeDept(String id);
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信部门
|
||||
* @author DB
|
||||
* @date 2023/11/15 16:56
|
||||
* @return: void
|
||||
*/
|
||||
void syncWxCpDept();
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package com.cpop.oam.business.service;
|
||||
|
||||
/**
|
||||
* Oam暴露的企业微信接口
|
||||
* @author DB
|
||||
*/
|
||||
public interface OamWxCpService {
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信部门
|
||||
* @author DB
|
||||
* @date 2023/11/15 16:56
|
||||
* @return: void
|
||||
*/
|
||||
void syncWxCpDept();
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信员工
|
||||
* @author DB
|
||||
* @date 2023/11/16 17:03
|
||||
* @return: void
|
||||
*/
|
||||
void syncWxCpStaff();
|
||||
}
|
||||
@ -120,11 +120,4 @@ public interface StaffService extends IService<Staff> {
|
||||
*/
|
||||
void createWxCpUser(WxCpXmlMessage wxMessage, WxCpService cpService);
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信员工
|
||||
* @author DB
|
||||
* @date 2023/11/16 17:03
|
||||
* @return: void
|
||||
*/
|
||||
void syncWxCpStaff();
|
||||
}
|
||||
|
||||
@ -212,63 +212,4 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信部门
|
||||
* @author DB
|
||||
* @date 2023/11/15 16:56
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void syncWxCpDept() {
|
||||
//企业微信互通应用
|
||||
WxCpService cpService = WxCpConfiguration.getCpService(1000024);
|
||||
try {
|
||||
//获取所有数据
|
||||
List<WxCpDepart> list = cpService.getDepartmentService().list(null);
|
||||
//过滤出最顶级部门
|
||||
WxCpDepart wxCpDepart = list.stream().filter(item -> item.getParentId() == 0).collect(Collectors.toList()).get(0);
|
||||
//先存
|
||||
Dept dept = new Dept();
|
||||
dept.setWxCpId(wxCpDepart.getId()).setWxCpParentId(wxCpDepart.getParentId()).setOrderNo(wxCpDepart.getOrder().intValue()).setName(wxCpDepart.getName());
|
||||
if (wxCpDepart.getDepartmentLeader().length > 0) {
|
||||
dept.setLeader(wxCpDepart.getDepartmentLeader()[0]);
|
||||
}
|
||||
this.save(dept);
|
||||
//递归保存余下部门
|
||||
List<WxCpDepart> filterWxDeptList = list.stream().filter(item -> item.getParentId() != 0).collect(Collectors.toList());
|
||||
recursionSonDept(filterWxDeptList, dept);
|
||||
} catch (WxErrorException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 递归保存子部门
|
||||
* @author DB
|
||||
* @date 2023/11/16 16:06
|
||||
* @param wxCpDepartList 部门id
|
||||
* @param parentDept 父部门
|
||||
* @return: void
|
||||
*/
|
||||
private void recursionSonDept(List<WxCpDepart> wxCpDepartList, Dept parentDept) {
|
||||
List<Dept> deptList = new ArrayList<Dept>();
|
||||
Iterator<WxCpDepart> iterator = wxCpDepartList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
WxCpDepart next = iterator.next();
|
||||
if (next.getParentId().equals(parentDept.getWxCpId())) {
|
||||
//先存
|
||||
Dept dept = new Dept();
|
||||
dept.setWxCpId(next.getId()).setWxCpParentId(next.getParentId()).setOrderNo(next.getOrder().intValue()).setParentId(parentDept.getId()).setName(next.getName());
|
||||
deptList.add(dept);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
//当子部门不为空的时候保存部门
|
||||
if (!deptList.isEmpty()) {
|
||||
this.saveBatch(deptList);
|
||||
deptList.forEach(item -> {
|
||||
recursionSonDept(wxCpDepartList, item);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,152 @@
|
||||
package com.cpop.oam.business.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.cpop.core.base.enums.UserType;
|
||||
import com.cpop.core.base.exception.ServiceException;
|
||||
import com.cpop.core.base.table.SysUser;
|
||||
import com.cpop.core.mapper.CoreMapper;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.core.utils.uuid.IdUtils;
|
||||
import com.cpop.oam.business.entity.Dept;
|
||||
import com.cpop.oam.business.entity.Staff;
|
||||
import com.cpop.oam.business.entity.StaffMidDept;
|
||||
import com.cpop.oam.business.service.DeptService;
|
||||
import com.cpop.oam.business.service.OamWxCpService;
|
||||
import com.cpop.oam.business.service.StaffMidDeptService;
|
||||
import com.cpop.oam.business.service.StaffService;
|
||||
import com.cpop.oam.framework.config.wxCp.WxCpConfiguration;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.cpop.oam.business.entity.table.DeptTableDef.DEPT;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
* @createTime 2023/11/17 9:42
|
||||
* @description Oam暴露的企业微信接口
|
||||
*/
|
||||
@Service("oamWxCpService")
|
||||
public class OamWxCpServiceImpl implements OamWxCpService {
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信部门
|
||||
* @author DB
|
||||
* @date 2023/11/15 16:56
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
public void syncWxCpDept() {
|
||||
//企业微信互通应用
|
||||
WxCpService cpService = WxCpConfiguration.getCpService(1000024);
|
||||
try {
|
||||
//获取所有数据
|
||||
List<WxCpDepart> list = cpService.getDepartmentService().list(null);
|
||||
//过滤出最顶级部门
|
||||
WxCpDepart wxCpDepart = list.stream().filter(item -> item.getParentId() == 0).collect(Collectors.toList()).get(0);
|
||||
//先存
|
||||
Dept dept = new Dept();
|
||||
dept.setWxCpId(wxCpDepart.getId()).setWxCpParentId(wxCpDepart.getParentId()).setOrderNo(wxCpDepart.getOrder().intValue()).setName(wxCpDepart.getName());
|
||||
if (wxCpDepart.getDepartmentLeader().length > 0) {
|
||||
dept.setLeader(wxCpDepart.getDepartmentLeader()[0]);
|
||||
}
|
||||
SpringUtils.getBean(DeptService.class).save(dept);
|
||||
//递归保存余下部门
|
||||
List<WxCpDepart> filterWxDeptList = list.stream().filter(item -> item.getParentId() != 0).collect(Collectors.toList());
|
||||
recursionSonDept(filterWxDeptList, dept);
|
||||
} catch (WxErrorException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 递归保存子部门
|
||||
* @author DB
|
||||
* @date 2023/11/16 16:06
|
||||
* @param wxCpDepartList 部门id
|
||||
* @param parentDept 父部门
|
||||
* @return: void
|
||||
*/
|
||||
private void recursionSonDept(List<WxCpDepart> wxCpDepartList, Dept parentDept) {
|
||||
List<Dept> deptList = new ArrayList<Dept>();
|
||||
Iterator<WxCpDepart> iterator = wxCpDepartList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
WxCpDepart next = iterator.next();
|
||||
if (next.getParentId().equals(parentDept.getWxCpId())) {
|
||||
//先存
|
||||
Dept dept = new Dept();
|
||||
dept.setWxCpId(next.getId()).setWxCpParentId(next.getParentId()).setOrderNo(next.getOrder().intValue()).setParentId(parentDept.getId()).setName(next.getName());
|
||||
deptList.add(dept);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
//当子部门不为空的时候保存部门
|
||||
if (!deptList.isEmpty()) {
|
||||
SpringUtils.getBean(DeptService.class).saveBatch(deptList);
|
||||
deptList.forEach(item -> {
|
||||
recursionSonDept(wxCpDepartList, item);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信员工
|
||||
* @author DB
|
||||
* @date 2023/11/16 17:04
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncWxCpStaff() {
|
||||
WxCpService cpService = WxCpConfiguration.getCpService(1000024);
|
||||
try {
|
||||
List<WxCpUser> wxCpUsers = cpService.getUserService().listByDepartment(1L, true, 0);
|
||||
if (!wxCpUsers.isEmpty()){
|
||||
//批量插入用户
|
||||
Map<SysUser,WxCpUser> userWxCpUserMap = new HashMap<>();
|
||||
wxCpUsers.forEach(item -> {
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setId(IdUtils.fastSimpleUUID())
|
||||
.setStatus(item.getStatus() == 1)
|
||||
.setUserType(UserType.OAM_USER.toString())
|
||||
.setCreateUserId("1");
|
||||
sysUser.setUpdateUserId("1");
|
||||
userWxCpUserMap.put(sysUser, item);
|
||||
});
|
||||
Db.executeBatch(userWxCpUserMap.keySet(), CoreMapper.class, CoreMapper::insertSysUser);
|
||||
List<Staff> staffList = new ArrayList<>();
|
||||
//批量创建用户
|
||||
userWxCpUserMap.forEach((key, value) -> {
|
||||
Staff staff = new Staff();
|
||||
staff.setName(value.getName()).setUserId(key.getId()).setWxCpUserId(value.getUserId());
|
||||
staffList.add(staff);
|
||||
});
|
||||
SpringUtils.getBean(StaffService.class).saveBatch(staffList);
|
||||
//获取所有部门信息
|
||||
List<Dept> deptList = SpringUtils.getBean(DeptService.class).queryChain().where(DEPT.WX_CP_ID.isNotNull()).list();
|
||||
//部门id映射
|
||||
Map<Long, String> deptMap = deptList.stream().collect(Collectors.toMap(Dept::getWxCpId, Dept::getId));
|
||||
Map<String, String> userIdToStaffIdMap = staffList.stream().collect(Collectors.toMap(Staff::getUserId, Staff::getId));
|
||||
List<StaffMidDept> staffMidDeptList = new ArrayList<>();
|
||||
//批量创建用户
|
||||
userWxCpUserMap.forEach((key, value) -> {
|
||||
for (Long wxDeptId : value.getDepartIds()) {
|
||||
StaffMidDept staffMidDept = new StaffMidDept();
|
||||
staffMidDept.setStaffId(userIdToStaffIdMap.get(key.getId())).setDeptId(deptMap.get(wxDeptId));
|
||||
staffMidDeptList.add(staffMidDept);
|
||||
}
|
||||
});
|
||||
SpringUtils.getBean(StaffMidDeptService.class).saveBatch(staffMidDeptList);
|
||||
}
|
||||
} catch (WxErrorException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -379,57 +379,4 @@ public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements
|
||||
//insertStaff(wxCpUserToStaff(wxMessage, cpService));
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 同步企业微信员工
|
||||
* @author DB
|
||||
* @date 2023/11/16 17:04
|
||||
* @return: void
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void syncWxCpStaff() {
|
||||
WxCpService cpService = WxCpConfiguration.getCpService(1000024);
|
||||
try {
|
||||
List<WxCpUser> wxCpUsers = cpService.getUserService().listByDepartment(1L, true, 0);
|
||||
if (!wxCpUsers.isEmpty()){
|
||||
log.info("部门用户信息:{}", JSONArray.toJSONString(wxCpUsers));
|
||||
//批量插入用户
|
||||
Map<SysUser,WxCpUser> userWxCpUserMap = new HashMap<>();
|
||||
wxCpUsers.forEach(item -> {
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setId(IdUtils.fastSimpleUUID())
|
||||
.setStatus(item.getStatus() == 1)
|
||||
.setUserType(UserType.OAM_USER.toString())
|
||||
.setCreateUserId("1");
|
||||
sysUser.setUpdateUserId("1");
|
||||
userWxCpUserMap.put(sysUser, item);
|
||||
});
|
||||
Db.executeBatch(userWxCpUserMap.keySet(), CoreMapper.class, CoreMapper::insertSysUser);
|
||||
List<Staff> staffList = new ArrayList<>();
|
||||
//批量创建用户
|
||||
userWxCpUserMap.forEach((key, value) -> {
|
||||
Staff staff = new Staff();
|
||||
staff.setName(value.getName()).setUserId(key.getId()).setWxCpUserId(value.getUserId());
|
||||
staffList.add(staff);
|
||||
});
|
||||
this.saveBatch(staffList);
|
||||
//获取所有部门信息
|
||||
List<Dept> deptList = SpringUtils.getBean(DeptService.class).queryChain().where(DEPT.WX_CP_ID.isNotNull()).list();
|
||||
//部门id映射
|
||||
Map<Long, String> deptMap = deptList.stream().collect(Collectors.toMap(Dept::getWxCpId, Dept::getId));
|
||||
List<StaffMidDept> staffMidDeptList = new ArrayList<>();
|
||||
//批量创建用户
|
||||
userWxCpUserMap.forEach((key, value) -> {
|
||||
for (Long wxDeptId : value.getDepartIds()) {
|
||||
StaffMidDept staffMidDept = new StaffMidDept();
|
||||
staffMidDept.setStaffId(key.getId()).setDeptId(deptMap.get(wxDeptId));
|
||||
staffMidDeptList.add(staffMidDept);
|
||||
}
|
||||
});
|
||||
SpringUtils.getBean(StaffMidDeptService.class).saveBatch(staffMidDeptList);
|
||||
}
|
||||
} catch (WxErrorException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ public class WxCpConfiguration {
|
||||
cpServices = this.properties.getAppConfigs().stream().map(a -> {
|
||||
val configStorage = new WxCpDefaultConfigImpl();
|
||||
configStorage.setCorpId(this.properties.getCorpId());
|
||||
configStorage.setOauth2redirectUri(this.properties.getOAuth2RedirectUri());
|
||||
configStorage.setAgentId(a.getAgentId());
|
||||
configStorage.setCorpSecret(a.getSecret());
|
||||
configStorage.setToken(a.getToken());
|
||||
|
||||
@ -22,6 +22,11 @@ public class WxCpProperties {
|
||||
*/
|
||||
private String corpId;
|
||||
|
||||
/**
|
||||
* oAuth2认证调整地址
|
||||
*/
|
||||
private String oAuth2RedirectUri;
|
||||
|
||||
private List<AppConfig> appConfigs;
|
||||
|
||||
@Getter
|
||||
|
||||
@ -4,7 +4,7 @@ package com.cpop.oam.framework.constant;
|
||||
* 企业微信通知类型实体类
|
||||
* @author DB
|
||||
*/
|
||||
public interface WxCpNoticeType {
|
||||
public interface WxCpConstant {
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
@ -35,4 +35,5 @@ public interface WxCpNoticeType {
|
||||
* 删除部门
|
||||
*/
|
||||
String DELETE_DEPT = "delete_party";
|
||||
|
||||
}
|
||||
@ -3,7 +3,7 @@ package com.cpop.oam.framework.handler.wxCp;
|
||||
import com.cpop.common.utils.JsonUtils;
|
||||
import com.cpop.oam.business.service.StaffService;
|
||||
import com.cpop.oam.framework.builder.wxCp.TextBuilder;
|
||||
import com.cpop.oam.framework.constant.WxCpNoticeType;
|
||||
import com.cpop.oam.framework.constant.WxCpConstant;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpXmlMessage;
|
||||
@ -30,18 +30,18 @@ public class ContactChangeHandler extends AbstractHandler {
|
||||
this.logger.info(content);
|
||||
//通知处理
|
||||
switch (wxMessage.getChangeType()){
|
||||
case WxCpNoticeType.CREATE_USER:
|
||||
case WxCpConstant.CREATE_USER:
|
||||
staffService.createWxCpUser(wxMessage, cpService);
|
||||
break;
|
||||
case WxCpNoticeType.UPDATE_USER:
|
||||
case WxCpConstant.UPDATE_USER:
|
||||
break;
|
||||
case WxCpNoticeType.DELETE_USER:
|
||||
case WxCpConstant.DELETE_USER:
|
||||
break;
|
||||
case WxCpNoticeType.CREATE_DEPT:
|
||||
case WxCpConstant.CREATE_DEPT:
|
||||
break;
|
||||
case WxCpNoticeType.UPDATE_DEPT:
|
||||
case WxCpConstant.UPDATE_DEPT:
|
||||
break;
|
||||
case WxCpNoticeType.DELETE_DEPT:
|
||||
case WxCpConstant.DELETE_DEPT:
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user