From f11afb84d32ed6d2b582ed193db2f9805cd365ec Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期一, 18 十二月 2023 15:13:32 +0800 Subject: [PATCH] 工作通知定时任务 --- ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java | 56 ++++---- ycl-platform/src/main/resources/logback-spring.xml | 13 ++ ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java | 19 +++ ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java | 15 ++ ycl-platform/src/main/resources/application-online.yml | 13 + ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java | 19 +- ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java | 42 ++++++ ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java | 10 + ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java | 83 +++++++++++++ ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java | 83 +++++++++++++ 10 files changed, 310 insertions(+), 43 deletions(-) diff --git a/ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java b/ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java index 9898fd2..471af60 100644 --- a/ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java +++ b/ycl-platform/src/main/java/com/ycl/common/dingding/DingCommon.java @@ -313,7 +313,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("寮�濮嬭ˉ鍏卆ccountId"); JSONArray users = getAccountId(employeeCodes); @@ -331,10 +340,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 +385,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"); diff --git a/ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java b/ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java new file mode 100644 index 0000000..e4fad7b --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/entity/message/DingMessage.java @@ -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; + + /** + * 鎺ユ敹鑰卛d + */ + @TableField("account_id") + @ApiModelProperty(value = "鎺ユ敹鑰卛d") + 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("body") + @ApiModelProperty(value = "鍙戦�佹椂闂�") + private Date sendTime; + + + /** + * 鏄惁鎵弿锛�0鏈壂鎻�-1宸叉壂鎻� + */ + @TableField("status") + @ApiModelProperty(value = "鏄惁鎵弿锛�0鏈壂鎻�-1宸叉壂鎻�") + private Short if_scan; + +} diff --git a/ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java b/ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java new file mode 100644 index 0000000..5e133f9 --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/mapper/message/DingMessageMapper.java @@ -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> { + +} diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java index ce83cb6..c32af93 100644 --- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/IDispatchHandleServiceImpl.java +++ b/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; } diff --git a/ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java b/ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java new file mode 100644 index 0000000..2ddca36 --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/service/message/IDingMessageService.java @@ -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> { +} diff --git a/ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java new file mode 100644 index 0000000..e10e217 --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/service/message/impl/DingMessageServiceImpl.java @@ -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 { + +} diff --git a/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java b/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java index 0491949..453f87a 100644 --- a/ycl-platform/src/main/java/com/ycl/timer/GetDingUserOrgTimer.java +++ b/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(); } } diff --git a/ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java b/ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java new file mode 100644 index 0000000..157b992 --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/timer/SendDingMsg.java @@ -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.setIf_scan(SCAN_FINISH); + dingMessage.setSendTime(new Date()); + dingCommon.sendDingMsgStr(accountId + "", text); + log.info("鍙戦�佷竴鏉″伐浣滈�氱煡锛屾秷鎭痠d{}", 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(); + } + } +} diff --git a/ycl-platform/src/main/resources/application-online.yml b/ycl-platform/src/main/resources/application-online.yml index e1181ec..3c816a9 100644 --- a/ycl-platform/src/main/resources/application-online.yml +++ b/ycl-platform/src/main/resources/application-online.yml @@ -79,10 +79,15 @@ keySecret: tRk39S6B1kSGARRdS4DF6jxr5nBYj5 bucketName: zhzfptoss +DH: + web_url: http://172.28.194.185:8281 + port: 8281 + userName: zfgy + passWord: zfj12345 #涓撴湁閽夐拤鍙傛暟 zzding : - app-key : SC_ZHZF-IC5g2YiRDW8tug1DfAfiui - app-secret : 39RIHFOKd8fUeeW9T7CdBcwEqA6dMKx5d3686B6P - domain-name : openplatform.dg-work.cn + app-key : sczhzfpt-81R3ErbU00G4VoXaEBruq + app-secret : 0GPY3aQDL3l38J7p6K37DV6BCXIOLzrynU71Br36 + domain-name : openplatform-pro.ding.zj.gov.cn protocal : https - tenant-id : 50645661 \ No newline at end of file + tenant-id : 196729 \ No newline at end of file diff --git a/ycl-platform/src/main/resources/logback-spring.xml b/ycl-platform/src/main/resources/logback-spring.xml index b1c2d12..20741e9 100644 --- a/ycl-platform/src/main/resources/logback-spring.xml +++ b/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> \ No newline at end of file -- Gitblit v1.8.0