bug
jiangqs
2023-08-17 b7c94458ce1c37cfc1b8797ebc38a9a03e305b1f
bug
17个文件已修改
4个文件已添加
402 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/sys/SysDept.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerOrderController.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/pojo/shop/ShopAuthentication.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/vo/MerAgencyPageVo.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/vo/MgtShopAuthPageVo.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-shop/src/main/resources/mapper/shop/ShopMapper.xml 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/WxCpConfiguration.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/WxCpProperties.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/conslole/QYWXCallBackController.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/sys/SysDeptMapper.java 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/scheduler/SystemScheduler.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysWxCpServiceImpl.java 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/sys/SysDeptServiceImpl.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/staff/SysWxCpService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/sys/ISysDeptService.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/main/resources/mapper/sys/SysDeptMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/systemTest.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/poji/sys/SysDept.java
@@ -66,6 +66,9 @@
    /** 菜单组 */
    private Long[] staffMenuIds;
    /** 微信部门id */
    private Long wxDeptId;
    public Long getDeptId()
    {
        return deptId;
@@ -216,6 +219,14 @@
        this.staffMenuIds = staffMenuIds;
    }
    public Long getWxDeptId() {
        return wxDeptId;
    }
    public void setWxDeptId(Long wxDeptId) {
        this.wxDeptId = wxDeptId;
    }
    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@@ -234,6 +245,7 @@
            .append("updateBy", getUpdateBy())
            .append("updateTime", getUpdateTime())
            .append("dataScope", getDataScope())
            .append("wxDeptId", getWxDeptId())
            .toString();
    }
}
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/business/MerOrderController.java
@@ -64,6 +64,16 @@
        return R.ok(merVerifyCodeVo);
    }
    @RequestMapping(value = "/verifyOrder", method = RequestMethod.POST)
    @ApiOperation(value = "核销code")
    public R<MerVerifyOrderVo> verifyOrder(@RequestBody MerVerifyCodeDto merVerifyCodeDto) {
        Long userId = SecurityUtils.getUserId();
        merVerifyCodeDto.setUserId(userId);
        String verifyCode = merVerifyCodeDto.getVerifyCode();
        MerVerifyOrderVo merVerifyOrderVo = orderService.verifyOrder(verifyCode,merVerifyCodeDto.getShopId());
        return R.ok(merVerifyOrderVo);
    }
    @RequestMapping(value = "/sureVerifyOrder", method = RequestMethod.POST)
    @ApiOperation(value = "核销订单")
    public R<MerVerifyOrderVo> sureVerifyOrder(@RequestBody MerVerifyOrderDto merVerifyOrderDto) {
ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/controller/miniapp/NotifyController.java
@@ -51,7 +51,7 @@
    @Resource
    private OrderService orderService;
    @Autowired
    @Resource
    private WxPayService wxService;
    @Resource
    private BackMessageService backMessageService;
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/pojo/shop/ShopAuthentication.java
@@ -61,6 +61,7 @@
     */
    @TableField("audit_status")
    private Integer auditStatus;
    /**
     * 主题类型1个人2企业
     */
@@ -86,6 +87,9 @@
     */
    @TableField("bl_registered_address")
    private String blRegisteredAddress;
    @TableField("bl_business_start_time")
    private String blBusinessStartTime;
    /**
     * 营业执照期限
     */
@@ -106,6 +110,10 @@
     */
    @TableField("lp_id_card")
    private String lpIdCard;
    @TableField("lp_id_address")
    private String lpIdAddress;
    /**
     * 法人身份证开始日期
     */
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/vo/MerAgencyPageVo.java
@@ -38,5 +38,6 @@
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date cooperationEndTime;
    @ApiModelProperty(value="合作状态0终止1开启")
    private Integer cooperativeFlag;
}
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/domain/vo/MgtShopAuthPageVo.java
@@ -32,9 +32,18 @@
    @ApiModelProperty(value="认证类型")
    private String mainType;
    @ApiModelProperty(value="审核状态")
    @ApiModelProperty(value="审核状态0待进件1资料校验中2待账户验证3审核中4已驳回5待签约6完成7已冻结8已作废")
    private Integer auditStatus;
    @ApiModelProperty(value="审核状态描述")
    private String auditStatusDesc;
    @ApiModelProperty(value = "签约状态1待签约2已签约3无法签约")
    private Integer signState;
    @ApiModelProperty(value = "签约链接")
    private String signUrl;
}
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/service/impl/shop/ShopServiceImpl.java
@@ -6,6 +6,7 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsResult;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.ruoyi.common.core.constant.CacheConstants;
@@ -352,6 +353,8 @@
        shopAuthentication.setAuthId(authId);
        shopAuthentication.setDelFlag(0);
        shopAuthentication.setShopId(shop.getShopId());
        shopAuthentication.setAuditStatus(0);
        shopAuthentication.setSignState(1);
        shopAuthenticationService.save(shopAuthentication);
        //商户分成信息初始化
        ShopProportion shopProportion = new ShopProportion();
