From d5420a8fef6d680e5bdce86b36cb8e90d7e22419 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期六, 16 八月 2025 09:49:25 +0800 Subject: [PATCH] 安灯发起-工单-飞书发送消息(一级响应/二级响应/三级响应) 飞书安灯消息模板相关代码 --- src/main/java/org/jeecg/modules/andon/service/impl/AndonButtonConfigServiceImpl.java | 11 src/main/java/org/jeecg/modules/andon/controller/AndonResponseConfigController.java | 283 +++++---- src/main/java/org/jeecg/modules/feishu/service/FeishuUserService.java | 635 +++++++++++++++++++++ src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java | 186 ++++++ src/main/java/org/jeecg/modules/andon/service/IAndonOrderService.java | 8 src/main/java/org/jeecg/modules/mes/entity/MessageResponse.java | 12 src/main/java/org/jeecg/modules/andon/entity/AndonResponseConfig.java | 3 src/main/java/org/jeecg/modules/andon/service/IAndonResponseConfigService.java | 18 src/main/java/org/jeecg/modules/andon/entity/AndonButtonConfig.java | 15 src/main/java/org/jeecg/modules/andon/controller/AndonButtonConfigController.java | 36 /dev/null | 327 ---------- src/main/java/org/jeecg/modules/andon/dto/AndonButtonDTO.java | 80 ++ src/main/java/org/jeecg/modules/andon/mapper/xml/AndonButtonConfigMapper.xml | 20 src/main/java/org/jeecg/modules/andon/mapper/AndonButtonConfigMapper.java | 9 src/main/java/org/jeecg/modules/andon/mapper/xml/AndonResponseConfigMapper.xml | 12 src/main/java/org/jeecg/modules/andon/controller/AndonOrderController.java | 31 src/main/resources/application-dev.yml | 5 src/main/java/org/jeecg/modules/andon/service/IAndonButtonConfigService.java | 10 src/main/java/org/jeecg/modules/feishu/job/FeishuSyncTask.java | 5 src/main/java/org/jeecg/modules/andon/service/impl/AndonOrderServiceImpl.java | 41 + src/main/java/org/jeecg/modules/andon/mapper/AndonResponseConfigMapper.java | 4 21 files changed, 1,251 insertions(+), 500 deletions(-) diff --git a/src/main/java/org/jeecg/modules/andon/controller/AndonButtonConfigController.java b/src/main/java/org/jeecg/modules/andon/controller/AndonButtonConfigController.java index a589c4b..633af0f 100644 --- a/src/main/java/org/jeecg/modules/andon/controller/AndonButtonConfigController.java +++ b/src/main/java/org/jeecg/modules/andon/controller/AndonButtonConfigController.java @@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -12,7 +13,9 @@ import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.query.QueryGenerator; import org.jeecg.common.system.vo.LoginUser; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonButtonConfig; +import org.jeecg.modules.andon.entity.AndonOrder; import org.jeecg.modules.andon.service.IAndonButtonConfigService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -21,6 +24,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Arrays; +import java.util.List; /** * @Description: 瀹夌伅鎸夐挳閰嶇疆 @@ -61,34 +65,22 @@ /** - * APP鍒嗛〉鍒楄〃鏌ヨ + * APP瀹夌伅鎸夐挳鍒楄〃鏌ヨ * - * @param andonButtonConfig - * @param pageNo - * @param pageSize - * @param req + * @param factoryId * @return */ @ApiOperation(value="瀹夌伅鎸夐挳閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ", notes="瀹夌伅鎸夐挳閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ") - @GetMapping(value = "/App/list") - public Result<IPage<AndonButtonConfig>> queryPageAppList(AndonButtonConfig andonButtonConfig, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { - QueryWrapper<AndonButtonConfig> queryWrapper = QueryGenerator.initQueryWrapper(andonButtonConfig, req.getParameterMap()); - - // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛 - LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - if (sysUser != null) { - // 澧炲姞閫氳繃绯荤粺鐧诲綍浜鸿繘琛岃繃婊� - queryWrapper.eq("create_by", sysUser.getUsername()); - } - - Page<AndonButtonConfig> page = new Page<AndonButtonConfig>(pageNo, pageSize); - IPage<AndonButtonConfig> pageList = andonButtonConfigService.page(page, queryWrapper); - return Result.OK(pageList); + @GetMapping(value = "/queryUserAndonButtonList") + public Result<List<AndonButtonDTO>> queryUserAndonButtonList(@RequestParam("factoryId") String factoryId) { + List<AndonButtonDTO> list = andonButtonConfigService.queryUserAndonButtonList(factoryId); + return Result.OK(list); } + + + + /** * 娣诲姞 * diff --git a/src/main/java/org/jeecg/modules/andon/controller/AndonOrderController.java b/src/main/java/org/jeecg/modules/andon/controller/AndonOrderController.java index ae59140..23ca85f 100644 --- a/src/main/java/org/jeecg/modules/andon/controller/AndonOrderController.java +++ b/src/main/java/org/jeecg/modules/andon/controller/AndonOrderController.java @@ -56,20 +56,23 @@ return Result.OK(pageList); } - /** - * 娣诲姞 - * - * @param andonOrder - * @return - */ - @AutoLog(value = "瀹夌伅宸ュ崟-娣诲姞") - @ApiOperation(value="瀹夌伅宸ュ崟-娣诲姞", notes="瀹夌伅宸ュ崟-娣诲姞") - //@RequiresPermissions("org.jeecg.modules:andon_order:add") - @PostMapping(value = "/add") - public Result<String> add(@RequestBody AndonOrder andonOrder) { - andonOrderService.save(andonOrder); - return Result.OK("娣诲姞鎴愬姛锛�"); - } + + + /** + * 娣诲姞 + * + * @param andonOrder + * @return + */ + @AutoLog(value = "瀹夌伅宸ュ崟-娣诲姞") + @ApiOperation(value="瀹夌伅宸ュ崟-娣诲姞", notes="瀹夌伅宸ュ崟-娣诲姞") + @PostMapping(value = "/add") + public Result<String> add(@RequestBody AndonOrder andonOrder) { + andonOrderService.save(andonOrder); + return Result.OK("娣诲姞鎴愬姛锛�"); + } + + /** * 缂栬緫 diff --git a/src/main/java/org/jeecg/modules/andon/controller/AndonResponseConfigController.java b/src/main/java/org/jeecg/modules/andon/controller/AndonResponseConfigController.java index 1798af8..63510ae 100644 --- a/src/main/java/org/jeecg/modules/andon/controller/AndonResponseConfigController.java +++ b/src/main/java/org/jeecg/modules/andon/controller/AndonResponseConfigController.java @@ -10,6 +10,7 @@ import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.system.base.controller.JeecgController; import org.jeecg.common.system.query.QueryGenerator; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonResponseConfig; import org.jeecg.modules.andon.service.IAndonResponseConfigService; import org.springframework.beans.factory.annotation.Autowired; @@ -19,143 +20,179 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Arrays; +import java.util.List; /** -* @Description: 瀹夌伅鍝嶅簲閰嶇疆 -* @Author: jeecg-boot -* @Date: 2025-07-10 -* @Version: V1.0 -*/ -@Api(tags="瀹夌伅鍝嶅簲閰嶇疆") + * @Description: 瀹夌伅鍝嶅簲閰嶇疆 + * @Author: jeecg-boot + * @Date: 2025-07-10 + * @Version: V1.0 + */ +@Api(tags = "瀹夌伅鍝嶅簲閰嶇疆") @RestController @RequestMapping("/andonresponseconfig/andonResponseConfig") @Slf4j public class AndonResponseConfigController extends JeecgController<AndonResponseConfig, IAndonResponseConfigService> { - @Autowired - private IAndonResponseConfigService andonResponseConfigService; + @Autowired + private IAndonResponseConfigService andonResponseConfigService; - /** - * 鍒嗛〉鍒楄〃鏌ヨ - * - * @param andonResponseConfig - * @param pageNo - * @param pageSize - * @param req - * @return - */ - //@AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ", notes="瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ") - @GetMapping(value = "/list") - public Result<IPage<AndonResponseConfig>> queryPageList(AndonResponseConfig andonResponseConfig, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { - QueryWrapper<AndonResponseConfig> queryWrapper = QueryGenerator.initQueryWrapper(andonResponseConfig, req.getParameterMap()); - Page<AndonResponseConfig> page = new Page<AndonResponseConfig>(pageNo, pageSize); - IPage<AndonResponseConfig> pageList = andonResponseConfigService.page(page, queryWrapper); - return Result.OK(pageList); - } + /** + * 鍒嗛〉鍒楄〃鏌ヨ + * + * @param andonResponseConfig + * @param pageNo + * @param pageSize + * @param req + * @return + */ + //@AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ", notes = "瀹夌伅鍝嶅簲閰嶇疆-鍒嗛〉鍒楄〃鏌ヨ") + @GetMapping(value = "/list") + public Result<IPage<AndonResponseConfig>> queryPageList(AndonResponseConfig andonResponseConfig, + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { + QueryWrapper<AndonResponseConfig> queryWrapper = QueryGenerator.initQueryWrapper(andonResponseConfig, req.getParameterMap()); + Page<AndonResponseConfig> page = new Page<AndonResponseConfig>(pageNo, pageSize); + IPage<AndonResponseConfig> pageList = andonResponseConfigService.page(page, queryWrapper); + return Result.OK(pageList); + } - /** - * 娣诲姞 - * - * @param andonResponseConfig - * @return - */ - @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-娣诲姞") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-娣诲姞", notes="瀹夌伅鍝嶅簲閰嶇疆-娣诲姞") - //@RequiresPermissions("org.jeecg.modules:andon_response_config:add") - @PostMapping(value = "/add") - public Result<String> add(@RequestBody AndonResponseConfig andonResponseConfig) { - andonResponseConfigService.save(andonResponseConfig); - return Result.OK("娣诲姞鎴愬姛锛�"); - } - /** - * 缂栬緫 - * - * @param andonResponseConfig - * @return - */ - @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-缂栬緫") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-缂栬緫", notes="瀹夌伅鍝嶅簲閰嶇疆-缂栬緫") - //@RequiresPermissions("org.jeecg.modules:andon_response_config:edit") - @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) - public Result<String> edit(@RequestBody AndonResponseConfig andonResponseConfig) { - andonResponseConfigService.updateById(andonResponseConfig); - return Result.OK("缂栬緫鎴愬姛!"); - } + /** + * 鍙戦�佸畨鐏秷鎭� + * + * @param andonButtonDTO + * @return + */ + @AutoLog(value = "瀹夌伅宸ュ崟-鍙戦�侀涔︽秷鎭�") + @ApiOperation(value = "瀹夌伅宸ュ崟-鍙戦�侀涔︽秷鎭�", notes = "瀹夌伅宸ュ崟-鍙戦�侀涔︽秷鎭�") + @PostMapping(value = "/sendMessage") + public Result<String> sendMessage(@RequestBody AndonButtonDTO andonButtonDTO) { + try { + andonButtonDTO.setBlinkingFlag(1); + // 璋冪敤鏈嶅姟灞傚鐞嗕笟鍔¢�昏緫 + andonResponseConfigService.sendAndonNotification(andonButtonDTO); + return Result.OK("娣诲姞鎴愬姛锛�"); + } catch (Exception e) { + log.error("瀹夌伅宸ュ崟[{}]椋炰功閫氱煡鍙戦�佸け璐�", andonButtonDTO.getId(), e); + return Result.error("鍙戦�佹秷鎭け璐�: " + e.getMessage()); + } + } - /** - * 閫氳繃id鍒犻櫎 - * - * @param id - * @return - */ - @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎", notes="瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎") - //@RequiresPermissions("org.jeecg.modules:andon_response_config:delete") - @DeleteMapping(value = "/delete") - public Result<String> delete(@RequestParam(name="id",required=true) String id) { - andonResponseConfigService.removeById(id); - return Result.OK("鍒犻櫎鎴愬姛!"); - } + /** + * 娣诲姞 + * + * @param andonResponseConfig + * @return + */ + @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-娣诲姞") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-娣诲姞", notes = "瀹夌伅鍝嶅簲閰嶇疆-娣诲姞") + @PostMapping(value = "/add") + public Result<String> add(@RequestBody AndonResponseConfig andonResponseConfig) { + andonResponseConfigService.save(andonResponseConfig); + return Result.OK("娣诲姞鎴愬姛锛�"); + } - /** - * 鎵归噺鍒犻櫎 - * - * @param ids - * @return - */ - @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎", notes="瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎") - //@RequiresPermissions("org.jeecg.modules:andon_response_config:deleteBatch") - @DeleteMapping(value = "/deleteBatch") - public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) { - this.andonResponseConfigService.removeByIds(Arrays.asList(ids.split(","))); - return Result.OK("鎵归噺鍒犻櫎鎴愬姛!"); - } + /** + * 缂栬緫 + * + * @param andonResponseConfig + * @return + */ + @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-缂栬緫") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-缂栬緫", notes = "瀹夌伅鍝嶅簲閰嶇疆-缂栬緫") + //@RequiresPermissions("org.jeecg.modules:andon_response_config:edit") + @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST}) + public Result<String> edit(@RequestBody AndonResponseConfig andonResponseConfig) { + andonResponseConfigService.updateById(andonResponseConfig); + return Result.OK("缂栬緫鎴愬姛!"); + } - /** - * 閫氳繃id鏌ヨ - * - * @param id - * @return - */ - //@AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ") - @ApiOperation(value="瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ", notes="瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ") - @GetMapping(value = "/queryById") - public Result<AndonResponseConfig> queryById(@RequestParam(name="id",required=true) String id) { - AndonResponseConfig andonResponseConfig = andonResponseConfigService.getById(id); - if(andonResponseConfig==null) { - return Result.error("鏈壘鍒板搴旀暟鎹�"); - } - return Result.OK(andonResponseConfig); - } + /** + * 閫氳繃id鍒犻櫎 + * + * @param id + * @return + */ + @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎", notes = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鍒犻櫎") + //@RequiresPermissions("org.jeecg.modules:andon_response_config:delete") + @DeleteMapping(value = "/delete") + public Result<String> delete(@RequestParam(name = "id", required = true) String id) { + andonResponseConfigService.removeById(id); + return Result.OK("鍒犻櫎鎴愬姛!"); + } - /** - * 瀵煎嚭excel - * - * @param request - * @param andonResponseConfig - */ - //@RequiresPermissions("org.jeecg.modules:andon_response_config:exportXls") - @RequestMapping(value = "/exportXls") - public ModelAndView exportXls(HttpServletRequest request, AndonResponseConfig andonResponseConfig) { - return super.exportXls(request, andonResponseConfig, AndonResponseConfig.class, "瀹夌伅鍝嶅簲閰嶇疆"); - } + /** + * 鎵归噺鍒犻櫎 + * + * @param ids + * @return + */ + @AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎", notes = "瀹夌伅鍝嶅簲閰嶇疆-鎵归噺鍒犻櫎") + //@RequiresPermissions("org.jeecg.modules:andon_response_config:deleteBatch") + @DeleteMapping(value = "/deleteBatch") + public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) { + this.andonResponseConfigService.removeByIds(Arrays.asList(ids.split(","))); + return Result.OK("鎵归噺鍒犻櫎鎴愬姛!"); + } - /** + /** + * 閫氳繃id鏌ヨ + * + * @param id + * @return + */ + //@AutoLog(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ") + @ApiOperation(value = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ", notes = "瀹夌伅鍝嶅簲閰嶇疆-閫氳繃id鏌ヨ") + @GetMapping(value = "/queryById") + public Result<AndonResponseConfig> queryById(@RequestParam(name = "id", required = true) String id) { + AndonResponseConfig andonResponseConfig = andonResponseConfigService.getById(id); + if (andonResponseConfig == null) { + return Result.error("鏈壘鍒板搴旀暟鎹�"); + } + return Result.OK(andonResponseConfig); + } + + /** + * 瀵煎嚭excel + * + * @param request + * @param andonResponseConfig + */ + //@RequiresPermissions("org.jeecg.modules:andon_response_config:exportXls") + @RequestMapping(value = "/exportXls") + public ModelAndView exportXls(HttpServletRequest request, AndonResponseConfig andonResponseConfig) { + return super.exportXls(request, andonResponseConfig, AndonResponseConfig.class, "瀹夌伅鍝嶅簲閰嶇疆"); + } + + /** * 閫氳繃excel瀵煎叆鏁版嵁 - * - * @param request - * @param response - * @return - */ - //@RequiresPermissions("andon_response_config:importExcel") - @RequestMapping(value = "/importExcel", method = RequestMethod.POST) - public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { - return super.importExcel(request, response, AndonResponseConfig.class); - } + * + * @param request + * @param response + * @return + */ + //@RequiresPermissions("andon_response_config:importExcel") + @RequestMapping(value = "/importExcel", method = RequestMethod.POST) + public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { + return super.importExcel(request, response, AndonResponseConfig.class); + } + + + /** + * APP瀹夌伅鎸夐挳鍒楄〃鏌ヨ + * + * @param factoryId + * @return + */ + @ApiOperation(value = "瀹夌伅鎸夐挳閰嶇疆-鍒楄〃鏌ヨ", notes = "瀹夌伅鎸夐挳閰嶇疆-鍒楄〃鏌ヨ") + @GetMapping(value = "/queryAndonButtonList") + public Result<List<AndonButtonDTO>> queryAndonButtonList(@RequestParam("factoryId") String factoryId) { + List<AndonButtonDTO> list = andonResponseConfigService.queryAndonButtonList(factoryId); + return Result.OK(list); + } } diff --git a/src/main/java/org/jeecg/modules/andon/dto/AndonButtonDTO.java b/src/main/java/org/jeecg/modules/andon/dto/AndonButtonDTO.java new file mode 100644 index 0000000..8c82ac8 --- /dev/null +++ b/src/main/java/org/jeecg/modules/andon/dto/AndonButtonDTO.java @@ -0,0 +1,80 @@ +package org.jeecg.modules.andon.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.jeecg.common.aspect.annotation.Dict; +import org.jeecgframework.poi.excel.annotation.Excel; + +@Data +public class AndonButtonDTO { + /** 鍝嶅簲ID */ + @ApiModelProperty(value = "鍝嶅簲ID") + private String id; + /** 鎸夐挳ID */ + @ApiModelProperty(value = " 鎸夐挳ID ") + private String buttonId; + /**瀹夌伅鍚嶇О*/ + @ApiModelProperty(value = "瀹夌伅鍚嶇О") + private String buttonName; + /**瀹夌伅缂栫爜*/ + @ApiModelProperty(value = "瀹夌伅缂栫爜") + private String buttonCode; + /** 涓�绾у搷搴斾汉 */ + @ApiModelProperty(value = "涓�绾у搷搴斾汉") + private String responder; + + + @ApiModelProperty(value = "浜岀骇鍝嶅簲浜�") + private String secondResponder; + /**浜х嚎鍚嶇О*/ + @ApiModelProperty(value = "浜х嚎鍚嶇О") + private String factoryName; + + /**浜х嚎鍚嶇О*/ + @ApiModelProperty(value = "宸ュ巶鍚嶇О") + private String parentFactoryName; + + /**涓�绾у搷搴旀椂闀�*/ + @ApiModelProperty(value = "涓�绾у搷搴旀椂闀�") + private Integer upgradeResponseDuration; + + + + /**浜岀骇鍝嶅簲鏃堕暱*/ + @ApiModelProperty(value = "浜岀骇鍝嶅簲鏃堕暱") + private Integer secondUpgradeResponseDuration; + + /**涓夌骇绾у搷搴旀椂闀�*/ + @ApiModelProperty(value = "涓夌骇鍝嶅簲鏃堕暱") + private Integer thirdUpgradeResponseDuration; + + /** + * 鏄惁闂儊 + * 瀵瑰簲鏁版嵁搴撹〃涓� is_blinking 瀛楁锛堝ぇ浜�0 鏈夊緟澶勭悊鐨勫伐鍗曢棯锛岀浉鍙嶄笉闂儊锛� + */ + @ApiModelProperty(value = "鏍囪瘑闂儊") + private Integer blinkingFlag; + + @ApiModelProperty(value = "涓�绾у搷搴斾汉openId") + private String responderOpenId; + + @ApiModelProperty(value = "浜岀骇鍝嶅簲浜簅penId") + private String secondResponderOpenId; + + @ApiModelProperty(value = "涓夌骇鍝嶅簲浜簅penId") + private String thirdResponderOpenId; + + + + @ApiModelProperty(value = "涓夌骇鍝嶅簲浜�") + private String thirdResponder; + + + + @ApiModelProperty(value = "宸ュ崟ID") + private String orderIds; + + @ApiModelProperty(value = "宸ュ崟鐘舵��") + private String orderStatus; + +} diff --git a/src/main/java/org/jeecg/modules/andon/entity/AndonButtonConfig.java b/src/main/java/org/jeecg/modules/andon/entity/AndonButtonConfig.java index 48eeeee..66cbd14 100644 --- a/src/main/java/org/jeecg/modules/andon/entity/AndonButtonConfig.java +++ b/src/main/java/org/jeecg/modules/andon/entity/AndonButtonConfig.java @@ -1,12 +1,10 @@ package org.jeecg.modules.andon.entity; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableLogic; -import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.*; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import liquibase.pro.packaged.B; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; @@ -89,4 +87,13 @@ @Excel(name = "澶囨敞", width = 15) @ApiModelProperty(value = "澶囨敞") private String remark; + + + /** + * 鏄惁闂儊 + * 瀵瑰簲鏁版嵁搴撹〃涓� is_blinking 瀛楁锛坱inyint绫诲瀷锛岄粯璁ゅ��0锛� + */ + @ApiModelProperty(value = "鏍囪瘑闂儊") + @TableField(exist = false) + private boolean blinkingFlag; } diff --git a/src/main/java/org/jeecg/modules/andon/entity/AndonResponseConfig.java b/src/main/java/org/jeecg/modules/andon/entity/AndonResponseConfig.java index 96dd37d..465add1 100644 --- a/src/main/java/org/jeecg/modules/andon/entity/AndonResponseConfig.java +++ b/src/main/java/org/jeecg/modules/andon/entity/AndonResponseConfig.java @@ -78,4 +78,7 @@ @Excel(name = "涓夌骇鍝嶅簲浜�(鍗囩骇涓ゆ)", width = 15) @ApiModelProperty(value = "涓夌骇鍝嶅簲浜�(鍗囩骇涓ゆ)") private String thirdResponder; + + + } diff --git a/src/main/java/org/jeecg/modules/andon/mapper/AndonButtonConfigMapper.java b/src/main/java/org/jeecg/modules/andon/mapper/AndonButtonConfigMapper.java index 2c87ddc..6812614 100644 --- a/src/main/java/org/jeecg/modules/andon/mapper/AndonButtonConfigMapper.java +++ b/src/main/java/org/jeecg/modules/andon/mapper/AndonButtonConfigMapper.java @@ -2,7 +2,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonButtonConfig; + +import java.util.List; /** * @Description: 瀹夌伅鎸夐挳閰嶇疆 @@ -12,4 +15,10 @@ */ public interface AndonButtonConfigMapper extends BaseMapper<AndonButtonConfig> { AndonButtonConfig getAndonButtonById(@Param("id") String id); + /** + * 瀹夌伅鎸夐挳鍒楄〃 + * @param factoryId + * @return + */ + List<AndonButtonDTO> queryUserAndonButtonList(String factoryId); } diff --git a/src/main/java/org/jeecg/modules/andon/mapper/AndonResponseConfigMapper.java b/src/main/java/org/jeecg/modules/andon/mapper/AndonResponseConfigMapper.java index 85c537d..6801fdb 100644 --- a/src/main/java/org/jeecg/modules/andon/mapper/AndonResponseConfigMapper.java +++ b/src/main/java/org/jeecg/modules/andon/mapper/AndonResponseConfigMapper.java @@ -2,7 +2,10 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonResponseConfig; + +import java.util.List; /** * @Description: 瀹夌伅鍝嶅簲閰嶇疆 @@ -12,4 +15,5 @@ */ public interface AndonResponseConfigMapper extends BaseMapper<AndonResponseConfig> { AndonResponseConfig getAndonResponseConfigByFactoryIdAndButtonId(@Param("factoryId") String factoryId, @Param("buttonId") String buttonId); + } diff --git a/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonButtonConfigMapper.xml b/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonButtonConfigMapper.xml index ec55989..128f32a 100644 --- a/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonButtonConfigMapper.xml +++ b/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonButtonConfigMapper.xml @@ -4,4 +4,24 @@ <select id="getAndonButtonById" resultType="org.jeecg.modules.andon.entity.AndonButtonConfig"> SELECT * FROM andon_button_config WHERE id = #{id} and del_flag = 0 and button_status = '鍚敤' </select> + <select id="queryUserAndonButtonList" resultType="org.jeecg.modules.andon.dto.AndonButtonDTO"> + select arc.id, + abc.id as button_id, + abc.button_name, + abc.button_code, + (select count(1) + from andon_order ao + where ao.button_id = arc.button_id + and ao.factory_id = arc.factory_id + and ao.order_status != '3') as blinking_flag, + STUFF((SELECT ',' + CAST(ao.id AS VARCHAR) + FROM andon_order ao + WHERE ao.button_id = arc.button_id + and ao.factory_id = arc.factory_id + FOR XML PATH('')), 1, 1, '') as order_ids + from andon_response_config arc + left join andon_button_config abc + on arc.button_id = abc.id + where arc.factory_id=#{factoryId}; + </select> </mapper> \ No newline at end of file diff --git a/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonResponseConfigMapper.xml b/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonResponseConfigMapper.xml index 2f95e67..650b483 100644 --- a/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonResponseConfigMapper.xml +++ b/src/main/java/org/jeecg/modules/andon/mapper/xml/AndonResponseConfigMapper.xml @@ -1,7 +1,13 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.jeecg.modules.andon.mapper.AndonResponseConfigMapper"> - <select id="getAndonResponseConfigByFactoryIdAndButtonId" resultType="org.jeecg.modules.andon.entity.AndonResponseConfig"> - SELECT * FROM andon_response_config WHERE factory_id = #{factoryId} AND button_id = #{buttonId} AND del_flag = 0 + <select id="getAndonResponseConfigByFactoryIdAndButtonId" + resultType="org.jeecg.modules.andon.entity.AndonResponseConfig"> + SELECT * + FROM andon_response_config + WHERE factory_id = #{factoryId} + AND button_id = #{buttonId} + AND del_flag = 0 </select> -</mapper> \ No newline at end of file + +</mapper> diff --git a/src/main/java/org/jeecg/modules/andon/service/IAndonButtonConfigService.java b/src/main/java/org/jeecg/modules/andon/service/IAndonButtonConfigService.java index a3bd9e1..b928375 100644 --- a/src/main/java/org/jeecg/modules/andon/service/IAndonButtonConfigService.java +++ b/src/main/java/org/jeecg/modules/andon/service/IAndonButtonConfigService.java @@ -1,7 +1,10 @@ package org.jeecg.modules.andon.service; import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonButtonConfig; + +import java.util.List; /** * @Description: 瀹夌伅鎸夐挳閰嶇疆 @@ -11,4 +14,11 @@ */ public interface IAndonButtonConfigService extends IService<AndonButtonConfig> { AndonButtonConfig getAndonButtonById(String id); + + /** + * 鏌ヨ鐢ㄦ埛瀹夌伅鎸夐挳鍒楄〃 + * @param factoryId + * @return + */ + List<AndonButtonDTO> queryUserAndonButtonList(String factoryId); } diff --git a/src/main/java/org/jeecg/modules/andon/service/IAndonOrderService.java b/src/main/java/org/jeecg/modules/andon/service/IAndonOrderService.java index a2cc301..08a9fa5 100644 --- a/src/main/java/org/jeecg/modules/andon/service/IAndonOrderService.java +++ b/src/main/java/org/jeecg/modules/andon/service/IAndonOrderService.java @@ -14,4 +14,12 @@ public interface IAndonOrderService extends IService<AndonOrder> { //宸插畬鎴愮姸鎬侀櫎澶� List<AndonOrder> getAndonOrdersExceptYWC(); + + /** + * 鑾峰彇宸ュ崟鐨勫垵濮嬪搷搴斾汉 + * @param andonOrder + * @return + */ + String getPrimaryResponder(AndonOrder andonOrder); + } diff --git a/src/main/java/org/jeecg/modules/andon/service/IAndonResponseConfigService.java b/src/main/java/org/jeecg/modules/andon/service/IAndonResponseConfigService.java index aaac967..253efbf 100644 --- a/src/main/java/org/jeecg/modules/andon/service/IAndonResponseConfigService.java +++ b/src/main/java/org/jeecg/modules/andon/service/IAndonResponseConfigService.java @@ -1,7 +1,10 @@ package org.jeecg.modules.andon.service; import com.baomidou.mybatisplus.extension.service.IService; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonResponseConfig; + +import java.util.List; /** * @Description: 瀹夌伅鍝嶅簲閰嶇疆 @@ -11,4 +14,19 @@ */ public interface IAndonResponseConfigService extends IService<AndonResponseConfig> { AndonResponseConfig getAndonResponseConfigByFactoryIdAndButtonId(String factoryId, String buttonId); + + /** + * 鏍规嵁宸ュ巶id鏌ヨ鎸夐挳鍒楄〃 + * @param factoryId 宸ュ巶id + * @return + */ + List<AndonButtonDTO> queryAndonButtonList(String factoryId); + + + /** + * 鍙戦�佸畨鐏�氱煡 + * @param andonButtonDTO 瀹夌伅鎸夐挳DTO + * @return 缁撴灉 + */ + void sendAndonNotification(AndonButtonDTO andonButtonDTO); } diff --git a/src/main/java/org/jeecg/modules/andon/service/impl/AndonButtonConfigServiceImpl.java b/src/main/java/org/jeecg/modules/andon/service/impl/AndonButtonConfigServiceImpl.java index 92a7933..e1ebd85 100644 --- a/src/main/java/org/jeecg/modules/andon/service/impl/AndonButtonConfigServiceImpl.java +++ b/src/main/java/org/jeecg/modules/andon/service/impl/AndonButtonConfigServiceImpl.java @@ -1,10 +1,14 @@ package org.jeecg.modules.andon.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.andon.dto.AndonButtonDTO; import org.jeecg.modules.andon.entity.AndonButtonConfig; import org.jeecg.modules.andon.mapper.AndonButtonConfigMapper; import org.jeecg.modules.andon.service.IAndonButtonConfigService; import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; /** * @Description: 瀹夌伅鎸夐挳閰嶇疆 @@ -19,4 +23,11 @@ public AndonButtonConfig getAndonButtonById(String id) { return baseMapper.getAndonButtonById(id); } + + @Override + public List<AndonButtonDTO> queryUserAndonButtonList(String factoryId) { + return baseMapper.queryUserAndonButtonList(factoryId); + } + + } diff --git a/src/main/java/org/jeecg/modules/andon/service/impl/AndonOrderServiceImpl.java b/src/main/java/org/jeecg/modules/andon/service/impl/AndonOrderServiceImpl.java index 1152cfd..e12effd 100644 --- a/src/main/java/org/jeecg/modules/andon/service/impl/AndonOrderServiceImpl.java +++ b/src/main/java/org/jeecg/modules/andon/service/impl/AndonOrderServiceImpl.java @@ -1,9 +1,16 @@ package org.jeecg.modules.andon.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.jeecg.modules.andon.entity.AndonResponseConfig; +import org.jeecg.modules.andon.mapper.AndonResponseConfigMapper; import org.jeecg.modules.andon.service.IAndonOrderService; import org.jeecg.modules.andon.entity.AndonOrder; import org.jeecg.modules.andon.mapper.AndonOrderMapper; +import org.jeecg.modules.feishu.service.FeishuUserService; +import org.jeecg.modules.system.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -11,14 +18,46 @@ /** * @Description: 瀹夌伅宸ュ崟 * @Author: jeecg-boot - * @Date: 2025-07-10 + * @Date: 2025-07-10 * @Version: V1.0 */ @Service public class AndonOrderServiceImpl extends ServiceImpl<AndonOrderMapper, AndonOrder> implements IAndonOrderService { + @Autowired + private FeishuUserService feishuService; + @Autowired + private ISysUserService sysUserService; + + @Autowired + private AndonResponseConfigMapper andonResponseConfigMapper; @Override public List<AndonOrder> getAndonOrdersExceptYWC() { return baseMapper.getAndonOrdersExceptYWC(); } + + @Override + public String getPrimaryResponder(AndonOrder andonOrder) { + // 1. 鏍¢獙蹇呰鍙傛暟 + if (StringUtils.isBlank(andonOrder.getFactoryId()) || StringUtils.isBlank(andonOrder.getButtonId())) { + + return null; + } + + // 2. 鏌ヨ鍝嶅簲浜洪厤缃紙鍋囪瀛樺湪鍝嶅簲浜洪厤缃疄浣撳拰Mapper锛� + // 鏋勫缓鏌ヨ鏉′欢锛氬尮閰嶄骇绾縄D銆佸畨鐏被鍨婭D锛屼笖閰嶇疆涓哄惎鐢ㄧ姸鎬� + QueryWrapper<AndonResponseConfig> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("factory_id", andonOrder.getFactoryId()) + .eq("button_id", andonOrder.getButtonId()) + .eq("status", 1) // 1琛ㄧず鍚敤鐘舵�� + .last("limit 1"); // 鍙彇涓�鏉℃湁鏁堥厤缃� + + // 3. 鎵ц鏌ヨ + AndonResponseConfig config = andonResponseConfigMapper.selectOne(queryWrapper); + if (config == null) { + return null; + } + return config.getFirsterResponder(); + } + } diff --git a/src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java b/src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java index 04db58b..c895470 100644 --- a/src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java +++ b/src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java @@ -1,22 +1,204 @@ package org.jeecg.modules.andon.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.lang.StringUtils; +import org.jeecg.modules.andon.dto.AndonButtonDTO; +import org.jeecg.modules.andon.entity.AndonButtonConfig; +import org.jeecg.modules.andon.entity.AndonOrder; import org.jeecg.modules.andon.entity.AndonResponseConfig; import org.jeecg.modules.andon.mapper.AndonResponseConfigMapper; +import org.jeecg.modules.andon.service.IAndonButtonConfigService; +import org.jeecg.modules.andon.service.IAndonOrderService; import org.jeecg.modules.andon.service.IAndonResponseConfigService; +import org.jeecg.modules.base.entity.Factory; +import org.jeecg.modules.base.service.IFactoryService; +import org.jeecg.modules.feishu.service.FeishuUserService; +import org.jeecg.modules.system.entity.SysUser; +import org.jeecg.modules.system.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; /** * @Description: 瀹夌伅鍝嶅簲閰嶇疆 * @Author: jeecg-boot - * @Date: 2025-07-10 + * @Date: 2025-07-10 * @Version: V1.0 */ @Service public class AndonResponseConfigServiceImpl extends ServiceImpl<AndonResponseConfigMapper, AndonResponseConfig> implements IAndonResponseConfigService { + @Autowired + private IFactoryService factoryService; + + @Autowired + private ISysUserService iSysUserService; + + @Autowired + private FeishuUserService feishuUserService; + @Autowired + private IAndonButtonConfigService andonButtonConfigService; + + @Autowired + private IAndonOrderService andonOrderService; @Override public AndonResponseConfig getAndonResponseConfigByFactoryIdAndButtonId(String factoryId, String buttonId) { - return baseMapper.getAndonResponseConfigByFactoryIdAndButtonId(factoryId,buttonId); + return baseMapper.getAndonResponseConfigByFactoryIdAndButtonId(factoryId, buttonId); } + + @Override + public List<AndonButtonDTO> queryAndonButtonList(String factoryId) { + return Collections.emptyList(); + } + + @Override + public void sendAndonNotification(AndonButtonDTO andonButtonDTO) { + /** + * 1. 楠岃瘉宸ュ崟鐘舵�� + */ + if (andonButtonDTO == null) { + log.warn("璇锋眰鍙傛暟涓虹┖"); + throw new IllegalArgumentException("璇锋眰鍙傛暟涓嶈兘涓虹┖"); + } + /** + * 2. 鑾峰彇鍝嶅簲閰嶇疆 + */ + AndonResponseConfig andonResponseConfig = this.getById(andonButtonDTO.getId()); + + AndonOrder andonOrder = andonOrderService.getById(andonButtonDTO.getOrderIds()); + if (andonOrder == null) { + log.warn("鏈壘鍒癐D涓篬{}]鐨勫畨鐏鍗�"); + throw new IllegalArgumentException("鏈壘鍒板搴旂殑瀹夌伅璁㈠崟"); + } + String orderStatus = andonOrder.getOrderStatus(); + andonButtonDTO.setOrderStatus(orderStatus); + if (andonResponseConfig == null) { + log.warn("鏈壘鍒癐D涓篬{}]鐨勫搷搴旈厤缃�"); + throw new IllegalArgumentException("鏈壘鍒板搴旂殑鍝嶅簲閰嶇疆"); + } + /** + * 3. 璁剧疆浜岀骇鍝嶅簲浜� + */ + String secondResponder = andonResponseConfig.getSecondResponder(); + if (StringUtils.isNotBlank(secondResponder)) { + andonButtonDTO.setSecondResponder(secondResponder); + } + + /** + * 4. 鑾峰彇宸ュ巶淇℃伅 + */ + + String factoryId = andonResponseConfig.getFactoryId(); + if (factoryId == null || factoryId.isEmpty()) { + log.warn("鍝嶅簲閰嶇疆[{}]鏈缃伐鍘侷D"); + throw new IllegalArgumentException("鍝嶅簲閰嶇疆鏈缃伐鍘備俊鎭�"); + } + + Factory factory = factoryService.getOne(new QueryWrapper<Factory>() + .eq("id", factoryId) + .eq("del_flag", 0)); + + if (factory == null) { + log.warn("鏈壘鍒癐D涓篬{}]鐨勫伐鍘�"); + throw new IllegalArgumentException("鏈壘鍒板搴旂殑宸ュ巶淇℃伅"); + } + + /** + * 鑾峰彇浜х嚎鍚嶇О + */ + String factoryName = factory.getFactoryName(); + andonButtonDTO.setFactoryName(factoryName); + /** + * 6. 璁剧疆宸ュ巶鍚嶇О + */ + String parentId = factory.getParentId(); + if (parentId != null && !parentId.isEmpty()) { + Factory parentFactory = factoryService.getOne(new QueryWrapper<Factory>() + .eq("id", parentId) + .eq("del_flag", 0)); + if (parentFactory != null) { + andonButtonDTO.setParentFactoryName(parentFactory.getFactoryName()); + } + } + /** + * 6. 鑾峰彇瀹夌伅鎸夐挳閰嶇疆 + */ + AndonButtonConfig andonButtonById = andonButtonConfigService.getAndonButtonById(andonButtonDTO.getButtonId()); + if (andonButtonById == null) { + log.warn("鏈壘鍒癐D涓篬{}]鐨勫畨鐏寜閽�"); + throw new IllegalArgumentException("鏈壘鍒板搴旂殑瀹夌伅鎸夐挳淇℃伅"); + } + /** + * 7. 璁剧疆鍝嶅簲鏃堕棿 + */ + Integer upgradeResponseDuration = andonButtonById.getUpgradeResponseDuration(); + andonButtonDTO.setUpgradeResponseDuration(upgradeResponseDuration); + + Integer secondUpgradeResponseDuration = andonButtonById.getSecondUpgradeResponseDuration(); + andonButtonDTO.setSecondUpgradeResponseDuration(secondUpgradeResponseDuration); + + /** + * 8. 鑾峰彇鍝嶅簲浜轰俊鎭� + */ + String firstResponder = andonResponseConfig.getFirsterResponder(); + String threeResponder = andonResponseConfig.getThirdResponder(); + SysUser thirdUser = iSysUserService.getUserByName(threeResponder); + SysUser userByName = iSysUserService.getUserByName(firstResponder); + SysUser secondUser = null; + + if (StringUtils.isNotBlank(secondResponder)) { + secondUser = iSysUserService.getUserByName(secondResponder); + } + /** + * 9. 楠岃瘉骞惰缃搷搴斾汉淇℃伅 + */ + + if (userByName == null) { + log.warn("鐢ㄦ埛[{}]鏈壘鍒帮紝鏃犳硶鍙戦�侀�氱煡"); + throw new IllegalArgumentException("鐢ㄦ埛[{}]鏈壘鍒帮紝鏃犳硶鍙戦�侀�氱煡"); + } + + if (secondUser == null && StringUtils.isNotBlank(secondResponder)) { + log.warn("鐢ㄦ埛[{}]鏈壘鍒帮紝鏃犳硶鍙戦�侀�氱煡"); + throw new IllegalArgumentException("鐢ㄦ埛[{}]鏈壘鍒帮紝鏃犳硶鍙戦�侀�氱煡"); + } + + if (threeResponder == null) { + StringUtils.isNotBlank(null); + } + // + /** + * 10. 璁剧疆鍝嶅簲浜虹浉鍏充俊鎭� + */ + + andonButtonDTO.setResponderOpenId(userByName.getOpenId()); + andonButtonDTO.setResponder(userByName.getRealname()); + log.warn("鐢ㄦ埛[{}]宸叉壘鍒帮紝寮�濮嬪彂閫侀�氱煡"); + + if (secondUser != null) { + andonButtonDTO.setSecondResponderOpenId(secondUser.getOpenId()); + andonButtonDTO.setSecondResponder(secondUser.getRealname()); + log.warn("鐢ㄦ埛[{}]宸叉壘鍒帮紝寮�濮嬪彂閫侀�氱煡"); + } + if (thirdUser != null) { + andonButtonDTO.setThirdResponderOpenId(thirdUser.getOpenId()); + andonButtonDTO.setThirdResponder(thirdUser.getRealname()); + log.warn("鐢ㄦ埛[{}]宸叉壘鍒帮紝寮�濮嬪彂閫侀�氱煡"); + } + + /** + * 11. 鍙戦�侀涔﹂�氱煡 + */ + if (StringUtils.isNotBlank(firstResponder)) { + String feishuAccessToken = feishuUserService.getFeishuAccessToken(); + feishuUserService.sendAndonNotification(feishuAccessToken, andonButtonDTO); + } else { + log.warn("宸ュ崟[{}]鏈壘鍒板搴斿搷搴斾汉锛屾棤娉曞彂閫侀�氱煡"); + } + } + + } diff --git a/src/main/java/org/jeecg/modules/mes/job/FeishuSyncTask.java b/src/main/java/org/jeecg/modules/feishu/job/FeishuSyncTask.java similarity index 88% rename from src/main/java/org/jeecg/modules/mes/job/FeishuSyncTask.java rename to src/main/java/org/jeecg/modules/feishu/job/FeishuSyncTask.java index 36e816a..eaa3bae 100644 --- a/src/main/java/org/jeecg/modules/mes/job/FeishuSyncTask.java +++ b/src/main/java/org/jeecg/modules/feishu/job/FeishuSyncTask.java @@ -1,7 +1,8 @@ -package org.jeecg.modules.mes.job; +package org.jeecg.modules.feishu.job; import lombok.extern.slf4j.Slf4j; +import org.jeecg.modules.feishu.service.FeishuUserService; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @@ -17,7 +18,7 @@ public class FeishuSyncTask implements Job { @Autowired - private org.jeecg.modules.mes.job.FeishuUserService feishuUserService; + private FeishuUserService feishuUserService; @Value("${feishu.sync.departmentId:0}") private String departmentId; diff --git a/src/main/java/org/jeecg/modules/feishu/service/FeishuUserService.java b/src/main/java/org/jeecg/modules/feishu/service/FeishuUserService.java new file mode 100644 index 0000000..92d6b09 --- /dev/null +++ b/src/main/java/org/jeecg/modules/feishu/service/FeishuUserService.java @@ -0,0 +1,635 @@ +package org.jeecg.modules.feishu.service; + +import com.alibaba.fastjson.JSONObject; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.util.PasswordUtil; +import org.jeecg.common.util.RestUtil; +import org.jeecg.common.util.oConvertUtils; +import org.jeecg.modules.andon.dto.AndonButtonDTO; +import org.jeecg.modules.mes.entity.FeishuUser; +import org.jeecg.modules.system.entity.SysUser; +import org.jeecg.modules.system.service.ISysUserService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +@Service +@Slf4j +public class FeishuUserService { + // 绫讳腑瀹氫箟妯℃澘甯搁噺锛堜究浜庣淮鎶わ級 + private static final String FIRST_LEVEL_TEMPLATE = "銆愬伐鑹哄畨鐏�慭n%s 路 %s 鍙戣捣浜嗗伐鑹哄畨鐏紝璇�%d鍒嗛挓鍐呭湪PDA涓婅繘琛屽搷搴斿鐞嗭紒锛侊紒"; + private static final String SECOND_LEVEL_TEMPLATE = "銆愬伐鑹哄畨鐏�慭n%s 路 %s 鍙戣捣鐨勫伐鑹哄畨鐏紝%s鏈湪%d鍒嗛挓鍐呭搷搴旓紝璇峰敖蹇潱淇冭繘琛屽搷搴斿鐞嗭紒锛侊紒"; + @Resource + private ISysUserService sysUserService; + + @Resource + private RestTemplate restTemplate; + + @Value("${feishu.appId:}") + private String appId; + + @Value("${feishu.appSecret:}") + private String appSecret; + + @Value("${feishu.url:}") + private String feishuUrl; + + // 瀹氭椂浠诲姟绾跨▼姹狅紙鏀寔澶氱骇鍝嶅簲璋冨害锛� + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(5); + private final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + + /** + * 鍚屾椋炰功閮ㄩ棬鐢ㄦ埛鍒扮郴缁熺敤鎴疯〃 + */ + public void syncFeishuDepartmentUsers(String departmentId) { + try { + log.info("寮�濮嬪悓姝ラ涔﹂儴闂ㄧ敤鎴凤紝閮ㄩ棬ID: {}", departmentId); + + // 1. 鑾峰彇椋炰功璁块棶浠ょ墝 + String accessToken = getFeishuAccessToken(); + if (oConvertUtils.isEmpty(accessToken)) { + log.error("鑾峰彇椋炰功璁块棶浠ょ墝澶辫触锛岀粓姝㈠悓姝ユ祦绋�"); + return; + } + + // 2. 鑾峰彇閮ㄩ棬涓嬬殑鐢ㄦ埛鍒楄〃 + List<FeishuUser> feishuUsers = getDepartmentUsers(accessToken, departmentId); + log.info("鑾峰彇鍒伴涔﹂儴闂ㄧ敤鎴锋暟閲�: {}", feishuUsers.size()); + + // 3. 鍚屾鍒扮郴缁熺敤鎴疯〃 + int successCount = 0; + int updateCount = 0; + int addCount = 0; + + for (FeishuUser feishuUser : feishuUsers) { + try { + boolean isUpdated = syncFeishuUserToSystem(feishuUser); + successCount++; + if (isUpdated) { + updateCount++; + } else { + addCount++; + } + } catch (Exception e) { + log.error("鍚屾椋炰功鐢ㄦ埛澶辫触锛岀敤鎴稩D: {}", feishuUser.getUserId(), e); + } + } + + log.info("椋炰功鐢ㄦ埛鍚屾瀹屾垚锛屾�诲鐞�: {}锛屾柊澧�: {}锛屾洿鏂�: {}", successCount, addCount, updateCount); + } catch (Exception e) { + log.error("鍚屾椋炰功閮ㄩ棬鐢ㄦ埛澶辫触锛岄儴闂↖D: {}", departmentId, e); + throw new RuntimeException("鍚屾椋炰功鐢ㄦ埛澶辫触: " + e.getMessage()); + } + } + + public String getFeishuAccessToken() { + try { + String url = feishuUrl + "open-apis/auth/v3/tenant_access_token/internal"; + + log.info("寮�濮嬭幏鍙栭涔﹁闂护鐗岋紝AppId: {}", + appId != null ? appId.substring(0, Math.min(appId.length(), 10)) + "..." : "null"); + + JSONObject params = new JSONObject(); + params.put("app_id", appId); + params.put("app_secret", appSecret); + + log.debug("鑾峰彇浠ょ墝璇锋眰鍙傛暟: {}", params.toJSONString()); + + JSONObject result = RestUtil.post(url, params); + + log.info("鑾峰彇椋炰功璁块棶浠ょ墝鍝嶅簲: {}", result != null ? result.toJSONString() : "null"); + + if (result != null && result.getInteger("code") == 0) { + String accessToken = result.getString("tenant_access_token"); + log.info("鎴愬姛鑾峰彇椋炰功璁块棶浠ょ墝锛屼护鐗岄暱搴�: {}", accessToken != null ? accessToken.length() : 0); + return accessToken; + } else { + log.error("鑾峰彇椋炰功璁块棶浠ょ墝澶辫触锛屽搷搴�: {}", result != null ? result.toJSONString() : "null"); + if (result != null) { + log.error("閿欒鐮�: {}, 閿欒淇℃伅: {}", result.getInteger("code"), result.getString("msg")); + } + return null; + } + } catch (Exception e) { + log.error("鑾峰彇椋炰功璁块棶浠ょ墝寮傚父", e); + return null; + } + } + + /** + * 鍙戦�佸畨鐏�氱煡娑堟伅锛堟敮鎸佷竴銆佷簩銆佷笁绾у搷搴旓級 + * 娴佺▼锛� + * 1. APP鐐瑰嚮鍙戦�佷竴绾у搷搴旓紙鍒濈骇鍝嶅簲锛� + * 2. 涓�绾у搷搴旀椂闀垮悗妫�鏌ョ姸鎬侊紝鏈鐞嗗垯鍙戦�佷簩绾� + * 3. 浜岀骇鍝嶅簲鏃堕暱鍚庢鏌ョ姸鎬侊紝鏈鐞嗗垯鍙戦�佷笁绾� + */ + public boolean sendAndonNotification(String accessToken, AndonButtonDTO andonOrde) { + try { + String currentTime = sdf.format(new Date()); + log.info("銆恵}銆戣Е鍙戜竴绾у搷搴旓紙鍒濈骇鍝嶅簲锛夛紝瀹夌伅ID: {}", currentTime, andonOrde.getId()); + + // 1. 鍙傛暟楠岃瘉 + if (!validateNotificationParams(andonOrde)) { + return false; + } + if (accessToken == null || accessToken.isEmpty()) { + log.error("璁块棶浠ょ墝涓虹┖锛屾棤娉曞彂閫佸畨鐏�氱煡"); + return false; + } + + // 2. 鍙戦�佷竴绾у搷搴旈�氱煡锛堝嵆鏃跺彂閫侊級 + boolean firstLevelResult = sendLevelNotification(accessToken, andonOrde, 1); + + // 3. 璋冨害浜岀骇鍝嶅簲閫氱煡锛堝欢杩熸椂闂�=涓�绾у搷搴旀椂闀匡級 + if (firstLevelResult) { + int secondDelay = andonOrde.getUpgradeResponseDuration(); + String secondTime = sdf.format(new Date(System.currentTimeMillis() + secondDelay * 60 * 1000L)); + log.info("銆恵}銆戜竴绾у搷搴旇皟搴︿簩绾ч�氱煡锛屽欢杩焮}鍒嗛挓锛岄璁″彂閫佹椂闂�: {}", + currentTime, secondDelay, secondTime); + scheduleNextLevelNotification(accessToken, andonOrde, 1, secondDelay); + } else { + log.warn("涓�绾ч�氱煡鍙戦�佸け璐ワ紝缁堟鍚庣画閫氱煡娴佺▼锛屽畨鐏疘D: {}", andonOrde.getId()); + } + + return firstLevelResult; + } catch (Exception e) { + log.error("澶勭悊瀹夌伅閫氱煡寮傚父锛屽畨鐏疘D: {}", andonOrde != null ? andonOrde.getId() : "鏈煡", e); + return false; + } + } + + /** + * 鍙戦�佹寚瀹氱骇鍒殑閫氱煡 + * @param level 1-涓�绾э紝2-浜岀骇锛�3-涓夌骇 + */ + private boolean sendLevelNotification(String accessToken, AndonButtonDTO andonOrde, int level) { + try { + String levelDesc = getLevelDesc(level); + String openId = getResponderOpenId(andonOrde, level); + String currentTime = sdf.format(new Date()); + log.info("銆恵}銆戝紑濮嬪彂閫亄}绾у畨鐏�氱煡锛屾帴鏀朵汉openId: {}, 瀹夌伅ID: {}", + currentTime, levelDesc, openId, andonOrde.getId()); + + // 鏋勫缓璇锋眰URL + String url = feishuUrl + "open-apis/im/v1/messages?receive_id_type=open_id"; + log.info("{}绾ч�氱煡璇锋眰URL: {}", levelDesc, url); + + // 璁剧疆璇锋眰澶� + HttpHeaders headers = new HttpHeaders(); + String authHeader = "Bearer " + accessToken; + headers.add("Authorization", authHeader); + headers.add("Content-Type", "application/json; charset=utf-8"); + log.info("璁剧疆{}绾ч�氱煡璇锋眰澶�: Authorization = {}", levelDesc, + authHeader.substring(0, Math.min(30, authHeader.length())) + "..."); + + // 鏋勫缓娑堟伅鍐呭 + JSONObject content = new JSONObject(); + String notificationContent = buildNotificationContent(andonOrde, level); + content.put("text", notificationContent); + log.debug("銆恵}銆憑}绾ч�氱煡鍐呭: {}", currentTime, levelDesc, notificationContent); + + // 鏋勫缓璇锋眰浣� + JSONObject requestBody = new JSONObject(); + requestBody.put("receive_id", openId); + requestBody.put("msg_type", "text"); + requestBody.put("content", content.toJSONString()); + requestBody.put("uuid", "andon_" + andonOrde.getId() + "_level_" + level + "_" + System.currentTimeMillis()); + + // 鍙戦�佽姹� + HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers); + ResponseEntity<String> response = restTemplate.exchange( + url, HttpMethod.POST, requestEntity, String.class + ); + + // 瑙f瀽鍝嶅簲 + JSONObject result = JSONObject.parseObject(response.getBody()); + log.debug("{}绾ч�氱煡API鍝嶅簲: {}", levelDesc, result != null ? result.toJSONString() : "null"); + + if (result != null && result.getInteger("code") == 0) { + JSONObject data = result.getJSONObject("data"); + if (data != null) { + log.info("銆恵}銆憑}绾у畨鐏�氱煡鍙戦�佹垚鍔燂紝娑堟伅ID: {}, 瀹夌伅ID: {}", + currentTime, levelDesc, data.getString("message_id"), andonOrde.getId()); + return true; + } else { + log.warn("{}绾ч�氱煡鍝嶅簲data涓虹┖锛屽畨鐏疘D: {}", levelDesc, andonOrde.getId()); + return false; + } + } else { + log.error("鍙戦�亄}绾у畨鐏�氱煡澶辫触锛屽畨鐏疘D: {}", levelDesc, andonOrde.getId()); + if (result != null) { + log.error("閿欒鐮�: {}, 閿欒淇℃伅: {}", result.getInteger("code"), result.getString("msg")); + } + return false; + } + + } catch (Exception e) { + log.error("鍙戦�亄}绾у畨鐏�氱煡寮傚父锛屽畨鐏疘D: {}", getLevelDesc(level), andonOrde.getId(), e); + return false; + } + } + + /** + * 璋冨害涓嬩竴绾ч�氱煡锛�1鈫�2鈫�3锛� + * @param currentLevel 褰撳墠绾у埆 + * @param delayMinutes 寤惰繜鍒嗛挓鏁帮紙鐢卞綋鍓嶇骇鍒搷搴旀椂闀垮喅瀹氾級 + */ + private void scheduleNextLevelNotification(String accessToken, AndonButtonDTO andonOrde, int currentLevel, int delayMinutes) { + int nextLevel = currentLevel + 1; + if (nextLevel > 3) { + log.info("宸插埌杈炬渶楂樼骇鍒�氱煡锛屾棤闇�缁х画璋冨害锛屽畨鐏疘D: {}", andonOrde.getId()); + return; + } + + String currentLevelDesc = getLevelDesc(currentLevel); + String nextLevelDesc = getLevelDesc(nextLevel); + String scheduleTime = sdf.format(new Date()); + String executeTime = sdf.format(new Date(System.currentTimeMillis() + delayMinutes * 60 * 1000L)); + + log.info("銆恵}銆戣皟搴}閫氱煡锛屽欢杩焮}鍒嗛挓锛堝綋鍓嶇骇鍒珄}鏃堕暱锛夛紝棰勮鎵ц鏃堕棿: {}", + scheduleTime, nextLevelDesc, delayMinutes, currentLevelDesc, executeTime); + + scheduler.schedule(() -> { + try { + String currentExecuteTime = sdf.format(new Date()); + log.info("銆恵}銆戝紑濮嬫墽琛寋}閫氱煡妫�鏌ワ紝瀹夌伅ID: {}", currentExecuteTime, nextLevelDesc, andonOrde.getId()); + + // 妫�鏌ヨ鍗曠姸鎬侊細3琛ㄧず宸插搷搴旓紝鏃犻渶鍙戦�佷笅涓�绾� + if (andonOrde.getOrderStatus() != null && "3".equals(andonOrde.getOrderStatus())) { + log.info("銆恵}銆戣鍗曞凡鍝嶅簲锛坰tatus=3锛夛紝鍙栨秷{}閫氱煡鍙戦�侊紝瀹夌伅ID: {}", + currentExecuteTime, nextLevelDesc, andonOrde.getId()); + return; + } + + // 妫�鏌ヤ笅涓�绾у搷搴斾汉鏄惁鏈夋晥 + if (!hasValidResponder(andonOrde, nextLevel)) { + log.warn("銆恵}銆憑}鍝嶅簲浜轰俊鎭棤鏁堬紝鍙栨秷閫氱煡鍙戦�侊紝瀹夌伅ID: {}", + currentExecuteTime, nextLevelDesc, andonOrde.getId()); + return; + } + + // 鍙戦�佷笅涓�绾ч�氱煡 + boolean nextLevelResult = sendLevelNotification(accessToken, andonOrde, nextLevel); + if (nextLevelResult && nextLevel < 3) { + + int nextDelay = getResponseDuration(andonOrde, nextLevel); + String nextExecuteTime = sdf.format(new Date(System.currentTimeMillis() + nextDelay * 60 * 1000L)); + log.info("銆恵}銆憑}閫氱煡璋冨害涓夌骇閫氱煡锛屽欢杩焮}鍒嗛挓锛岄璁″彂閫佹椂闂�: {}", + currentExecuteTime, nextLevelDesc, nextDelay, nextExecuteTime); + scheduleNextLevelNotification(accessToken, andonOrde, nextLevel, nextDelay); + } else if (!nextLevelResult) { + log.warn("銆恵}銆憑}閫氱煡鍙戦�佸け璐ワ紝缁堟鍚庣画璋冨害锛屽畨鐏疘D: {}", + currentExecuteTime, nextLevelDesc, andonOrde.getId()); + } + + } catch (Exception e) { + log.error("鎵ц{}璋冨害浠诲姟寮傚父锛屽畨鐏疘D: {}", nextLevelDesc, andonOrde.getId(), e); + } + }, delayMinutes, TimeUnit.MINUTES); + } + /** + * 鏋勫缓閫氱煡鍐呭锛堜紭鍖栧垎闅旂锛屾彁鍗囧彲璇绘�э級 + */ + private String buildNotificationContent(AndonButtonDTO andonOrde, int level) { + // 鑾峰彇宸ュ巶鍚嶇О鍜屼骇绾垮悕绉帮紝鍋氱┖鍊间繚鎶� + String parentFactoryName = andonOrde.getParentFactoryName() != null ? andonOrde.getParentFactoryName() : "鏈煡宸ュ巶"; + String factoryName = andonOrde.getFactoryName() != null ? andonOrde.getFactoryName() : "鏈煡浜х嚎"; + String content; + + if (level == 1) { + // 涓�绾фā鏉匡細浣跨敤"路"鍒嗛殧宸ュ巶鍜屼骇绾� + int firstDuration = andonOrde.getUpgradeResponseDuration() != null ? andonOrde.getUpgradeResponseDuration() : 0; + content = String.format(FIRST_LEVEL_TEMPLATE, parentFactoryName, factoryName, firstDuration); + } else { + // 浜岀骇妯℃澘锛氫繚鎸佷竴鑷寸殑鍒嗛殧椋庢牸 + String prevResponder = getResponderName(andonOrde, level - 1); + int prevDuration = getResponseDuration(andonOrde, level - 1); + + prevResponder = oConvertUtils.isEmpty(prevResponder) ? "鏈煡浜哄憳" : prevResponder; + prevDuration = Math.max(prevDuration, 0); + + content = String.format(SECOND_LEVEL_TEMPLATE, parentFactoryName, factoryName, prevResponder, prevDuration); + } + + log.debug("鏋勫缓{}绾ч�氱煡鍐呭: {}", level, content); + return content; + } +// /** +// * 鏋勫缓閫氱煡鍐呭锛堟寜绾у埆浣跨敤涓嶅悓妯℃澘锛� +// */ +// private String buildNotificationContent(AndonButtonDTO andonOrde, int level) { +// String factoryName = andonOrde.getFactoryName() != null ? andonOrde.getFactoryName() : "鏈煡浜х嚎"; +// +// if (level == 1) { +// // 涓�绾фā鏉匡細銆愬伐鑹哄畨鐏�慩XX浜х嚎鍙戣捣浜嗗伐鑹哄畨鐏紝璇穢x鍒嗛挓鍐呭湪PDA涓婅繘琛屽搷搴斿鐞嗭紒锛侊紒 +// return String.format("銆愬伐鑹哄畨鐏�慭n%s浜х嚎鍙戣捣浜嗗伐鑹哄畨鐏紝璇�%d鍒嗛挓鍐呭湪PDA涓婅繘琛屽搷搴斿鐞嗭紒锛侊紒", +// factoryName, +// andonOrde.getUpgradeResponseDuration()); +// } else { +// // 浜�/涓夌骇妯℃澘锛氥�愬伐鑹哄畨鐏�慩XX锛堜骇绾匡級鍙戣捣鐨勫伐鑹哄畨鐏紝xxx锛堜笂涓�绾у搷搴斾汉锛夋湭鍦▁x鍒嗛挓鍐呭搷搴旓紝璇峰敖蹇潱淇冭繘琛屽搷搴斿鐞嗭紒锛侊紒 +// String prevLevelDesc = getLevelDesc(level - 1); +// String prevResponder = getResponderName(andonOrde, level - 1); +// int prevDuration = getResponseDuration(andonOrde, level - 1); +// +// return String.format("銆愬伐鑹哄畨鐏�慭n%s锛堜骇绾匡級鍙戣捣鐨勫伐鑹哄畨鐏紝%s锛�%s鍝嶅簲浜猴級鏈湪%d鍒嗛挓鍐呭搷搴旓紝璇峰敖蹇潱淇冭繘琛屽搷搴斿鐞嗭紒锛侊紒", +// factoryName, +// prevResponder, +// prevLevelDesc, +// prevDuration); +// } +// } + + /** + * 楠岃瘉閫氱煡鐩稿叧鍙傛暟 + */ + private boolean validateNotificationParams(AndonButtonDTO andonOrde) { + if (andonOrde == null) { + log.error("瀹夌伅璁㈠崟淇℃伅涓虹┖"); + return false; + } + if (andonOrde.getId() == null) { + log.error("瀹夌伅ID涓虹┖"); + return false; + } + // 涓�绾у搷搴旀牎楠岋紙蹇呴�夛級 + if (andonOrde.getResponderOpenId() == null || andonOrde.getResponderOpenId().isEmpty() + || andonOrde.getUpgradeResponseDuration() == null || andonOrde.getUpgradeResponseDuration() <= 0) { + log.error("涓�绾у搷搴斾汉淇℃伅鏃犳晥锛坥penId鎴栨椂闀跨己澶憋級锛屽畨鐏疘D: {}", andonOrde.getId()); + return false; + } + // 浜岀骇鍝嶅簲鏍¢獙锛堣嫢瀛樺湪鍒欏繀閫夊畬鏁达級 + if (andonOrde.getSecondResponderOpenId() != null && !andonOrde.getSecondResponderOpenId().isEmpty()) { + if (andonOrde.getSecondUpgradeResponseDuration() == null || andonOrde.getSecondUpgradeResponseDuration() <= 0) { + log.error("浜岀骇鍝嶅簲浜哄瓨鍦ㄤ絾鏃堕暱鏃犳晥锛屽畨鐏疘D: {}", andonOrde.getId()); + return false; + } + } + // 涓夌骇鍝嶅簲鏍¢獙锛堣嫢瀛樺湪鍒欏繀閫夊畬鏁达級 + if (andonOrde.getThirdResponderOpenId() != null && !andonOrde.getThirdResponderOpenId().isEmpty()) { + if (andonOrde.getSecondUpgradeResponseDuration() == null || andonOrde.getSecondUpgradeResponseDuration() <= 0) { + log.error("涓夌骇鍝嶅簲浜哄瓨鍦ㄤ絾浜岀骇鏃堕暱鏃犳晥锛堜笁绾т緷璧栦簩绾ф椂闀匡級锛屽畨鐏疘D: {}", andonOrde.getId()); + return false; + } + } + return true; + } + + // 宸ュ叿鏂规硶锛氳幏鍙栫骇鍒弿杩� + private String getLevelDesc(int level) { + switch (level) { + case 1: return "涓�绾�"; + case 2: return "浜岀骇"; + case 3: return "涓夌骇"; + default: return "鏈煡绾у埆"; + } + } + + // 宸ュ叿鏂规硶锛氳幏鍙栧搷搴斾汉openId + private String getResponderOpenId(AndonButtonDTO andonOrde, int level) { + switch (level) { + case 1: return andonOrde.getResponderOpenId(); + case 2: return andonOrde.getSecondResponderOpenId(); + case 3: return andonOrde.getThirdResponderOpenId(); + default: return null; + } + } + + // 宸ュ叿鏂规硶锛氳幏鍙栧搷搴斾汉鍚嶇О + private String getResponderName(AndonButtonDTO andonOrde, int level) { + String name = null; + switch (level) { + case 1: + name = andonOrde.getResponder(); + break; + case 2: + name = andonOrde.getSecondResponder(); + break; + case 3: + name = andonOrde.getThirdResponder(); + break; + default: + name = null; + } + return name != null ? name : "鏈煡鍝嶅簲浜�"; + } + + // 宸ュ叿鏂规硶锛氳幏鍙栧搷搴旀椂闀匡紙涓�绾�=浜岀骇寤惰繜锛屼簩绾�=涓夌骇寤惰繜锛� + private int getResponseDuration(AndonButtonDTO andonOrde, int level) { + int duration = 0; + switch (level) { + case 1: + duration = andonOrde.getUpgradeResponseDuration() != null ? andonOrde.getUpgradeResponseDuration() : 0; + break; + case 2: + duration = andonOrde.getSecondUpgradeResponseDuration() != null ? andonOrde.getSecondUpgradeResponseDuration() : 0; + break; + case 3: + duration = 0; // 涓夌骇鏄渶鍚庝竴绾э紝鏃犻渶寤惰繜 + break; + default: + duration = 0; + } + return duration; + } + + // 宸ュ叿鏂规硶锛氬垽鏂寚瀹氱骇鍒搷搴斾汉鏄惁鏈夋晥 + private boolean hasValidResponder(AndonButtonDTO andonOrde, int level) { + String openId = getResponderOpenId(andonOrde, level); + return openId != null && !openId.isEmpty(); + } + + /** + * 鑾峰彇閮ㄩ棬鐢ㄦ埛鍒楄〃锛堢洿灞炲憳宸ワ級 + */ + private List<FeishuUser> getDepartmentUsers(String accessToken, String departmentId) { + List<FeishuUser> userList = new ArrayList<>(); + try { + log.info("寮�濮嬭幏鍙栭涔﹂儴闂ㄧ敤鎴峰垪琛紝閮ㄩ棬ID: {}", departmentId); + + if (accessToken == null || accessToken.isEmpty()) { + log.error("璁块棶浠ょ墝涓虹┖锛屾棤娉曠户缁墽琛�"); + return userList; + } + log.info("浣跨敤鐨勮闂护鐗屽墠缂�: Bearer {}", accessToken.substring(0, Math.min(20, accessToken.length())) + "..."); + + String url = feishuUrl + "open-apis/contact/v3/users/find_by_department"; + String pageToken = null; + int pageNumber = 1; + + do { + StringBuilder urlBuilder = new StringBuilder(url); + urlBuilder.append("?department_id=").append(departmentId); + urlBuilder.append("&department_id_type=open_department_id"); + urlBuilder.append("&page_size=50"); + urlBuilder.append("&user_id_type=open_id"); + + if (pageToken != null && !pageToken.isEmpty()) { + urlBuilder.append("&page_token=").append(pageToken); + } + + log.info("璇锋眰绗瑊}椤垫暟鎹紝URL: {}", pageNumber, urlBuilder.toString()); + + HttpHeaders headers = new HttpHeaders(); + String authHeader = "Bearer " + accessToken; + headers.add("Authorization", authHeader); + headers.add("Content-Type", "application/json; charset=utf-8"); + log.info("璁剧疆璇锋眰澶�: Authorization = {}", authHeader.substring(0, Math.min(30, authHeader.length())) + "..."); + + HttpEntity<String> requestEntity = new HttpEntity<>(headers); + ResponseEntity<String> response = restTemplate.exchange( + urlBuilder.toString(), HttpMethod.GET, requestEntity, String.class + ); + + JSONObject result = JSONObject.parseObject(response.getBody()); + log.debug("绗瑊}椤礎PI鍝嶅簲: {}", pageNumber, result != null ? result.toJSONString() : "null"); + + if (result != null && result.getInteger("code") == 0) { + JSONObject data = result.getJSONObject("data"); + if (data != null) { + Object items = data.get("items"); + log.info("绗瑊}椤靛師濮嬬敤鎴锋暟鎹暟閲�: {}", pageNumber, items instanceof List ? ((List<?>) items).size() : 0); + + if (items != null) { + List<FeishuUser> pageUsers = parseUsers(items); + userList.addAll(pageUsers); + log.info("绗瑊}椤佃В鏋愬悗鐢ㄦ埛鏁伴噺: {}", pageNumber, pageUsers.size()); + } + + pageToken = data.getString("page_token"); + boolean hasMore = data.getBooleanValue("has_more"); + log.info("绗瑊}椤礹as_more: {}, page_token: {}", pageNumber, hasMore, pageToken); + pageNumber++; + } else { + log.warn("绗瑊}椤礵ata涓虹┖", pageNumber); + break; + } + } else { + log.error("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛鍒楄〃澶辫触锛屽搷搴�: {}", result != null ? result.toJSONString() : "null"); + if (result != null) { + log.error("閿欒鐮�: {}, 閿欒淇℃伅: {}", result.getInteger("code"), result.getString("msg")); + } + break; + } + } while (pageToken != null && !pageToken.isEmpty()); + + log.info("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛瀹屾垚锛屾�荤敤鎴锋暟閲�: {}", userList.size()); + + } catch (Exception e) { + log.error("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛鍒楄〃寮傚父", e); + } + return userList; + } + + /** + * 瑙f瀽鐢ㄦ埛鏁版嵁 + */ + @SuppressWarnings("unchecked") + private List<FeishuUser> parseUsers(Object items) { + Logger log = LoggerFactory.getLogger(FeishuUserService.class); + List<FeishuUser> userList = new ArrayList<>(); + if (!(items instanceof List)) { + log.warn("瑙f瀽鐢ㄦ埛鏁版嵁澶辫触锛宨tems涓嶆槸鍒楄〃绫诲瀷: {}", items); + return userList; + } + List<?> userItems = (List<?>) items; + log.info("寮�濮嬭В鏋愰涔︾敤鎴峰垪琛紝鍏眥}鏉¤褰�", userItems.size()); + for (Object item : userItems) { + if (item == null || !(item instanceof Map)) { + log.warn("璺宠繃鏃犳晥鐢ㄦ埛鏁版嵁椤癸紝绫诲瀷涓嶅尮閰�: {}", item != null ? item.getClass() : "null"); + continue; + } + Map<String, Object> userMap = (Map<String, Object>) item; + FeishuUser user = new FeishuUser(); + user.setOpenId((String) userMap.getOrDefault("open_id", "")); + + String name = (String) userMap.getOrDefault("name", ""); + if (name.contains(" ")) { + String[] parts = name.split(" "); + if (parts.length == 2) { + user.setUsername(parts[0].trim()); + user.setRealname(parts[1].trim()); + user.setWorkNo(parts[0].trim()); + } else { + user.setUsername(name); + user.setRealname(name); + user.setWorkNo(""); + log.warn("椋炰功鐢ㄦ埛name瀛楁鏍煎紡寮傚父锛屾棤娉曟媶鍒嗭紝鍘熷鍊硷細{}", name); + } + } else { + user.setUsername(name); + user.setRealname(name); + user.setWorkNo(""); + log.warn("椋炰功鐢ㄦ埛name瀛楁鏃犵┖鏍煎垎闅旓紝鏃犳硶鎷嗗垎锛屽師濮嬪�硷細{}", name); + } + + user.setEnName((String) userMap.getOrDefault("en_name", "")); + user.setDescription((String) userMap.getOrDefault("description", "")); + Object mobileVisibleObj = userMap.get("mobile_visible"); + user.setMobileVisible(mobileVisibleObj instanceof Boolean ? (Boolean) mobileVisibleObj : false); + + Object avatarObj = userMap.get("avatar"); + if (avatarObj instanceof Map) { + Map<String, Object> avatarMap = (Map<String, Object>) avatarObj; + user.setAvatar240((String) avatarMap.getOrDefault("avatar_240", "")); + user.setAvatar640((String) avatarMap.getOrDefault("avatar_640", "")); + user.setAvatar72((String) avatarMap.getOrDefault("avatar_72", "")); + user.setAvatarOrigin((String) avatarMap.getOrDefault("avatar_origin", "")); + } else { + log.info("鐢ㄦ埛[{}]鏈缃ご鍍忔垨澶村儚鏍煎紡寮傚父", user.getRealname()); + } + + user.setPassword("123456"); + user.setOpenId((String) userMap.getOrDefault("open_id", "")); + userList.add(user); + } + + return userList; + } + + /** + * 鍚屾鍗曚釜椋炰功鐢ㄦ埛鍒扮郴缁� + */ + private boolean syncFeishuUserToSystem(FeishuUser feishuUser) { + String username = feishuUser.getUsername(); + SysUser existUser = sysUserService.getUserByName(username); + SysUser sysUser = new SysUser(); + sysUser.setUsername(username); + sysUser.setStatus(1); + sysUser.setDelFlag(0); + sysUser.setAvatar(feishuUser.getAvatar640()); + sysUser.setRealname(feishuUser.getRealname()); + sysUser.setWorkNo(feishuUser.getWorkNo()); + String password = "123456", salt = oConvertUtils.randomGen(8); + String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt); + sysUser.setSalt(salt); + sysUser.setPassword(passwordEncode); + sysUser.setOpenId(feishuUser.getOpenId()); + + if (existUser == null) { + sysUserService.addUserWithRole(sysUser, "5"); + log.info("鏂板鐢ㄦ埛: {}", username); + return false; + } else { + sysUser.setId(existUser.getId()); + sysUserService.editUser(sysUser); + log.info("鏇存柊鐢ㄦ埛: {}", username); + return true; + } + } +} diff --git a/src/main/java/org/jeecg/modules/mes/entity/MessageResponse.java b/src/main/java/org/jeecg/modules/mes/entity/MessageResponse.java new file mode 100644 index 0000000..1d5679f --- /dev/null +++ b/src/main/java/org/jeecg/modules/mes/entity/MessageResponse.java @@ -0,0 +1,12 @@ +package org.jeecg.modules.mes.entity; + +import lombok.Data; + +@Data +public class MessageResponse { + private boolean success; + private String message; + private String messageId; + private Long timestamp; + +} diff --git a/src/main/java/org/jeecg/modules/mes/job/FeishuUserService.java b/src/main/java/org/jeecg/modules/mes/job/FeishuUserService.java deleted file mode 100644 index b5b3991..0000000 --- a/src/main/java/org/jeecg/modules/mes/job/FeishuUserService.java +++ /dev/null @@ -1,327 +0,0 @@ -package org.jeecg.modules.mes.job; - -import com.alibaba.fastjson.JSONObject; -import lombok.extern.slf4j.Slf4j; -import org.jeecg.common.util.PasswordUtil; -import org.jeecg.common.util.RestUtil; -import org.jeecg.common.util.oConvertUtils; -import org.jeecg.modules.mes.entity.FeishuUser; -import org.jeecg.modules.system.entity.SysUser; -import org.jeecg.modules.system.service.ISysUserService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; - -import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Service -@Slf4j -public class FeishuUserService { - - @Resource - private ISysUserService sysUserService; - - @Resource - private RestTemplate restTemplate; // 鏂板RestTemplate渚濊禆娉ㄥ叆 - - @Value("${feishu.appId:}") - private String appId; - - @Value("${feishu.appSecret:}") - private String appSecret; - - @Value("${feishu.url:}") - private String feishuUrl; - - /** - * 鍚屾椋炰功閮ㄩ棬鐢ㄦ埛鍒扮郴缁熺敤鎴疯〃 - * @param departmentId 椋炰功閮ㄩ棬ID - */ - public void syncFeishuDepartmentUsers(String departmentId) { - try { - log.info("寮�濮嬪悓姝ラ涔﹂儴闂ㄧ敤鎴凤紝閮ㄩ棬ID: {}", departmentId); - - // 1. 鑾峰彇椋炰功璁块棶浠ょ墝 - String accessToken = getFeishuAccessToken(); - if (oConvertUtils.isEmpty(accessToken)) { - log.error("鑾峰彇椋炰功璁块棶浠ょ墝澶辫触锛岀粓姝㈠悓姝ユ祦绋�"); - return; // 浠ょ墝鑾峰彇澶辫触鐩存帴杩斿洖锛岄伩鍏嶅悗缁棤鏁堟搷浣� - } - - // 2. 鑾峰彇閮ㄩ棬涓嬬殑鐢ㄦ埛鍒楄〃 - List<FeishuUser> feishuUsers = getDepartmentUsers(accessToken, departmentId); - log.info("鑾峰彇鍒伴涔﹂儴闂ㄧ敤鎴锋暟閲�: {}", feishuUsers.size()); - - // 3. 鍚屾鍒扮郴缁熺敤鎴疯〃 - int successCount = 0; - int updateCount = 0; - int addCount = 0; - - for (FeishuUser feishuUser : feishuUsers) { - try { - boolean isUpdated = syncFeishuUserToSystem(feishuUser); - successCount++; - if (isUpdated) { - updateCount++; - } else { - addCount++; - } - } catch (Exception e) { - log.error("鍚屾椋炰功鐢ㄦ埛澶辫触锛岀敤鎴稩D: {}", feishuUser.getUserId(), e); - } - } - - log.info("椋炰功鐢ㄦ埛鍚屾瀹屾垚锛屾�诲鐞�: {}锛屾柊澧�: {}锛屾洿鏂�: {}", successCount, addCount, updateCount); - } catch (Exception e) { - log.error("鍚屾椋炰功閮ㄩ棬鐢ㄦ埛澶辫触锛岄儴闂↖D: {}", departmentId, e); - throw new RuntimeException("鍚屾椋炰功鐢ㄦ埛澶辫触: " + e.getMessage()); - } - } - - private String getFeishuAccessToken() { - try { - String url = feishuUrl + "open-apis/auth/v3/tenant_access_token/internal"; - - log.info("寮�濮嬭幏鍙栭涔﹁闂护鐗岋紝AppId: {}", - appId != null ? appId.substring(0, Math.min(appId.length(), 10)) + "..." : "null"); - - JSONObject params = new JSONObject(); - params.put("app_id", appId); - params.put("app_secret", appSecret); - - log.debug("鑾峰彇浠ょ墝璇锋眰鍙傛暟: {}", params.toJSONString()); - - JSONObject result = RestUtil.post(url, params); - - log.info("鑾峰彇椋炰功璁块棶浠ょ墝鍝嶅簲: {}", result != null ? result.toJSONString() : "null"); - - if (result != null && result.getInteger("code") == 0) { - String accessToken = result.getString("tenant_access_token"); - log.info("鎴愬姛鑾峰彇椋炰功璁块棶浠ょ墝锛屼护鐗岄暱搴�: {}", accessToken != null ? accessToken.length() : 0); - return accessToken; - } else { - log.error("鑾峰彇椋炰功璁块棶浠ょ墝澶辫触锛屽搷搴�: {}", result != null ? result.toJSONString() : "null"); - if (result != null) { - log.error("閿欒鐮�: {}, 閿欒淇℃伅: {}", result.getInteger("code"), result.getString("msg")); - } - return null; - } - } catch (Exception e) { - log.error("鑾峰彇椋炰功璁块棶浠ょ墝寮傚父", e); - return null; - } - } - - /** - * 鑾峰彇閮ㄩ棬鐢ㄦ埛鍒楄〃锛堢洿灞炲憳宸ワ級 - */ - private List<FeishuUser> getDepartmentUsers(String accessToken, String departmentId) { - List<FeishuUser> userList = new ArrayList<>(); - try { - log.info("寮�濮嬭幏鍙栭涔﹂儴闂ㄧ敤鎴峰垪琛紝閮ㄩ棬ID: {}", departmentId); - - // 楠岃瘉璁块棶浠ょ墝 - if (accessToken == null || accessToken.isEmpty()) { - log.error("璁块棶浠ょ墝涓虹┖锛屾棤娉曠户缁墽琛�"); - return userList; - } - log.info("浣跨敤鐨勮闂护鐗屽墠缂�: Bearer {}", accessToken.substring(0, Math.min(20, accessToken.length())) + "..."); - - // 椋炰功API绔偣 - String url = feishuUrl + "open-apis/contact/v3/users/find_by_department"; - - String pageToken = null; - int pageNumber = 1; - - do { - // 鏋勫缓璇锋眰URL鍜屽弬鏁� - StringBuilder urlBuilder = new StringBuilder(url); - urlBuilder.append("?department_id=").append(departmentId); - urlBuilder.append("&department_id_type=open_department_id"); - urlBuilder.append("&page_size=50"); - urlBuilder.append("&user_id_type=open_id"); - - if (pageToken != null && !pageToken.isEmpty()) { - urlBuilder.append("&page_token=").append(pageToken); - } - - log.info("璇锋眰绗瑊}椤垫暟鎹紝URL: {}", pageNumber, urlBuilder.toString()); - - // 璁剧疆璇锋眰澶� - 鍏抽敭淇鐐癸細浣跨敤HttpHeaders纭繚澶翠俊鎭纭缃� - HttpHeaders headers = new HttpHeaders(); - String authHeader = "Bearer " + accessToken; - headers.add("Authorization", authHeader); - headers.add("Content-Type", "application/json; charset=utf-8"); - log.info("璁剧疆璇锋眰澶�: Authorization = {}", authHeader.substring(0, Math.min(30, authHeader.length())) + "..."); - - // 浣跨敤RestTemplate鍙戦�佽姹傦紝纭繚澶翠俊鎭姝g‘浼犻�� - HttpEntity<String> requestEntity = new HttpEntity<>(headers); - ResponseEntity<String> response = restTemplate.exchange( - urlBuilder.toString(), - HttpMethod.GET, - requestEntity, - String.class - ); - - // 瑙f瀽鍝嶅簲 - JSONObject result = JSONObject.parseObject(response.getBody()); - log.debug("绗瑊}椤礎PI鍝嶅簲: {}", pageNumber, result != null ? result.toJSONString() : "null"); - - if (result != null && result.getInteger("code") == 0) { - JSONObject data = result.getJSONObject("data"); - if (data != null) { - // 瑙f瀽鐢ㄦ埛鍒楄〃 - Object items = data.get("items"); - log.info("绗瑊}椤靛師濮嬬敤鎴锋暟鎹暟閲�: {}", pageNumber, items instanceof List ? ((List<?>) items).size() : 0); - - if (items != null) { - List<FeishuUser> pageUsers = parseUsers(items); - userList.addAll(pageUsers); - log.info("绗瑊}椤佃В鏋愬悗鐢ㄦ埛鏁伴噺: {}", pageNumber, pageUsers.size()); - } - - // 妫�鏌ユ槸鍚︽湁涓嬩竴椤� - pageToken = data.getString("page_token"); - boolean hasMore = data.getBooleanValue("has_more"); - log.info("绗瑊}椤礹as_more: {}, page_token: {}", pageNumber, hasMore, pageToken); - pageNumber++; - } else { - log.warn("绗瑊}椤礵ata涓虹┖", pageNumber); - break; - } - } else { - log.error("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛鍒楄〃澶辫触锛屽搷搴�: {}", result != null ? result.toJSONString() : "null"); - if (result != null) { - log.error("閿欒鐮�: {}, 閿欒淇℃伅: {}", result.getInteger("code"), result.getString("msg")); - } - break; - } - } while (pageToken != null && !pageToken.isEmpty()); - - log.info("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛瀹屾垚锛屾�荤敤鎴锋暟閲�: {}", userList.size()); - - } catch (Exception e) { - log.error("鑾峰彇椋炰功閮ㄩ棬鐢ㄦ埛鍒楄〃寮傚父", e); - } - return userList; - } - - /** - * 瑙f瀽鐢ㄦ埛鏁版嵁 - */ - /** - * 瑙f瀽鐢ㄦ埛鏁版嵁 - */ - @SuppressWarnings("unchecked") - private List<FeishuUser> parseUsers(Object items) { - Logger log = LoggerFactory.getLogger(FeishuUserService.class); - List<FeishuUser> userList = new ArrayList<>(); - if (!(items instanceof List)) { - log.warn("瑙f瀽鐢ㄦ埛鏁版嵁澶辫触锛宨tems涓嶆槸鍒楄〃绫诲瀷: {}", items); - return userList; - } - List<?> userItems = (List<?>) items; - log.info("寮�濮嬭В鏋愰涔︾敤鎴峰垪琛紝鍏眥}鏉¤褰�", userItems.size()); - for (Object item : userItems) { - if (item == null || !(item instanceof Map)) { - log.warn("璺宠繃鏃犳晥鐢ㄦ埛鏁版嵁椤癸紝绫诲瀷涓嶅尮閰�: {}", item != null ? item.getClass() : "null"); - continue; - } - Map<String, Object> userMap = (Map<String, Object>) item; - FeishuUser user = new FeishuUser(); - // 瑙f瀽open_id - user.setOpenId((String) userMap.getOrDefault("open_id", "")); - // 瑙f瀽name骞舵媶鍒� - String name = (String) userMap.getOrDefault("name", ""); - if (name.contains(" ")) { - String[] parts = name.split(" "); - if (parts.length == 2) { - user.setUsername(parts[0].trim()); // 宸ュ彿閮ㄥ垎瀛樺埌username - user.setRealname(parts[1].trim()); // 濮撳悕閮ㄥ垎瀛樺埌realname - user.setWorkNo(parts[0].trim()); // 宸ュ彿涔熷瓨鍒皐orkNo - } else { - // 鎷嗗垎寮傚父鏃讹紝榛樿澶勭悊 - user.setUsername(name); - user.setRealname(name); - user.setWorkNo(""); - log.warn("椋炰功鐢ㄦ埛name瀛楁鏍煎紡寮傚父锛屾棤娉曟媶鍒嗭紝鍘熷鍊硷細{}", name); - } - } else { - user.setUsername(name); - user.setRealname(name); - user.setWorkNo(""); - log.warn("椋炰功鐢ㄦ埛name瀛楁鏃犵┖鏍煎垎闅旓紝鏃犳硶鎷嗗垎锛屽師濮嬪�硷細{}", name); - } - // 瑙f瀽鍏朵粬鍩烘湰淇℃伅 - user.setEnName((String) userMap.getOrDefault("en_name", "")); - user.setDescription((String) userMap.getOrDefault("description", "")); - Object mobileVisibleObj = userMap.get("mobile_visible"); - user.setMobileVisible(mobileVisibleObj instanceof Boolean ? (Boolean) mobileVisibleObj : false); - // 瑙f瀽澶村儚淇℃伅 - Object avatarObj = userMap.get("avatar"); - if (avatarObj instanceof Map) { - Map<String, Object> avatarMap = (Map<String, Object>) avatarObj; - user.setAvatar240((String) avatarMap.getOrDefault("avatar_240", "")); - user.setAvatar640((String) avatarMap.getOrDefault("avatar_640", "")); - user.setAvatar72((String) avatarMap.getOrDefault("avatar_72", "")); - user.setAvatarOrigin((String) avatarMap.getOrDefault("avatar_origin", "")); - } else { - log.info("鐢ㄦ埛[{}]鏈缃ご鍍忔垨澶村儚鏍煎紡寮傚父", user.getRealname()); - } - // 璁剧疆榛樿鍔犲瘑瀵嗙爜锛堣繖閲屽亣璁惧瘑鐮佹槸绠�鍗曞姞瀵嗗瓨鍌紝瀹為檯寤鸿鐢ㄦ洿瀹夊叏鐨勫姞瀵嗘柟寮忥級 - user.setPassword("123456"); // 浣犺姹傜殑榛樿瀵嗙爜 - // 灏唎pen_id瀛樺埌瀵瑰簲鐨勫瓧娈碉紙鏍规嵁浣犵殑鐢ㄦ埛琛ㄧ粨鏋勶紝鍋囪鐢ㄦ埛琛ㄦ湁open_id瀛楁锛� - user.setOpenId((String) userMap.getOrDefault("open_id", "")); - userList.add(user); - } - - return userList; - } - - /** - * 鍚屾鍗曚釜椋炰功鐢ㄦ埛鍒扮郴缁� - * @param feishuUser 椋炰功鐢ㄦ埛 - * @return true琛ㄧず鏇存柊锛宖alse琛ㄧず鏂板 - * - * 鍚庢湡澧炲姞锛� 鐢ㄦ埛鍚屾瀵规瘮锛岄涔︾鑱屽憳宸ラ渶瑕佸湪鏈湴鐢ㄦ埛琛ㄩ噷闈㈠皢璇ョ敤鎴风姸鎬佺鐢� - */ - private boolean syncFeishuUserToSystem(FeishuUser feishuUser) { - // 杩欓噷鏍规嵁鎷嗗垎鍚庣殑username锛堝伐鍙凤級鍘绘煡璇㈢郴缁熺敤鎴� - String username = feishuUser.getUsername(); - SysUser existUser = sysUserService.getUserByName(username); - SysUser sysUser = new SysUser(); - sysUser.setUsername(username); - sysUser.setStatus(1); - sysUser.setDelFlag(0); - sysUser.setAvatar(feishuUser.getAvatar640()); - sysUser.setRealname(feishuUser.getRealname()); - sysUser.setWorkNo(feishuUser.getWorkNo()); - String password = "123456", salt = oConvertUtils.randomGen(8); - String passwordEncode = PasswordUtil.encrypt(sysUser.getUsername(), password, salt); - sysUser.setSalt(salt); - sysUser.setPassword(passwordEncode); - sysUser.setOpenId(feishuUser.getOpenId()); - - if (existUser == null) { - - sysUserService.addUserWithRole(sysUser, "5"); - log.info("鏂板鐢ㄦ埛: {}", username); - return false; - } else { - sysUser.setId(existUser.getId()); - sysUserService.editUser(sysUser); - log.info("鏇存柊鐢ㄦ埛: {}", username); - return true; - } - } -} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index c2159c1..3ecdf62 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -126,9 +126,10 @@ connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000 datasource: master: - url: jdbc:sqlserver://192.168.1.118:1433;databasename=LXZN_TEST_XHJ;nullCatalogMeansCurrent=true + + url: jdbc:sqlserver://127.0.0.1:1433;databasename=LXZN-TEXT-XHJ;nullCatalogMeansCurrent=true username: sa - password: 123 + password: 123456 driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver #redis 閰嶇疆 redis: -- Gitblit v1.9.3