e328acd399dae70ccdf413a6dce94272563477b5..9b208eb3947358169df8f46472a246eb6ea8ca32
2023-12-18 fuliqi
工作通知
9b208e 对比 | 目录
2023-12-18 fuliqi
Merge remote-tracking branch 'origin/master'
acea91 对比 | 目录
2023-12-18 fuliqi
工作通知定时任务
f11afb 对比 | 目录
7个文件已修改
5个文件已添加
361 ■■■■ 已修改文件
ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/auth/impl/AuthService.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java 83 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/resources/application-online.yml 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-platform/src/main/resources/logback-spring.xml 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ycl-common/src/main/java/com/ycl/entity/user/UmsAdmin.java
@@ -103,6 +103,7 @@
    private String openid;
    @ApiModelProperty(value = "钉钉账户id")
    @TableField("account_id")
    private Long accountId;
    @ApiModelProperty(value = "是否为网格管理员:0->不是;1->是")
ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java
@@ -62,7 +62,6 @@
//        判断ding 信息是否存在
        boolean hasDing = redisTemplate.hasKey("ding");
        if (hasDing) {
            log.info("redis正常有消息");
            String dingStr = redisTemplate.opsForValue().get("ding");
            JSONObject dingObj = JSONObject.parseObject(dingStr);
            String getToken = dingObj.getString("token");
@@ -86,6 +85,12 @@
                DingUserInfo dingUserInfo = BeanUtil.toBean(resObj, DingUserInfo.class);
                String accId = DingEncodeUtil.getMD5(resObj.getString("employeeCode").getBytes());
                dingUserInfo.setUserId(Long.parseLong(accId));
                String employeeCode = resObj.getString("employeeCode");
                JSONArray users = getAccountId(Arrays.asList(employeeCode));
                JSONObject jsonObject = users.getJSONObject(0);
                String accountId = jsonObject.getString("accountId");
                dingUserInfo.setAccountId(Long.parseLong(accountId));
                return dingUserInfo;
            }
        }
