diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java b/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java index 18791b7..59a78dd 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java +++ b/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java @@ -12,7 +12,7 @@ public enum OrderSource { /** * 商城 */ - MALL("Mall",0.06); + MALL("Mall",0.002); OrderSource(String name, Double rate) { this.rate = rate; diff --git a/Cpop-Mall/Cpop-Mall-Web/pom.xml b/Cpop-Mall/Cpop-Mall-Web/pom.xml index b79800d..ea4c3c0 100644 --- a/Cpop-Mall/Cpop-Mall-Web/pom.xml +++ b/Cpop-Mall/Cpop-Mall-Web/pom.xml @@ -29,7 +29,7 @@ - Cpop-Oam-Web + Cpop-Mall-Web org.springframework.boot diff --git a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java index 1669f45..403f303 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java +++ b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java @@ -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); + } + } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java index b8f3f9e..f04841f 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java @@ -305,7 +305,7 @@ public class OrderServiceImpl extends ServiceImpl 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 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 implements Map 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); } //异步更新 diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/task/WxPayAsyncTask.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/task/WxPayAsyncTask.java index 89671e9..36d4c73 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/task/WxPayAsyncTask.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/task/WxPayAsyncTask.java @@ -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); - //存入系统 - 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(); + 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()); diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml index 3f8e27a..fe43f55 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application.yml @@ -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 diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DeptController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DeptController.java similarity index 85% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DeptController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DeptController.java index 027afcd..c35c540 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DeptController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DeptController.java @@ -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 - * @Description: 同步企业微信部门 - * @Author DB - * @Date: 2023/5/9 20:47 - */ - @Deprecated - @PreAuthorize("@aps.hasPermission('*:*:*')") - @ApiOperation("同步企业微信部门") - @PostMapping("/syncWxCpDept") - public R syncWxCpDept() { - deptService.syncWxCpDept(); - return R.ok(); - } + } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DutyController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DutyController.java similarity index 98% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DutyController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DutyController.java index 784966a..686c957 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/DutyController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/DutyController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/FinanceReimburseController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/FinanceReimburseController.java similarity index 99% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/FinanceReimburseController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/FinanceReimburseController.java index e7bc831..1fdb6e8 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/FinanceReimburseController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/FinanceReimburseController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/OamMallController.java similarity index 98% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/OamMallController.java index 29fac32..c92af6a 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/OamMallController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/OamMallController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/StaffController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/StaffController.java similarity index 93% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/StaffController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/StaffController.java index 1b31d63..ec41a82 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/StaffController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/StaffController.java @@ -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 - * @Description: 同步企业微信员工 - * @Author DB - * @Date: 2023/5/9 20:47 - */ - @Deprecated - @PreAuthorize("@aps.hasPermission('*:*:*')") - @ApiOperation("同步企业微信员工") - @PostMapping("/syncWxCpStaff") - public R syncWxCpStaff() { - staffService.syncWxCpStaff(); - return R.ok(); - } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/SysConfigController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/SysConfigController.java similarity index 97% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/SysConfigController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/SysConfigController.java index c68d5db..2d58f4b 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/SysConfigController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/SysConfigController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskController.java similarity index 99% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskController.java index 36006d3..3b396f7 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskDemandController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskDemandController.java similarity index 97% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskDemandController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskDemandController.java index b2141f6..e49e658 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskDemandController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskDemandController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskWorkOrderController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskWorkOrderController.java similarity index 98% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskWorkOrderController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskWorkOrderController.java index 426d0d2..68e9a5b 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/TaskWorkOrderController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/TaskWorkOrderController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxCpController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxCpController.java new file mode 100644 index 0000000..1b00fe2 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxCpController.java @@ -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 + * @Description: 同步企业微信部门 + * @Author DB + * @Date: 2023/5/9 20:47 + */ + @Deprecated + @PreAuthorize("@aps.hasPermission('*:*:*')") + @ApiOperation("同步企业微信部门") + @PostMapping("/syncWxCpDept") + public R syncWxCpDept() { + oamWxCpService.syncWxCpDept(); + return R.ok(); + } + + /** + * @return R + * @Description: 同步企业微信员工 + * @Author DB + * @Date: 2023/5/9 20:47 + */ + @Deprecated + @PreAuthorize("@aps.hasPermission('*:*:*')") + @ApiOperation("同步企业微信员工") + @PostMapping("/syncWxCpStaff") + public R syncWxCpStaff() { + oamWxCpService.syncWxCpStaff(); + return R.ok(); + } +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxOpenController.java similarity index 99% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxOpenController.java index b741224..bee237e 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxOpenController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxOpenController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java similarity index 98% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java index b640be8..0123e11 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxPayController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java @@ -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; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxCpPortalController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/callback/WxCpPortalController.java similarity index 94% rename from Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxCpPortalController.java rename to Cpop-Oam/src/main/java/com/cpop/oam/business/controller/callback/WxCpPortalController.java index 22df6ee..cf88ab4 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/WxCpPortalController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/callback/WxCpPortalController.java @@ -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; } + } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/DeptService.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/DeptService.java index 6e0e253..0bc770a 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/DeptService.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/DeptService.java @@ -48,12 +48,4 @@ public interface DeptService extends IService { */ void removeDept(String id); - /** - * @descriptions 同步企业微信部门 - * @author DB - * @date 2023/11/15 16:56 - * @return: void - */ - void syncWxCpDept(); - } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamWxCpService.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamWxCpService.java new file mode 100644 index 0000000..50f7a50 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/OamWxCpService.java @@ -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(); +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/StaffService.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/StaffService.java index e43168a..6b42e5f 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/StaffService.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/StaffService.java @@ -120,11 +120,4 @@ public interface StaffService extends IService { */ void createWxCpUser(WxCpXmlMessage wxMessage, WxCpService cpService); - /** - * @descriptions 同步企业微信员工 - * @author DB - * @date 2023/11/16 17:03 - * @return: void - */ - void syncWxCpStaff(); } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DeptServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DeptServiceImpl.java index 7fb4e2a..1bfb737 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DeptServiceImpl.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/DeptServiceImpl.java @@ -212,63 +212,4 @@ public class DeptServiceImpl extends ServiceImpl implements De }); } - /** - * @descriptions 同步企业微信部门 - * @author DB - * @date 2023/11/15 16:56 - * @return: void - */ - @Override - public void syncWxCpDept() { - //企业微信互通应用 - WxCpService cpService = WxCpConfiguration.getCpService(1000024); - try { - //获取所有数据 - List 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 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 wxCpDepartList, Dept parentDept) { - List deptList = new ArrayList(); - Iterator 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); - }); - } - } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamWxCpServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamWxCpServiceImpl.java new file mode 100644 index 0000000..8fe8537 --- /dev/null +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/OamWxCpServiceImpl.java @@ -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 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 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 wxCpDepartList, Dept parentDept) { + List deptList = new ArrayList(); + Iterator 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 wxCpUsers = cpService.getUserService().listByDepartment(1L, true, 0); + if (!wxCpUsers.isEmpty()){ + //批量插入用户 + Map 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 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 deptList = SpringUtils.getBean(DeptService.class).queryChain().where(DEPT.WX_CP_ID.isNotNull()).list(); + //部门id映射 + Map deptMap = deptList.stream().collect(Collectors.toMap(Dept::getWxCpId, Dept::getId)); + Map userIdToStaffIdMap = staffList.stream().collect(Collectors.toMap(Staff::getUserId, Staff::getId)); + List 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()); + } + } +} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/StaffServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/StaffServiceImpl.java index c130c27..36d2aa4 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/StaffServiceImpl.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/StaffServiceImpl.java @@ -379,57 +379,4 @@ public class StaffServiceImpl extends ServiceImpl 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 wxCpUsers = cpService.getUserService().listByDepartment(1L, true, 0); - if (!wxCpUsers.isEmpty()){ - log.info("部门用户信息:{}", JSONArray.toJSONString(wxCpUsers)); - //批量插入用户 - Map 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 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 deptList = SpringUtils.getBean(DeptService.class).queryChain().where(DEPT.WX_CP_ID.isNotNull()).list(); - //部门id映射 - Map deptMap = deptList.stream().collect(Collectors.toMap(Dept::getWxCpId, Dept::getId)); - List 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()); - } - } } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpConfiguration.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpConfiguration.java index 5d7cc91..3540bce 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpConfiguration.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpConfiguration.java @@ -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()); diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpProperties.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpProperties.java index 700c767..761473d 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpProperties.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxCp/WxCpProperties.java @@ -22,6 +22,11 @@ public class WxCpProperties { */ private String corpId; + /** + * oAuth2认证调整地址 + */ + private String oAuth2RedirectUri; + private List appConfigs; @Getter diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpNoticeType.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpConstant.java similarity index 94% rename from Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpNoticeType.java rename to Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpConstant.java index 465309c..a783d4e 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpNoticeType.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/constant/WxCpConstant.java @@ -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"; + } diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxCp/ContactChangeHandler.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxCp/ContactChangeHandler.java index 4136555..23b2395 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxCp/ContactChangeHandler.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxCp/ContactChangeHandler.java @@ -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: }