@@ -593,13 +596,19 @@
            }
            mgtShopInfoVo.setShopTagIds(shopTagJs.toString());
        }
        //归属员工
        if(mgtShopInfoVo.getBelongUserId()!=null){
            SysUser sysUser = sysUserService.getSysUser(mgtShopInfoVo.getBelongUserId()).getData();
            mgtShopInfoVo.setBelongUserName(sysUser.getNickName());
            if(sysUser!=null){
                mgtShopInfoVo.setBelongUserName(sysUser.getNickName());
            }
        }
        //归属商户
        if(mgtShopInfoVo.getBelongShopId()!=null){
            Shop belongShop = this.getByShopId(mgtShopInfoVo.getBelongShopId());
            mgtShopInfoVo.setBelongShopName(belongShop.getShopName());
            if(belongShop!=null){
                mgtShopInfoVo.setBelongShopName(belongShop.getShopName());
            }
        }
        //商户关联用户
        List<ShopRelUser> shopRelUserList = shopRelUserService.listByShopId(shopId);
@@ -994,16 +1003,22 @@
        Shop shop = this.getByShopId(shopAuthentication.getShopId());
        String applyNumber = IdUtils.simpleUUID();
        if(mgtShopAuthDto.getBlBusinessFoeverFlag()!=null&&mgtShopAuthDto.getBlBusinessFoeverFlag()==1){
            mgtShopAuthDto.setBlBusinessDeanline("长期");
            mgtShopAuthDto.setBlBusinessDeanline(mgtShopAuthDto.getBlBusinessStartTime()+",长期");
        }
        if(mgtShopAuthDto.getLpIcForeverFlag()!=null&&mgtShopAuthDto.getLpIcForeverFlag()==1){
            mgtShopAuthDto.setLpIcEndDate("长期");
        }
        BeanUtils.copyProperties(mgtShopAuthDto , shopAuthentication);
        shopAuthentication.setApplyNumber(applyNumber);
        ApplymentsResult applymentsResult;
        try {
            applymentsResult = wechatPayUtils.ecommerceApply(shopAuthentication,applyNumber,shop);
        } catch (Exception e) {
            log.debug("-----"+shop.getShopId()+":进件异常-----");
            throw new RuntimeException(e);
        }
        shopAuthentication.setAuditStatus(3);
        shopAuthenticationService.saveOrUpdate(shopAuthentication);
        //wechatPayUtils.ecommerceApply(shopAuthentication,applyNumber,shop);
    }
    /**
ruoyi-modules/ruoyi-shop/src/main/java/com/ruoyi/shop/util/WechatPayUtils.java
@@ -1,5 +1,6 @@
package com.ruoyi.shop.util;
import com.alibaba.fastjson.JSONObject;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsRequest;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsResult;
import com.github.binarywang.wxpay.bean.ecommerce.ApplymentsStatusResult;
@@ -56,7 +57,13 @@
        business_license_info.setMerchantName(shopAuthentication.getBlShopName());
        business_license_info.setLegalPerson(shopAuthentication.getBlCorporateName());
        business_license_info.setCompanyAddress(shopAuthentication.getBlRegisteredAddress());
        business_license_info.setBusinessTime("[\"2023-05-08\",\"长期\"]");
        List<String> businessTimeList = new ArrayList<>();
        businessTimeList.add(0,shopAuthentication.getBlBusinessStartTime());
        businessTimeList.add(1,shopAuthentication.getBlBusinessDeanline());
        if(businessTimeList!=null&&businessTimeList.size()>1){
            String businessTime = JSONObject.toJSONString(businessTimeList);
            business_license_info.setBusinessTime(businessTime);
        }
        request.setBusinessLicenseInfo(business_license_info);
        //法人证件
        request.setIdDocType("IDENTIFICATION_TYPE_MAINLAND_IDCARD");
@@ -71,7 +78,7 @@
        lpIcBackIO.close();
        id_card_info.setIdCardName(shopAuthentication.getLpCorporateName());
        id_card_info.setIdCardNumber(shopAuthentication.getLpIdCard());
        id_card_info.setIdCardAddress("四川省泸州市江阳区桃园路1号2号楼4单元1号");
        id_card_info.setIdCardAddress(shopAuthentication.getLpIdAddress());
        id_card_info.setIdCardValidTimeBegin(shopAuthentication.getLpIcStartDate());
        id_card_info.setIdCardValidTime(shopAuthentication.getLpIcEndDate());
        request.setIdCardInfo(id_card_info);
@@ -118,8 +125,8 @@
        contactInfo.setContactType("65");
        contactInfo.setContactName(shopAuthentication.getLpCorporateName());
        contactInfo.setContactIdCardNumber(shopAuthentication.getLpIdCard());
        contactInfo.setMobilePhone("13882237106");
        contactInfo.setContactEmail("343695869@qq.com");
        contactInfo.setMobilePhone(shopAuthentication.getLpMobilePhone());
        contactInfo.setContactEmail(shopAuthentication.getLpContactEmail());
        request.setContactInfo(contactInfo);
        //店铺信息
        ApplymentsRequest.SalesSceneInfo salesSceneInfo = new ApplymentsRequest.SalesSceneInfo();
@@ -127,6 +134,7 @@
        InputStream storeQrCodeIO = OBSUploadUtils.getOSSInputStream(shop.getShopCode().replace("https://hongruitang.oss-cn-beijing.aliyuncs.com/",""));
        ImageUploadResult storeQrCodeIR = merchantMediaService.imageUploadV3(storeQrCodeIO,applyNumber+"storeQrCode.jpg");
        salesSceneInfo.setStoreQrCode(storeQrCodeIR.getMediaId());
        storeQrCodeIO.close();
        request.setSalesSceneInfo(salesSceneInfo);
        request.setMerchantShortname(shop.getShopName());
        request.setBusinessAdditionPics(shopAuthentication.getBaPics());
ruoyi-modules/ruoyi-shop/src/main/resources/mapper/shop/ShopMapper.xml
@@ -404,7 +404,8 @@
        CONCAT(ts.shop_area_name,ts.shop_address) shopAddress,
        ts.shopowner_name shopownerName,
        ts.shopowner_phone shopownerPhone,
        ts.cooperation_end_time cooperationEndTime
        ts.cooperation_end_time cooperationEndTime,
        ts.cooperative_flag cooperativeFlag
        FROM t_shop ts
        WHERE ts.del_flag = 0 AND ts.belong_shop_id = #{param.shopId}
        <if test="param.shopStatus!=null and param.shopStatus==1">
@@ -530,6 +531,8 @@
            WHEN 2 THEN '企业'
            END mainType,
        tsa.audit_status auditStatus,
        tsa.sign_state signState,
        tsa.sign_url signUrl,
        CASE tsa.audit_status
            WHEN 0 THEN '待审核'
            WHEN 1 THEN '审核中'
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/WxCpConfiguration.java
New file
@@ -0,0 +1,51 @@
package com.ruoyi.system.config;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @ClassName WxCpConfiguration
 * @Description TODO
 * @Author jqs
 * @Date 2023/8/17 12:42
 * @Version 1.0
 */