@@ -313,7 +318,16 @@
                } while (isHasPage);
            }
        }
        //补充accountId
        dingAccoutId(employeeCodes,dingUserInfoList);
        JSONArray arr = new JSONArray(Collections.singletonList(dingUserInfoList));
        redisTemplate.opsForValue().set("userJsonList", arr.toJSONString());
        return dingUserInfoList;
    }
    //补充DingUserInfo中的accountId
    private void insertAccoutId(Set<DingUserInfo> dingUserInfoList, List<String> employeeCodes) {
        if(CollectionUtils.isNotEmpty(employeeCodes)) {
            log.info("开始补充accountId");
            JSONArray users = getAccountId(employeeCodes);
@@ -331,10 +345,36 @@
                }
            }
        }
    }
        JSONArray arr = new JSONArray(Collections.singletonList(dingUserInfoList));
        redisTemplate.opsForValue().set("userJsonList", arr.toJSONString());
        return dingUserInfoList;
    //分批执行
    private void dingAccoutId(List<String> employeeCodes,Set<DingUserInfo> dingUserInfoList) {
        // 每次插入的数量
        int batchSize = 99;
        // 计算需要分多少批
        int batch = employeeCodes.size() / batchSize;
        // 计算最后一批的大小
        int lastSize = employeeCodes.size() % batchSize;
        log.info("插入数量{},分多少批{},最后一批的大小{}", batchSize, batch, lastSize);
        // 将筛选出的结果分批次添加
        int num = 1;
        for (int i = batchSize; i <= batch * batchSize; i = i + batchSize) {
            log.info("开始");
            // 截取本次要添加的数据
            List<String> insertList = employeeCodes.subList(i - batchSize, i);
            // 添加本批次数据
            log.info("批量导入数据第{}次", num);
            insertAccoutId(dingUserInfoList, insertList);
            num++;
        }
        // 最后一批元素的大小是否为0
        if (lastSize != 0) {
            // 如果元素有剩余则将所有元素一次性插入
            List<String> lastList = employeeCodes.subList(batchSize * batch, employeeCodes.size());
            log.info("最后一次导入数据");
            insertAccoutId(dingUserInfoList, lastList);
        }
    }
    /**
     * 根据员工code 获取员工accountId
@@ -350,6 +390,7 @@
        }
        postClient.addParameter("tenantId", dingConfig.getTenantId());
        String apiResult = postClient.post();
        log.info("获取员工accountId接口返回------>{}",apiResult);
        JSONObject resObj = parsingJson(apiResult);
        if (null != resObj) {
            return resObj.getJSONArray("data");
ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java
New file
@@ -0,0 +1,83 @@
package com.ycl.entity.message;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
/**
 * <p>
 * 钉钉消息
 * </p>
 *
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("ums_message_ding")
@ApiModel(value = "消息表")
@Builder
public class DingMessage implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    @ApiModelProperty(value = "主键")
    private Long id;
    /**
     * 接收者id
     */
    @TableField("account_id")
    @ApiModelProperty(value = "接收者id")
    private Long accountId;
    /**
     * 事件编号
     */
    @TableField("base_case_code")
    @ApiModelProperty(value = "事件编号")
    private String baseCaseCode;
    /**
     * 0待发送-1已发送-2-发送失败
     */
    @TableField("state")
    @ApiModelProperty(value = "0待发送-1已发送-2-发送失败")
    private Short state;
    /**
     * 创建时间
     */
    @TableField("create_time")
    @ApiModelProperty(value = "创建时间")
    private Date createTime;
    /**
     * 发送时间
     */
    @TableField("send_time")
    @ApiModelProperty(value = "发送时间")
    private Date sendTime;
    /**
     * 是否扫描,0未扫描-1已扫描
     */
    @TableField("if_scan")
    @ApiModelProperty(value = "是否扫描,0未扫描-1已扫描")
    private Short ifScan;
}
ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java
New file
@@ -0,0 +1,10 @@
package com.ycl.mapper.message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ycl.entity.message.DingMessage;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface DingMessageMapper extends BaseMapper<DingMessage> {
}
ycl-platform/src/main/java/com/ycl/service/auth/impl/AuthService.java
@@ -58,6 +58,7 @@
            userParam.setOpenid(openid); //openid
            userParam.setIsDy(Byte.parseByte("0"));
            userParam.setMobile("");
            userParam.setAccountId(dingUserInfo.getAccountId());
            String encodePassword = passwordEncoder.encode("123456");
            userParam.setPassword(encodePassword); //密码
            userParam.setStatus(1); //状态
ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java
@@ -15,12 +15,14 @@
import com.ycl.entity.caseHandler.DispatchInfo;
import com.ycl.entity.caseHandler.DisposeRecord;
import com.ycl.entity.caseHandler.WorkflowConfigStep;
import com.ycl.entity.message.DingMessage;
import com.ycl.entity.user.UmsAdmin;
import com.ycl.exception.ApiException;
import com.ycl.mapper.caseHandler.BaseCaseMapper;
import com.ycl.mapper.caseHandler.DispatchInfoMapper;
import com.ycl.mapper.caseHandler.DisposeRecordMapper;
import com.ycl.mapper.caseHandler.WorkflowConfigStepMapper;
import com.ycl.mapper.message.DingMessageMapper;
import com.ycl.service.caseHandler.IDispatchHandleService;
import com.ycl.service.user.UmsAdminService;
import lombok.extern.slf4j.Slf4j;
@@ -56,6 +58,8 @@
    DingCommon dingCommon;
    @Autowired
    UmsAdminService umsAdminService;
    @Autowired
    DingMessageMapper dingMessageMapper;
    @Override
    @Transactional
    public DispatchInfo dispatch(DispatchInfoParam dispatchInfoParam) {
@@ -110,17 +114,16 @@
        stepNextRecord.setCreateTime(LocalDateTime.now());
        disposeRecordMapper.insert(stepNextRecord);
        //发送钉钉工作通知消息
        log.info("发送一条工作通知");
        //存钉钉工作通知消息到数据库
        BaseCase baseCaseForCode = baseCaseMapper.selectById(dispatchInfoParam.getBaseCaseId());
        String baseCaseCode = baseCaseForCode.getCode();
        String text ="您有一条工作通知  \n  " +
                " 遂昌云执法:有待处理的任务  \n  " +
                "·您有1条待处理事件。事件编号:  \n  " +
                baseCaseCode;
        Long lawEnforcer = dispatchInfoParam.getLawEnforcer();
        UmsAdmin user = umsAdminService.getById(lawEnforcer);
        dingCommon.sendDingMsgStr(user.getAccountId()+"",text);
        Long accountId = umsAdminService.getById(lawEnforcer).getAccountId();
        DingMessage dingMessage = DingMessage.builder()
                .accountId(accountId)
                .baseCaseCode(baseCaseCode)
                .createTime(new Date()).build();
        dingMessageMapper.insert(dingMessage);
        return dispatchInfo;
    }
ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java
New file
@@ -0,0 +1,15 @@
package com.ycl.service.message;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ycl.entity.message.DingMessage;
/**
 * <p>
 * 钉钉消息
 * </p>
 *
 * @author mg
 * @since 2022-10-08
 */
