From c007f0ca1785db093d48f4846cda82fe8e955765 Mon Sep 17 00:00:00 2001 From: kimi <kimi42345@gmail.com> Date: 星期三, 27 五月 2020 09:59:29 +0800 Subject: [PATCH] merage --- src/main/java/com/highdatas/mdm/controller/DispenseController.java | 923 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 903 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/highdatas/mdm/controller/DispenseController.java b/src/main/java/com/highdatas/mdm/controller/DispenseController.java index 3c9508f..2246cb5 100644 --- a/src/main/java/com/highdatas/mdm/controller/DispenseController.java +++ b/src/main/java/com/highdatas/mdm/controller/DispenseController.java @@ -1,35 +1,43 @@ package com.highdatas.mdm.controller; -import com.highdatas.mdm.entity.TUser; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.mapper.Wrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.highdatas.mdm.entity.*; +import com.highdatas.mdm.entity.Character; import com.highdatas.mdm.pojo.CodeMsg; +import com.highdatas.mdm.pojo.DispenseField; import com.highdatas.mdm.pojo.Result; -import com.highdatas.mdm.service.DispenseService; -import com.highdatas.mdm.service.MasterDataService; +import com.highdatas.mdm.pojo.SubscribeEntity; +import com.highdatas.mdm.service.*; import com.highdatas.mdm.util.Constant; import com.highdatas.mdm.util.DbUtils; import com.highdatas.mdm.util.RedisClient; +import com.highdatas.mdm.util.pool.MqEntity; import com.highdatas.mdm.util.pool.MqMessage; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.List; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; /** * <p> * 鍓嶇鎺у埗鍣� * </p> - * + * @description 鍒嗗彂鎺ュ彛 * @author kimi * @since 2019-12-31 */ @RestController -@RequestMapping("/dispense") +@RequestMapping("/subscribe") public class DispenseController { @Autowired DispenseService dispenseService; @@ -37,28 +45,903 @@ RedisClient redisClient; @Autowired MasterDataService masterDataService; + @Autowired + IMasterAuthorService masterAuthorService; + @Autowired + IMaintainFieldService maintainFieldService; + @Autowired + IMaintainService maintainService; + @Autowired + IMenuMappingService menuMappingService; + @Autowired + IMasterAuthorSubscribeService subscribeService; + @Autowired + ISysMenuService menuService; + @Autowired + ISysViewService viewService; + @Autowired + IMasterAuthorSubscribeService masterAuthorSubscribeService; + @Autowired + IMasterAuthorUnactiveService masterAuthorUnactiveService; + @Autowired + ISysDispenseLogsService dispenseLogsService; + @Autowired + ISysFieldService fieldService; + /** + * + * @description: 椤甸潰璋冪敤鍒嗗彂鎺ュ彛 + * @param userId 鍒嗗彂鐢ㄦ埛 + * @param dataId 鍒嗗彂鐨刣ataId + * @param type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * @param increment 澧為噺/鍏ㄩ噺 + * @return: 鏄惁娣诲姞鍒伴槦鍒� + * + */ + @RequestMapping(value = "/dispense/surface", method = RequestMethod.GET) + public Result surface(@RequestParam String userId, @RequestParam String type, @RequestParam String dataId, HttpServletRequest request, HttpServletResponse response) { + //绫诲瀷涓� 涓婚鐨勬椂鍊欓渶瑕佷紶鍒嗗彂鍝釜鐗堟湰鐨勬暟鎹� + String versionId = request.getParameter("versionId"); + //娣诲姞鍒板垎鍙戦槦鍒� + return addPassiveMq(userId, type, dataId, versionId, request, "surface"); + } + /** + * + * @description: 鑾峰彇褰撳墠鍒嗗彂浠诲姟鏁版嵁鎬绘潯鏁帮紝渚涘閮ㄧ郴缁熻皟鐢� + * @param reqObj 鍙傛暟瀵硅薄 + * token 閫氳繃token鑾峰彇user淇℃伅 + * type 鏁版嵁绫诲瀷 瑙嗗浘锛屼富棰� + * dataId 鍒嗗彂鐨刣ataId + * versionId 涓婚鐨勭増鏈琲d + * increment 澧為噺/鍏ㄩ噺 + * @return: 璁板綍鏁� + * + */ + @RequestMapping(value = "/api/count", method = RequestMethod.POST) + public Result count(@RequestBody JSONObject reqObj) { + String token = reqObj.getString("token"); + String type = reqObj.getString("type"); + String dataId = reqObj.getString("dataId"); + String versionId = reqObj.getString("versionId"); + String incrementStr = reqObj.getString("increment"); + //鏍¢獙蹇呬紶瀛楁 + if (StringUtils.isEmpty(token) || StringUtils.isEmpty(type) || StringUtils.isEmpty(dataId)) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇鐢ㄦ埛淇℃伅 + String userId = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(userId)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + //杞崲increment绫诲瀷 + boolean increment = true; + if (!StringUtils.isEmpty(incrementStr)) { + increment = Boolean.valueOf(incrementStr); + } + if (type.equalsIgnoreCase(Constant.Master)) { + //涓婚 闇�鏍¢獙鐗堟湰瀛楁 + if (StringUtils.isEmpty(versionId)) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇涓婚鐗堟湰淇℃伅 + Maintain maintain = maintainService.selectById(versionId); + if (maintain == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇涓婚淇℃伅 + SysMenu sysMenu = menuService.selectById(dataId); + if (sysMenu == null) { + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + //鏍¢獙鏄惁宸茬粡娉ㄥ唽 + int subscribeCnt = subscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("menu_id", dataId).eq("user_id", userId)); + if (subscribeCnt < 1) { + return Result.error(CodeMsg.SUBSCRIBE_UN_ERROR); + } + //鏍¢獙鏄惁婵�娲� + int i = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().eq("maintain_id", versionId).eq("user_id", userId)); + if (i > 0) { + return Result.error(CodeMsg.Active_UN_ERROR); + } + //鑾峰彇鏉冮檺淇℃伅 + MasterAuthor masterAuthor = new MasterAuthor().setTableName(maintain.getTableName()); + TUser user = new TUser().setUserId(userId); + //鑾峰彇鐞嗚涓婄殑椤电爜鏁帮紝璁板綍淇℃伅 + com.highdatas.mdm.pojo.Page initPageInfo = DbUtils.masterAuthorService.getInitPageInfo(masterAuthor, maintain, user, increment); + if (initPageInfo != null) { + return Result.success(initPageInfo.getRecordCount()); + } + return Result.success(0); + } else if (type.equalsIgnoreCase(Constant.View)) { + //鑾峰彇瑙嗗浘淇℃伅 + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + //鏍¢獙鏄惁婵�娲� + Boolean active = sysView.getActive(); + if (!active) { + return Result.error(CodeMsg.Active_UN_ERROR); + } + //鑾峰彇瑙嗗浘璁板綍鏁� + long viewCount = viewService.getViewCount(sysView); + return Result.success(viewCount); + } else { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + } + + /** + * + * @description: 鑾峰彇褰撳墠鍒嗗彂浠诲姟鏁版嵁鏁版嵁锛屼緵澶栭儴绯荤粺璋冪敤 + * @param reqObj 鍙傛暟瀵硅薄 + * token 閫氳繃token鑾峰彇user淇℃伅 + * beginNo 璧峰鏉℃暟 + * endNo 缁撴潫鏉℃暟 + * type 鏁版嵁绫诲瀷 瑙嗗浘锛屼富棰� + * dataId 鍒嗗彂鐨刣ataId + * versionId 涓婚鐨勭増鏈琲d + * increment 澧為噺/鍏ㄩ噺 + * @return: 鏁版嵁璁板綍 + * + */ + @RequestMapping(value = "/api/data", method = RequestMethod.POST) + public Result data(@RequestBody JSONObject reqObj) { + //鍒涘缓鍒嗗彂鏃ュ織 + SysDispenseLogs logs = new SysDispenseLogs().setId(DbUtils.getUUID()).setCreateTime(new Date()); + //璁剧疆鏃ュ織绫诲瀷 + logs.setTouchType("rest"); + logs.insert(); + String token = reqObj.getString("token"); + String type = reqObj.getString("type"); + String dataId = reqObj.getString("dataId"); + String versionId = reqObj.getString("versionId"); + String incrementStr = reqObj.getString("increment"); + Integer beginNo = reqObj.getInteger("beginNo"); + Integer endNo = reqObj.getInteger("endNo"); + logs.setTopicId(type).setTagId(dataId).setDataType(type); + //beginNo endNo瀛楁 鏄惁鍚堢悊 + if (beginNo == null || endNo == null) { + logs.setErrorInfo("beginNo or endNo not exists").setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } else if (endNo < beginNo) { + logs.setErrorInfo("beginNo > endNo ").setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + if (beginNo < 0 || endNo < 0) { + logs.setErrorInfo("beginNo or endNo < 0").setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鏍¢獙蹇呬紶瀛楁 + if (StringUtils.isEmpty(token) || StringUtils.isEmpty(type) || StringUtils.isEmpty(dataId)) { + logs.setErrorInfo("token or type or dataId not found").setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇鐢ㄦ埛淇℃伅 + String userId = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(userId)) { + logs.setErrorInfo(CodeMsg.ERROR_FIND_TOKEN.getMsg()).setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + TUser userById = DbUtils.getUserById(userId); + //鏇存柊鏃ュ織淇℃伅 + logs.setUserName(userById.getUserName()); + logs.setUserId(userId).updateById(); + boolean increment = true; + if (!StringUtils.isEmpty(incrementStr)) { + increment = Boolean.valueOf(incrementStr); + } + com.highdatas.mdm.pojo.Page initPageInfo = null; + if (type.equalsIgnoreCase(Constant.Master)) { + //鏍¢獙鐗堟湰瀛楁 + if (StringUtils.isEmpty(versionId)) { + logs.setErrorInfo("versionId not exists").setStatus("false").updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇鐗堟湰淇℃伅 + Maintain maintain = maintainService.selectById(versionId); + if (maintain == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鏇存柊鏃ュ織淇℃伅 + logs.setMaintainId(maintain.getId()).setVersion(maintain.getVersion()); + logs.updateById(); + //鑾峰彇涓婚淇℃伅 + SysMenu sysMenu = menuService.selectById(dataId); + if (sysMenu == null) { + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + //鏇存柊涓婚淇℃伅 + logs.setName(sysMenu.getName()); + logs.updateById(); + //妫�楠屾槸鍚﹀凡娉ㄥ唽 + int subscribeCnt = subscribeService.selectCount(new EntityWrapper<MasterAuthorSubscribe>().eq("menu_id", dataId).eq("user_id", userId)); + if (subscribeCnt < 1) { + logs.setErrorInfo(CodeMsg.SUBSCRIBE_UN_ERROR.getMsg()).updateById(); + return Result.error(CodeMsg.SUBSCRIBE_UN_ERROR); + } + //妫�楠屾槸鍚﹀凡婵�娲� + int i = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().eq("maintain_id", versionId).eq("user_id", userId)); + if (i > 0) { + logs.setErrorInfo(CodeMsg.Active_UN_ERROR.getMsg()).updateById(); + return Result.error(CodeMsg.Active_UN_ERROR); + } + //鑾峰彇鏉冮檺 + MasterAuthor masterAuthor = new MasterAuthor().setTableName(maintain.getTableName()); + TUser user = new TUser().setUserId(userId); + //鑾峰彇鐞嗚涓婄殑椤垫暟锛岃褰曟暟 + initPageInfo = masterAuthorService.getInitPageInfo(masterAuthor, maintain, user, increment); + if (initPageInfo == null) { + return Result.success(null); + } + //閫氳繃 beginNo锛宔ndNo鏇存柊page淇℃伅 + boolean b = refreshInitPage(initPageInfo, beginNo, endNo); + if(!b) { + return Result.error(CodeMsg.ERROR_SIZE_TOO_LONG); + } + if (increment) { + //鑾峰彇澧為噺鏁版嵁 + String maintainTableName = maintain.getTableName(); + //鑾峰彇璁板綍琛� + String tempTableName = maintainTableName + Constant.RECORD; + //缁勮瀛楁 + List<SysField> fieldByMaintain = DbUtils.fieldService.getFieldByMaintain(maintain.getId()); + List<String> fieldList = fieldByMaintain.stream().map(sysField -> sysField.getField()).collect(Collectors.toList()); + String fields = fieldByMaintain.stream().map(sysField -> sysField.getField()).collect(Collectors.joining(Constant.COMMA)); + + //缁勮绛涢�夋潯浠� + String filter = DbUtils.masterAuthorService.getFilter(user, maintain.getId()); + if (StringUtils.isEmpty(filter)) { + filter = Constant.WHERE_DEFAULT; + } + //鑾峰彇鏁版嵁 + List<Map<String, Object>> maps = DbUtils.maintainDetailMapper.selectMaintainDetail(fields, tempTableName, maintain.getId(), filter, initPageInfo.getLimitSQL()); + //鑴辨晱瑙勫垯 + Map<String, AntianaphylaxisResult> helpfulField = DbUtils.antianaphylaxisClient.getHelpfulField(fields, maintainTableName); + //杞崲涓鸿劚鏁忓悗鐨勬暟鎹� + DbUtils.antianaphylaxisClient.fixMasterData(maps,helpfulField); + + //缁勮杩斿洖缁撴灉 + JSONObject object = new JSONObject(); + + object.fluentPut("records", maps); + + List<SysField> sysFields = masterAuthorService.getField(user, versionId); + List<DispenseField> collect = sysFields.stream().map(sysField -> new DispenseField().setField(sysField.getField()).setAlias(sysField.getAlias())).collect(Collectors.toList()); + object.fluentPut("fields", collect); + long time = new Date().getTime(); + logs.setSchedule(time - logs.getCreateTime().getTime()).setStatus("true").setTotal(Long.valueOf(initPageInfo.getRecordCount()).intValue()).updateById(); + return Result.success(object); + } else { + //鑾峰彇鍏ㄩ噺鏁版嵁 + Result result = masterDataService.selectListByPageByVersion(user, maintain.getTableName(), null, Constant.WHERE_DEFAULT, null, null, maintain.getVersion(), false, null, initPageInfo); + //缁勮杩斿洖缁撴灉 + Object data = result.getData(); + JSONObject masterResult = new JSONObject(); + JSONObject dataResult = (JSONObject) JSONObject.toJSON(data); + JSONObject grid = dataResult.getJSONObject("grid"); + masterResult.fluentPut("records", grid.getJSONArray("record")); + JSONArray fields = dataResult.getJSONArray("fields"); + ArrayList<DispenseField> dispenseFields = new ArrayList<>(); + for (Object field : fields) { + JSONObject one = (JSONObject) JSONObject.toJSON(field); + dispenseFields.add(new DispenseField().setAlias(one.getString("alias")).setField(one.getString("field"))); + } + grid.remove("record"); + masterResult.fluentPut("fields", dispenseFields); + //鏇存柊鎵ц鏃堕棿 + long time = new Date().getTime(); + logs.setSchedule(time - logs.getCreateTime().getTime()).setStatus("true").setTotal(Long.valueOf(initPageInfo.getRecordCount()).intValue()).updateById(); + + return Result.success(masterResult); + } + } else if (type.equalsIgnoreCase(Constant.View)) { + //鑾峰彇瑙嗗浘淇℃伅 + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + logs.setName(sysView.getName()); + logs.updateById(); + //妫�楠屾槸鍚︽縺娲� + Boolean active = sysView.getActive(); + if (!active) { + return Result.error(CodeMsg.Active_UN_ERROR); + } + //鑾峰彇鐞嗚涓婄殑璁板綍鏁� + initPageInfo = viewService.getInitPageInfo(sysView.getId()); + if (initPageInfo == null) { + long time = new Date().getTime(); + logs.setSchedule(time - logs.getCreateTime().getTime()).setStatus("true").setTotal(Long.valueOf(initPageInfo.getRecordCount()).intValue()).updateById(); + return Result.success(null); + } + //閫氳繃beginNo锛� endNo鏇存柊璁板綍 + boolean b = refreshInitPage(initPageInfo, beginNo, endNo); + if(!b) { + logs.setErrorInfo(CodeMsg.ERROR_SIZE_TOO_LONG.getMsg()).updateById(); + return Result.error(CodeMsg.ERROR_SIZE_TOO_LONG); + } + //鑾峰彇瑙嗗浘鏁版嵁 + Result viewData = viewService.getViewData(sysView, null, 0, initPageInfo); + //鏇存柊璁板綍鏃ュ織 + long time = new Date().getTime(); + logs.setSchedule(time - logs.getCreateTime().getTime()).setStatus("true").setTotal(Long.valueOf(initPageInfo.getRecordCount()).intValue()).updateById(); + return viewData; + } else { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + + } + /** + * + * @description: 閫氳繃biginNo endNo 鏇存柊page + * @param initPageInfo 椤垫暟淇℃伅瀹炰綋 + * @param beginNo 寮�濮嬫潯鏁� + * @param endNo 缁撴潫鏉℃暟 + * @return: 鍒锋柊鎴愬姛/澶辫触 + * + */ + private boolean refreshInitPage(com.highdatas.mdm.pojo.Page initPageInfo, Integer beginNo, Integer endNo) { + //姣忛〉鏉℃暟 + int size = endNo - beginNo; + int pageSize = initPageInfo.getPageSize(); + //姣忛〉鏁版嵁杩囧 涓嶅噯缁х画鎵ц + if (pageSize < size) { + return false; + } + //鏇存柊page淇℃伅 + initPageInfo.setBeginNo(beginNo); + initPageInfo.setEndNo(endNo); + initPageInfo.setPageSize(size); + initPageInfo.setRecordCount(size); + return true; + } + /** + * + * @description: 椤甸潰璋冪敤鍒嗗彂鎺ュ彛 澶氶�� + * @param objectList + * userId 鍒嗗彂鐢ㄦ埛 + * datas + * [ + * dataId 鍒嗗彂鐨刣ataId + * type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * increment 澧為噺/鍏ㄩ噺 + * ] + * + * @return: 鏄惁娣诲姞鍒伴槦鍒� + * + */ + @RequestMapping(value = "/dispense/surface/muti", method = RequestMethod.POST) + public Result surface(@RequestBody JSONObject objectList, HttpServletRequest request, HttpServletResponse response) { + //鑾峰彇鐢ㄦ埛淇℃伅 + String userId = objectList.getString("userId"); + //澶氫釜浠诲姟鐨勬暟鎹� + JSONArray datas = objectList.getJSONArray("datas"); + ArrayList<Result> results = new ArrayList<>(); + for (int i = 0; i < datas.size(); i++) { + JSONObject oneRequest = datas.getJSONObject(i); + String type = oneRequest.getString("type"); + String dataId = oneRequest.getString("dataId"); + String versionId = oneRequest.getString("versionId"); + //寰幆鍔犲埌鍒嗗彂闃熷垪閲� + Result result = addPassiveMq(userId, type, dataId, versionId, request, "muti"); + results.add(result); + } +// 杩斿洖姣忔潯鎵ц鐨勭粨鏋� + return Result.success(results); + + } + /** + * + * @description: 椤甸潰璋冪敤鍒嗗彂鎺ュ彛 + * @param userId 鍒嗗彂鐢ㄦ埛 + * @param dataId 鍒嗗彂鐨刣ataId + * @param type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * @param increment 澧為噺/鍏ㄩ噺 + * @param touchType 璇锋眰鏉ユ簮鐨勭被鍨� + * @return: 鏄惁娣诲姞鍒伴槦鍒� + * + */ + private Result addPassiveMq(@RequestParam String userId, @RequestParam String type, @RequestParam String dataId, String versionId, HttpServletRequest request, String touchType) { + //鍒涘缓鍒嗗彂鏃ュ織 + SysDispenseLogs logs = new SysDispenseLogs() + .setId(DbUtils.getUUID()) + .setTouchType(touchType) + .setDataType(type) + .setCreateTime(new Date()) + .setTopicId(type) + .setTagId(dataId) + .setMaintainId(versionId); + logs.insert(); + //鑾峰彇鐢ㄦ埛淇℃伅 + TUser user = DbUtils.getUserById(userId); + if (user == null) { + logs.setResult(CodeMsg.USER_NOT_MATHED.getMsg()).updateById(); + return Result.error(CodeMsg.USER_NOT_MATHED); + } + logs.setUserName(user.getUserName()); + logs.updateById(); + //鏄惁澧為噺 + String incrementStr = request.getParameter("increment"); + boolean increment = true; + if (!StringUtils.isEmpty(incrementStr)) { + increment = Boolean.valueOf(incrementStr); + } + //鍒涘缓MQ浠诲姟 + MqEntity mqEntity = new MqEntity(); + mqEntity.setUserId(userId); + mqEntity.setIncrement(increment); + mqEntity.setMsgTopicName(type); + mqEntity.setType(type); + mqEntity.setLogId(logs.getId()); + mqEntity.setDataId(dataId); + if(type.equalsIgnoreCase(Constant.Master)) { + //涓婚鐨勯渶瑕佹楠岀増鏈俊鎭� + if (StringUtils.isEmpty(versionId)) { + logs.setResult(CodeMsg.ERROR_PARAMS_NOT_MATHED.getMsg()).updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鑾峰彇鐗堟湰淇℃伅 + Maintain maintain = maintainService.selectById(versionId); + if (maintain == null) { + logs.setResult(CodeMsg.ERROR_PARAMS_NOT_MATHED.getMsg()).updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + logs.setVersion(maintain.getVersion()); + logs.updateById(); + mqEntity.setMaintainId(versionId); + //鑾峰彇涓婚淇℃伅 + SysMenu sysMenu = menuService.selectById(dataId); + if (sysMenu == null) { + logs.setResult(CodeMsg.SELECT_ERROR_NOTFOUND.getMsg()).updateById(); + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + logs.setName(sysMenu.getName()); + logs.updateById(); + //鏍¢獙鏄惁婵�娲� + int i = masterAuthorUnactiveService.selectCount(new EntityWrapper<MasterAuthorUnactive>().eq("maintain_id", versionId).eq("user_id", userId)); + if (i > 0) { + logs.setResult(CodeMsg.Active_UN_ERROR.getMsg()).updateById(); + return Result.error(CodeMsg.Active_UN_ERROR); + } + + mqEntity.setMsgTagName(sysMenu.getId()); + } else if (type.equalsIgnoreCase(Constant.View)) { + //鑾峰彇瑙嗗浘淇℃伅 + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + logs.setResult(CodeMsg.SELECT_ERROR_NOTFOUND.getMsg()).updateById(); + return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); + } + logs.setName(sysView.getName()); + logs.updateById(); + //鏍¢獙鏄惁婵�娲� + Boolean active = sysView.getActive(); + if (!active) { + logs.setResult(CodeMsg.Active_UN_ERROR.getMsg()).updateById(); + return Result.error(CodeMsg.Active_UN_ERROR); + } + mqEntity.setMsgTagName(sysView.getId()); + } else { + logs.setResult(CodeMsg.ERROR_PARAMS_NOT_MATHED.getMsg()).updateById(); + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鍒涘缓msgKey + mqEntity.setMsgKey(DbUtils.getUUID(16)); + MqEntity.MsgBodyBean msgBody = mqEntity.getMsgBody(); + msgBody.setTo(userId); + msgBody.setVersion(versionId); + MqMessage mqMessage = new MqMessage(mqEntity); + //淇濆瓨鏃ュ織id 鏂逛究鍚庣画鑾峰彇 + mqEntity.setLogId(logs.getId()); + //娣诲姞鍒拌鍔ㄥ垎鍙戦槦鍒� + return dispenseService.pushPassiveMq(mqMessage, touchType, logs);//琚姩杩斿洖 +// dispenseService.pushActiveMq(mqMessage); 涓诲姩鎺� + } + /** + * + * @description: 澶栭儴绯荤粺璋冪敤鍒嗗彂鎺ュ彛 + * @param token 鍒嗗彂鐢ㄦ埛token + * @param dataId 鍒嗗彂鐨刣ataId + * @param type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * @param versionId 鐗堟湰id + * @return: 鏄惁娣诲姞鍒伴槦鍒� + * + */ + @RequestMapping(value = "/dispense/api", method = RequestMethod.GET) + public Result api(@RequestParam String token, @RequestParam String type, @RequestParam String dataId, HttpServletRequest request, HttpServletResponse response) { + //閫氳繃token鑾峰彇鐢ㄦ埛淇℃伅 + String userId = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(userId)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + //鑾峰彇鐗堟湰淇℃伅 + String versionId = request.getParameter("versionId"); + //娣诲姞鍒板垎鍙戦槦鍒� + return addPassiveMq(userId, type, dataId, versionId, request, "api"); + } + /** + * + * @description: 澶栭儴绯荤粺璋冪敤 娉ㄥ唽鎺ュ彛 + * @param token 鍒嗗彂鐢ㄦ埛 + * @param dataId 鍒嗗彂鐨刣ataId + * @param type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ @RequestMapping(value = "/add", method = RequestMethod.GET) - public void getAll(@RequestParam String code, HttpServletResponse response) { - dispenseService.pushPassiveMq(new MqMessage( code, response)); + public Result add(@RequestParam String token, @RequestParam String type, @RequestParam String dataId) { + try{ + //鑾峰彇鐢ㄦ埛淇℃伅 + String redisVal = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(redisVal)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + if(type.equalsIgnoreCase(Constant.Master)) { + //鑾峰彇鏉冮檺 + MasterAuthor masterAuthor = masterAuthorService.selectById(dataId); + if (masterAuthor == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鍒涘缓娉ㄥ唽淇℃伅 + boolean updated = new MasterAuthorSubscribe().setId(DbUtils.getUUID()).setMenuId(masterAuthor.getId()).setUserId(redisVal).insert(); + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else if (type.equalsIgnoreCase(Constant.View)) { + //鑾峰彇瑙嗗浘淇℃伅 + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //娉ㄥ唽瑙嗗浘 + boolean updated = sysView.setSubscribe(true).updateById(); + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + } + catch (Exception e) { + e.printStackTrace(); + return Result.error(CodeMsg.ERROR_SAVE_TOKEN); + } } - @RequestMapping(value = "/test", method = RequestMethod.GET) - public String test(@RequestParam String tableName, HttpServletRequest request) { - TUser user = DbUtils.getUser(request); - List<String> size = new ArrayList<>(); - String s = masterDataService.selectByVersionSql(user, tableName, size, Constant.WHERE_DEFAULT, "V1.0", false); - return s; + /** + * + * @description: 澶栭儴绯荤粺璋冪敤鎵归噺 娉ㄥ唽鎺ュ彛 + * @param token 鍒嗗彂鐢ㄦ埛 + * @param datalist 鍒嗗彂鐨刣ataList + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ + @RequestMapping(value = "/refreshList", method = RequestMethod.POST) + public Result refreshList(@RequestBody JSONObject requestBody) { + //閫氳繃token鑾峰彇鐢ㄦ埛淇℃伅 + String token = requestBody.getString(Constant.Token); + if (StringUtils.isEmpty(token)) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + try{ + String userId = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(userId)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + //鏍¢獙datalist + JSONArray dataList = requestBody.getJSONArray("dataList"); + if (dataList == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //un subscribe + //鍒犻櫎褰撳墠鐢ㄦ埛鎵�鏈夌殑娉ㄥ唽淇℃伅 + List<SysView> sysViews = viewService.selectList(new EntityWrapper<SysView>().eq(Constant.USERID, userId)); + for (SysView sysView : sysViews) { + sysView.setSubscribe(false).updateById(); + } + + masterAuthorSubscribeService.delete(new EntityWrapper<MasterAuthorSubscribe>().eq(Constant.USERID, userId)); + + //寰幆娣诲姞鏂扮殑娉ㄥ唽淇℃伅 + for (int i = 0; i < dataList.size(); i++) { + JSONObject oneObj = dataList.getJSONObject(i); + String dataId = oneObj.getString("dataId"); + String type = oneObj.getString("type"); + if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(type)) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + if(type.equalsIgnoreCase(Constant.Master)) { + //鏍¢獙鏄惁鏈夋潈闄� + MasterAuthor masterAuthor = masterAuthorService.selectById(dataId); + if (masterAuthor == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //娉ㄥ唽涓婚 + boolean updated = new MasterAuthorSubscribe().setId(DbUtils.getUUID()).setMenuId(masterAuthor.getId()).setUserId(userId).insert(); + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else if (type.equalsIgnoreCase(Constant.View)) { + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //娉ㄥ唽瑙嗗浘 + boolean updated = sysView.setSubscribe(true).updateById(); + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + } + return Result.success(null); + } + catch (Exception e) { + e.printStackTrace(); + return Result.error(CodeMsg.ERROR_SAVE_TOKEN); + } } + + /** + * + * @description: 澶栭儴绯荤粺璋冪敤 鍒犻櫎娉ㄥ唽鎺ュ彛 + * @param token 鍒嗗彂鐢ㄦ埛 + * @param dataId 鍒嗗彂鐨刣ataId + * @param type 鍒嗗彂绫诲瀷锛� 瑙嗗浘杩樻槸涓婚 + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ + @RequestMapping(value = "/delete", method = RequestMethod.GET) + public Result delete(@RequestParam String token, @RequestParam String type, @RequestParam String dataId) { + try{ + //鑾峰彇鐢ㄦ埛淇℃伅閫氳繃token + String redisVal = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(redisVal)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + if(type.equalsIgnoreCase(Constant.Master)) { + //鏍¢獙鏉冮檺 + MasterAuthor masterAuthor = masterAuthorService.selectById(dataId); + if (masterAuthor == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鍒犻櫎娉ㄥ唽 + boolean updated = masterAuthorSubscribeService.delete(new EntityWrapper<MasterAuthorSubscribe>().eq("master_author_id", masterAuthor.getId()).eq(Constant.USERID, redisVal)); + + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else if (type.equalsIgnoreCase(Constant.View)) { + SysView sysView = viewService.selectById(dataId); + if (sysView == null) { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + //鍒犻櫎瑙嗗浘 + boolean updated = sysView.setSubscribe(false).updateById(); + if (updated) { + return Result.success(null); + } else { + return Result.error(CodeMsg.SUBSCRIBE_SAVE_ERROR); + } + } else { + return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); + } + } + catch (Exception e) { + e.printStackTrace(); + return Result.error(CodeMsg.ERROR_SAVE_TOKEN); + } + } + /** + * + * @description: 澶栭儴绯荤粺璋冪敤 鑾峰彇鍙敞鍐屾暟鎹垪琛ㄦ帴鍙� + * @param token 鍒嗗彂鐢ㄦ埛 + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ + @RequestMapping(value = "/authors", method = RequestMethod.GET) + public Result authors(@RequestParam String token) { + try{ + //閫氳繃token鑾峰彇鐢ㄦ埛淇℃伅 + String userId = redisClient.getRedisVal(token); + if (StringUtils.isEmpty(userId)) { + return Result.error(CodeMsg.ERROR_FIND_TOKEN); + } + TUser user = DbUtils.getUserById(userId); + if (user == null) { + return Result.error(CodeMsg.USER_NOT_MATHED); + } + List<SubscribeEntity> result = new ArrayList<>(); + + + //鑾峰彇鐢ㄦ埛鏉冮檺 + List<MasterAuthor> userAuthor = masterAuthorService.getUserAuthor(userId, null); + // author 鍙湁鎷ユ湁鏈�鏂版潈闄愮殑鎵嶈兘璁㈤槄 + userAuthor = userAuthor.stream() + .filter(masterAuthor -> !StringUtils.isEmpty(masterAuthor.getMaintainFieldId())) +// .filter(masterAuthor -> masterAuthor.getMaintainFieldId().equalsIgnoreCase(Constant.All)) + .collect(Collectors.toList()); + + for (MasterAuthor masterAuthor : userAuthor) { + SubscribeEntity subscribeEntity = new SubscribeEntity(); + //鑾峰彇鐗堟湰list + List<Maintain> versionList = maintainFieldService.getMaintainByMaintainField(masterAuthor.getMaintainFieldId(), masterAuthor.getTableName()); + if (versionList != null && !versionList.isEmpty()) { + //鐗堟湰鎺掑簭 鍊掑簭 + Collections.sort(versionList, new Comparator<Maintain>() { + @Override + public int compare(Maintain o1, Maintain o2) { + return o2.getOrderNo().compareTo(o1.getOrderNo()); + } + }); + ArrayList<JSONObject> jsonObjects = new ArrayList<>(); + for (Maintain maintain : versionList) { + JSONObject object = new JSONObject(); + object.fluentPut("id", maintain.getId()); + object.fluentPut("version", maintain.getVersion()); + jsonObjects.add(object); + } + //缁勮杩斿洖淇℃伅 + subscribeEntity.setVersionList(jsonObjects); + } + //娣诲姞褰撳墠杩斿洖鐨勬暟鎹被鍨嬩负涓婚 + subscribeEntity.setType(Constant.Master); + String menuId = masterAuthor.getMenuId(); + SysMenu sysMenu = menuService.selectById(menuId); + if (sysMenu == null) { + continue; + } + subscribeEntity.setId(sysMenu.getId()); + subscribeEntity.setName(sysMenu.getName()); + + String maintainFieldId = masterAuthor.getMaintainFieldId(); + String tableName = masterAuthor.getTableName(); + //鑾峰彇褰撳墠鐗堟湰淇℃伅閫氳繃鏉冮檺锛屼富棰� + Maintain nowVersion = maintainService.getNowVersion(tableName); + if (nowVersion == null) { + continue; + } + List<Maintain> maintainByMaintainField = maintainFieldService.getMaintainByMaintainField(maintainFieldId, tableName); + //鏍¢獙鏉冮檺鏄惁鍖呭惈鏈�鏂扮増鏈� + long count = maintainByMaintainField.stream().filter(maintain -> maintain.getId().equalsIgnoreCase(nowVersion.getId())).count(); + if (count == 1) { + result.add(subscribeEntity); + } + + } + + //view 鍙敞鍐岀殑瑙嗗浘淇℃伅 + List<SysView> sysViews = viewService.selectList(new EntityWrapper<SysView>().eq(Constant.USERID, userId)); + List<SubscribeEntity> viewList = sysViews.stream() + .map(view -> new SubscribeEntity().setId(view.getId()).setName(view.getName()).setType(Constant.View)) + .collect(Collectors.toList()); + result.addAll(viewList); + + return Result.success(result); + } + catch (Exception e) { + e.printStackTrace(); + return Result.error(CodeMsg.ERROR_SAVE_TOKEN); + } + + } + + /** + * + * @description: 澶栭儴绯荤粺璋冪敤 鑾峰彇token淇℃伅 + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ @RequestMapping(value = "/login", method = RequestMethod.GET) public Result login(HttpServletRequest request) { + //璇锋眰澶撮噷鑾峰彇鐢ㄦ埛淇℃伅 TUser user = DbUtils.getUser(request); String token = DbUtils.getUUID(32); - boolean b = redisClient.putRedisVal(user.getId(), token); + //淇濆瓨redis鍐咃紝榛樿 瓒呮椂鏃堕棿30Min + boolean b = redisClient.putRedisVal(token, user.getId()); if (b) { return Result.success(token); }else { return Result.success(CodeMsg.ERROR_SAVE_TOKEN); } } + + + + /** + * + * @description: 鍒嗛〉鑾峰彇鏃ュ織淇℃伅 + * @param pageNo 椤垫暟 + * @param touchType 璇锋眰绫诲瀷 + * @param pageSize 姣忛〉鏉℃暟 + * @return: 鏄惁娣诲姞鎴愬姛 + * + */ + @RequestMapping(value = "/log/all/{pageNo}", method = RequestMethod.GET) + public Result login( @PathVariable int pageNo, HttpServletRequest request) throws ParseException { + String pageSizeStr = request.getParameter("pageSize"); + String touchType = request.getParameter("touchType"); + int pageSize = 15; + if (!StringUtils.isEmpty(pageSizeStr)) { + pageSize = Integer.valueOf(pageSizeStr); + } + Wrapper<SysDispenseLogs> wrapper = new EntityWrapper<SysDispenseLogs>(); + if (!StringUtils.isEmpty(touchType)) { + if ("sys".equalsIgnoreCase(touchType)) { + //椤甸潰鐐瑰嚮+绯荤粺涓诲姩鍒嗗彂鐨勪负鍒嗗彂鍒楄〃 + ArrayList<String> strings = new ArrayList<>(); + strings.add("muti"); + strings.add("sys"); + strings.add("surface"); + wrapper.in("touch_type", strings); + } else { + //澶栭儴绯荤粺璋冪敤涓鸿皟鐢ㄥ垪琛� + ArrayList<String> strings = new ArrayList<>(); + strings.add("api"); + strings.add("rest"); + wrapper.in("touch_type", strings); + } + } + //绛涢��--鏁版嵁绫诲瀷 + String dataType = request.getParameter("dataType"); + if (!StringUtils.isEmpty(dataType)) { + wrapper.eq("data_type", dataType); + } + //绛涢��--鐢ㄦ埛 + String userId = request.getParameter("userId"); + if (!StringUtils.isEmpty(userId)) { + wrapper.eq("user_id", userId); + } +// 绛涢��-- 涓婚 + String name = request.getParameter("name"); + if (!StringUtils.isEmpty(name)) { + wrapper.like("name", name); + } + //绛涢��-- 涓婚id鎴栬�呰鍥緄d + String tagId = request.getParameter("tagId"); + if (!StringUtils.isEmpty(tagId)) { + wrapper.eq("tag_id", tagId); + } + //绛涢��-- 涓婚鐗堟湰 + String maintainId = request.getParameter("maintainId"); + if (!StringUtils.isEmpty(maintainId)) { + wrapper.eq("maintain_id", maintainId); + } + //绛涢��--鍒嗗彂鐘舵�� + String status = request.getParameter("status"); + if (!StringUtils.isEmpty(status)) { + wrapper.eq("status", status); + } + //--BY 鏃堕棿娈电瓫閫� + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String startTime = request.getParameter("startTime"); + if (!StringUtils.isEmpty(startTime)) { + Date start = simpleDateFormat.parse(startTime); + wrapper.ge("create_time", start); + } + String endTime = request.getParameter("endTime"); + if (!StringUtils.isEmpty(endTime)) { + Date end = simpleDateFormat.parse(endTime); + wrapper.le("create_time", end); + } + + Page<SysDispenseLogs> page = new Page<>(pageNo, pageSize); + //鍒涘缓鏃堕棿鍊掑彊 + wrapper.orderBy("create_time desc"); + Page<SysDispenseLogs> sysDispenseLogsPage = dispenseLogsService.selectPage(page, wrapper); + + return Result.success(sysDispenseLogsPage); + } } -- Gitblit v1.8.0