@Configuration
@ConditionalOnClass(WxCpService.class)
@EnableConfigurationProperties(WxCpProperties.class)
@AllArgsConstructor
public class WxCpConfiguration {
    private WxCpProperties properties;
    @Bean
    @ConditionalOnMissingBean
    public WxCpService wxService() {
        WxCpDefaultConfigImpl wxCpConfigStorage = new WxCpDefaultConfigImpl();
        wxCpConfigStorage.setCorpId(properties.getCorpId());
        wxCpConfigStorage.setAgentId(properties.getAgentId());
        wxCpConfigStorage.setCorpSecret(properties.getAgentSecret());
        WxCpService wxService = new WxCpServiceImpl();
        wxService.setWxCpConfigStorage(wxCpConfigStorage);
        return wxService;
    }
    @Bean
    public WxCryptUtil wxCryptUtil() {
        WxCryptUtil wxCryptUtil = new WxCryptUtil("", "", properties.getCorpId());
        return wxCryptUtil;
    }
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/config/WxCpProperties.java
New file
@@ -0,0 +1,36 @@
package com.ruoyi.system.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
 * @ClassName WxCpProperties
 * @Description TODO
 * @Author jqs
 * @Date 2023/8/17 12:43
 * @Version 1.0
 */
@Data
@ConfigurationProperties(prefix = "wx.cp")
public class WxCpProperties {
    /**
     *
     */
    private String corpId;
    /**
     *
     */
    private Integer agentId;
    /**
     *
     */
    private String agentSecret;
    /**
     *
     */
    private String authorizeState;
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/conslole/QYWXCallBackController.java
@@ -1,10 +1,15 @@
package com.ruoyi.system.controller.conslole;
import com.esotericsoftware.minlog.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -19,8 +24,11 @@
@Api(value = "企业微信通知控制", tags = "企业微信通知控制", description = "企业微信通知控制")
@RestController
@RequestMapping("/qywx")
@Log4j2
public class QYWXCallBackController {
    @Autowired
    private  WxCryptUtil wxCryptUtil;
    @ApiOperation(value = "消息与事件接收配置")
    @RequestMapping(value = "/qywxNotify",
@@ -35,7 +43,14 @@
        String msgSignature = request.getParameter("msg_signature");
        String encType =  request.getParameter("encrypt_type");
        String xml =  IOUtils.toString(request.getReader());
        Log.info("企业微信回调"+xml);
        log.info("企业微信回调参数nonce"+nonce);
        log.info("企业微信回调参数timestamp"+timestamp);
        log.info("企业微信回调参数signature"+signature);
        log.info("企业微信回调参数msgSignature"+msgSignature);
        log.info("企业微信回调参数encType"+encType);
        log.info("企业微信回调参数xml"+xml);
        String reponseStr = wxCryptUtil.decryptXml(msgSignature,timestamp,nonce,xml);
        log.info("企业微信回调参数xml解析"+reponseStr);
        return "SUCCESS";
    }
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/sys/SysDeptMapper.java
@@ -1,8 +1,9 @@
package com.ruoyi.system.mapper.sys;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.system.api.domain.poji.sys.SysDept;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * 部门管理 数据层
@@ -36,6 +37,16 @@
     */
    public SysDept selectDeptById(Long deptId);
    /**
     * @description  通过微信部门id获取部门
     * @author  jqs
     * @date    2023/8/17 16:21
     * @param wxDeptId
     * @return  SysDept
     */
    SysDept getByWxDeptId(Long wxDeptId);
    /**
     * 根据ID查询所有子部门
     * 
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/scheduler/SystemScheduler.java
@@ -1,8 +1,10 @@
package com.ruoyi.system.scheduler;
import com.ruoyi.system.service.staff.SysWxCpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -14,7 +16,20 @@
    @Autowired
    private SchedulerUtils schedulerUtils;
    @Autowired
    private SysWxCpService sysWxCpService;
    /**
     * 定时同步企业微信部门
     */
    @Scheduled(cron="0 2 * * * ?")
    private void timingCheckMemberCoupon(){
        if(schedulerUtils.getSchedulerRun()) {
            log.info("定时同步企业微信部门任务开始执行");
            sysWxCpService.syncDepartment();
        }
    }
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysWxCpServiceImpl.java
New file
@@ -0,0 +1,94 @@
package com.ruoyi.system.service.impl.staff;
import com.ruoyi.system.api.domain.poji.sys.SysDept;
import com.ruoyi.system.service.staff.SysWxCpService;
import com.ruoyi.system.service.sys.ISysDeptService;
import lombok.extern.log4j.Log4j2;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
 * @ClassName WxCpServiceImpl
 * @Description TODO
 * @Author jqs
 * @Date 2023/8/17 15:25
 * @Version 1.0
 */
@Service
@Log4j2
public class SysWxCpServiceImpl implements SysWxCpService {
    @Resource
    private WxCpService wxCpService;
    @Resource
    private ISysDeptService  sysDeptService;
    /**
     * @description
     * @author  jqs
     * @date    2023/8/17 15:26
     * @param
     * @return  String
     */
    @Override
    public String getToken(){
        String accessToken = null;
        try {
            accessToken = wxCpService.getAccessToken();
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
        return accessToken;
    }
    /**
     * @description  同步部门
     * @author  jqs
     * @date    2023/8/17 15:42
     * @param
     * @return  void
     */
    @Override
    public void syncDepartment(){
        WxCpDepartmentService wxCpDepartmentService = wxCpService.getDepartmentService();
        try {
            //从企业微信拉去部门名单
            List<WxCpDepart> wxCpDepartList = wxCpDepartmentService.list(null);
            if(wxCpDepartList!=null&&wxCpDepartList.size()>0){
                for(WxCpDepart wxCpDepart : wxCpDepartList){
                    //获取系统内对应部门
                    SysDept sysDept = sysDeptService.getByWxDeptId(wxCpDepart.getId());
                    //判断是否有该部门,没有则新建
                    if(sysDept!=null){
                        //判断是否有变化
                        if(!sysDept.getDeptName().equals(wxCpDepart.getName())||sysDept.getOrderNum()!=wxCpDepart.getOrder().intValue()){
                            sysDept.setDeptName(wxCpDepart.getName());
                            sysDept.setOrderNum(wxCpDepart.getOrder().intValue());
                            sysDept.setUpdateBy("企业微信同步");
                            sysDeptService.updateDept(sysDept);
                            log.info("企业微信同步更新部门:"+wxCpDepart.getName());
                        }
                    }else{
                        sysDept = new SysDept();
                        sysDept.setDelFlag("0");
                        sysDept.setStatus("0");
                        sysDept.setParentId(100L);
                        sysDept.setOrderNum(wxCpDepart.getOrder().intValue());
                        sysDept.setCreateBy("企业微信同步");
                        sysDept.setDeptName(wxCpDepart.getName());
                        sysDeptService.insertDept(sysDept);
                        log.info("企业微信同步新增部门:"+wxCpDepart.getName());
                    }
                }
            }
        } catch (WxErrorException e) {
            throw new RuntimeException(e);
        }
    }
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/sys/SysDeptServiceImpl.java
@@ -383,4 +383,17 @@
    {
        return getChildList(list, t).size() > 0 ? true : false;
    }
    /**
     * @description  通过微信部门id获取部门
     * @author  jqs
     * @date    2023/8/17 16:21
     * @param wxDeptId
     * @return  SysDept
     */
    @Override
    public SysDept getByWxDeptId(Long wxDeptId){
        return deptMapper.getByWxDeptId(wxDeptId);
    }
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/staff/SysWxCpService.java
New file
@@ -0,0 +1,29 @@
package com.ruoyi.system.service.staff;
/**
 * @ClassName WxCpService
 * @Description TODO
 * @Author jqs
 * @Date 2023/8/17 15:22
 * @Version 1.0
 */
public interface SysWxCpService {
    /**
     * @description 获取token
     * @author  jqs
     * @date    2023/8/17 15:26
     * @param
     * @return  String
     */
    String getToken();
    /**
     * @description  同步部门
     * @author  jqs
     * @date    2023/8/17 15:42
     * @param
     * @return  void
     */
    void syncDepartment();
}
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/sys/ISysDeptService.java
@@ -1,8 +1,9 @@
package com.ruoyi.system.service.sys;
import java.util.List;
import com.ruoyi.system.api.domain.poji.sys.SysDept;
import com.ruoyi.system.domain.vo.TreeSelect;
import java.util.List;
/**
 * 部门管理 服务层
@@ -121,4 +122,13 @@
     * @return 结果
     */
    public int deleteDeptById(Long deptId);
    /**
     * @description  通过微信部门id获取部门
     * @author  jqs
     * @date    2023/8/17 16:21
     * @param wxDeptId
     * @return  SysDept
     */
    SysDept getByWxDeptId(Long wxDeptId);
}
ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml
@@ -35,3 +35,14 @@
      max-request-size: 200MB
      location: /home/temp
wx:
  cp:
    corpId: ww11400938eb1b91bc
    agentId: 1000024
    agentSecret: -wuQ2EBxNT9BJa40LdpFqyxI_8RqrZTCUNiabzBasi8
    authorizeState: HONGRUITANG
    suiteSecret: ""
    token: ""
    encodingAESKey: ""
ruoyi-modules/ruoyi-system/src/main/resources/mapper/sys/SysDeptMapper.xml
@@ -21,10 +21,11 @@
        <result property="updateBy"   column="update_by"   />
        <result property="updateTime" column="update_time" />
        <result property="dataScope" column="data_scope" />
        <result property="wxDeptId" column="wx_dept_id" />
    </resultMap>
    
    <sql id="selectDeptVo">
        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time ,d.data_scope
        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time ,d.data_scope,d.wx_dept_id
        from sys_dept d
    </sql>
    
@@ -63,6 +64,11 @@
        <include refid="selectDeptVo"/>
        where dept_id = #{deptId}
    </select>
    <select id="getByWxDeptId" parameterType="Long" resultMap="SysDeptResult">
        <include refid="selectDeptVo"/>
        where wx_dept_id = #{wxDeptId}
    </select>
    
    <select id="checkDeptExistUser" parameterType="Long" resultType="int">
        select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'
ruoyi-modules/ruoyi-system/src/test/java/com/ruoyi/system/systemTest.java
@@ -1,9 +1,12 @@
package com.ruoyi.system;
import com.ruoyi.system.service.staff.SysWxCpService;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.Resource;
/**
 * @ClassName systemTest
@@ -16,7 +19,7 @@
@SpringBootTest(classes = RuoYiSystemApplication.class)
public class systemTest {
    @Resource
    private SysWxCpService sysWxCpService;
}