public interface IDingMessageService extends IService<DingMessage> {
}
ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java
New file
@@ -0,0 +1,19 @@
package com.ycl.service.message.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycl.entity.message.DingMessage;
import com.ycl.mapper.message.DingMessageMapper;
import com.ycl.service.message.IDingMessageService;
import org.springframework.stereotype.Service;
/**
 * <p>
 * 钉钉消息实现类
 * </p>
 *
 */
@Service
public class DingMessageServiceImpl extends ServiceImpl<DingMessageMapper, DingMessage> implements IDingMessageService {
}
ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java
@@ -72,7 +72,8 @@
    @Value("${spring.profiles.active}")
    private String env;
    @Scheduled(cron = "0 0 1 * * ?")   // 每天零点执行
    @Scheduled(cron = "0 00 00 * * ?")   // 每天零点执行
    @Transactional(rollbackFor = Exception.class)
    public void run() {
        if ("online".equals(env)) {
@@ -115,13 +116,14 @@
            /**
             //         * 根据组织code 查询 通讯录人员信息
             //         */
            //查询用户组织关联表
            List<UmsDepartManage> empOrgList = departManageService.list();
            //查询所有用户
            Set<DingUserInfo> dingList = dingCommon.getPersonInfoByOrgCode();
            Set<DingUserInfo> dingUsers = new HashSet<>(dingList);
            log.info("dinglistStart----->{}", dingList);
            log.info("查询所有用户------->{}", dingUsers);
            List<UmsAdmin> userList = umsAdminService.list();
            //查询用户组织关联表
            List<UmsDepartManage> empOrgList = departManageService.list();
            Iterator<DingUserInfo> iterator = dingUsers.iterator();
            while (iterator.hasNext()) {
                DingUserInfo dingUserInfo = iterator.next();
@@ -142,7 +144,6 @@
            }
            log.info("dinglistEnd----->{}", dingUsers);
            ArrayList<UmsAdminRoleRelation> relations = new ArrayList<>();
//        log.info(TAG + " elapsed time:" + timer.interval());
            for (DingUserInfo dingUserInfo : dingUsers) {
@@ -158,7 +159,6 @@
                }
                //code
                //accountId
                log.info("员工账户id{}", dingUserInfo.getAccountId());
                user.setAccountId(dingUserInfo.getAccountId());
                //头像
                user.setIcon(dingUserInfo.getGovEmpAvatar());
@@ -177,30 +177,30 @@
                //状态为停用(不可用状态)点击登录后才能使用
                user.setStatus(1);
                umsAdminService.save(user);
//            //员工信息,关联组织
//            UmsDepartManage departManage = new UmsDepartManage();
//            departManage.setDepartId(dingUserInfo.getOrgId());
//            departManage.setIsLeader(0);
//            departManage.setUserId(dingUserInfo.getUserId());
//            departManageService.saveOrUpdate(departManage);
//            //角色信息
//            List<String> roleCode = dingUserInfo.getRoleCodeList();
//            if (CollectionUtils.isNotEmpty(roleCode)) {
//                List<UmsRole> roleList = roleService.getRoleListByCodes(roleCode);
//                roleList.forEach(item -> {
//                    UmsAdminRoleRelation relation = new UmsAdminRoleRelation();
//                    relation.setAdminId(dingUserInfo.getUserId());
//                    relation.setRoleId(item.getId());
//                    relations.add(relation);
//                });
//            }
//        }
//        if (CollUtil.isNotEmpty(relations)) {
//            umsAdminRoleRelationService.saveBatch(relations, IService.DEFAULT_BATCH_SIZE);
                //员工信息,关联组织
                UmsDepartManage departManage = new UmsDepartManage();
                departManage.setDepartId(dingUserInfo.getOrgId());
                departManage.setIsLeader(0);
                departManage.setUserId(dingUserInfo.getUserId());
                departManageService.saveOrUpdate(departManage);
                //角色信息
                List<String> roleCode = dingUserInfo.getRoleCodeList();
                if (CollectionUtils.isNotEmpty(roleCode)) {
                    List<UmsRole> roleList = roleService.getRoleListByCodes(roleCode);
                    roleList.forEach(item -> {
                        UmsAdminRoleRelation relation = new UmsAdminRoleRelation();
                        relation.setAdminId(dingUserInfo.getUserId());
                        relation.setRoleId(item.getId());
                        relations.add(relation);
                    });
                }
            }
            if (CollUtil.isNotEmpty(relations)) {
                umsAdminRoleRelationService.saveBatch(relations, IService.DEFAULT_BATCH_SIZE);
            }
            log.info("同步任务结束");
//        log.info(TAG + "update user size " + dingList.size());
//        getEmployeeAvatar();
            log.info(TAG + "update user size " + dingList.size());
            getEmployeeAvatar();
        }
    }
ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java
New file
@@ -0,0 +1,83 @@
package com.ycl.timer;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ycl.common.dingding.DingCommon;
import com.ycl.entity.message.DingMessage;
import com.ycl.mapper.message.DingMessageMapper;
import com.ycl.service.message.IDingMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
@Slf4j
@Component
public class SendDingMsg implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private DingMessageMapper dingMessageMapper;
    @Autowired
    private DingCommon dingCommon;
    @Autowired
    private IDingMessageService dingMessageService;
    @Value("${spring.profiles.active}")
    private String env;
    public final static Short STATE_READY = 0;
    public final static Short STATE_SUCCESS = 1;
    public final static Short STATE_FAILURE = 2;
    public final static Short SCAN_READY = 0;
    public final static Short SCAN_FINISH = 1;
    @Scheduled(cron = "0 0/2 * * * ?")
    public void runAction() {
        if ("online".equals(env)) {
            QueryWrapper<DingMessage> wrapper = new QueryWrapper<>();
            wrapper.eq("state", STATE_READY);
            wrapper.eq("if_scan", SCAN_READY);
            List<DingMessage> dingMessages = dingMessageMapper.selectList(wrapper);
            if (CollectionUtils.isNotEmpty(dingMessages)) {
                int size = dingMessages.size();
                log.info("有待发送消息{}条", size);
                for (DingMessage dingMessage : dingMessages) {
                    String baseCaseCode = dingMessage.getBaseCaseCode();
                    Long accountId = dingMessage.getAccountId();
                    Long messageId = dingMessage.getId();
                    String text = "遂昌云执法:有待处理的任务\n" +
                            "·您有1条待处理事件。事件编号:\n" +
                            baseCaseCode;
                    String title = "您有一条工作通知";
                    try {
                        dingMessage.setIfScan(SCAN_FINISH);
                        dingMessage.setSendTime(new Date());
                        dingCommon.sendDingMsgStr(accountId + "", text);
                        log.info("发送一条工作通知,消息id{}", messageId);
                        dingMessage.setState(STATE_SUCCESS);
                    } catch (Exception e) {
                        log.error("发送钉钉消息出现异常,消息id{}", messageId, e);
                        dingMessage.setState(STATE_FAILURE);
                        size--;
                    }
                }
                dingMessageService.updateBatchById(dingMessages);
                log.info("发送成功{}条,失败{}条", size, dingMessages.size() - size);
            }
        }
    }
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent() == null) {
//            runAction();
        }
    }
}
ycl-platform/src/main/resources/application-online.yml
@@ -74,12 +74,6 @@
  passWord: a12345677
  ip: 10.10.10.10
DH:
  web_url: http://172.28.194.185:8281
  port: 8281
  userName: zfgy
  passWord: zfj12345
aliyun:
  oss:
    endpoint: http://oss-cn-zjls-lszwy-d01-a.ops.zjlscloud.com
@@ -87,6 +81,12 @@
    keySecret: tRk39S6B1kSGARRdS4DF6jxr5nBYj5
    bucketName: zhzfptoss
DH:
  web_url: http://172.28.194.185:8281
  port: 8281
  userName: zfgy
  passWord: zfj12345
#专有钉钉参数
zzding :
  app-key : sczhzfpt-81R3ErbU00G4VoXaEBruq
ycl-platform/src/main/resources/logback-spring.xml
@@ -122,5 +122,18 @@
        </root>
    </springProfile>
    <springProfile name="online">
        <!--打印SQL-->
        <logger name="java.sql.Connection" level="ERROR" />
        <logger name="java.sql.Statement" level="ERROR" />
        <logger name="java.sql.PreparedStatement" level="ERROR" />
        <logger name="com.ycl" level="debug" >
            <appender-ref ref="normalLog" />
            <appender-ref ref="errorLog" />
        </logger>
        <root level="info">
            <appender-ref ref="Console" />
        </root>
    </springProfile>
</configuration>