import Ignore_ExecPageFlipper as ExecPageFlipper import com.dderp.business.dao.ProductDao import com.dderp.common.api.NoSqlKeysService import com.dderp.common.datas.RedisKeys import com.dderp.common.entity.product.ProductParameter import com.dderp.common.tool.ERPUtils import com.dySweetFishPlugin.redis.RedisService import com.dySweetFishPlugin.sql.TableCodeNode import com.dySweetFishPlugin.sql.TableIdNode import com.dySweetFishPlugin.sql.TableIdService import com.sweetfish.convert.json.JsonConvert import com.sweetfish.source.PageFlipper import org.apache.commons.lang3.StringUtils import org.rex.RMap static def createRunnable(TableIdService tableIdService, RedisService redisService, NoSqlKeysService keysService, ProductDao productDao, JsonConvert jsonConvert, String sysRunMode, String dataSourceId, long supplierCode) { return { redisService.del(keysService.getRedisKey(RedisKeys.KEY_PRODUCT_PARAMETER, supplierCode)) RMap params = new RMap() ExecPageFlipper.execute(300, { PageFlipper p -> List productParameterList = productDao.selectProductParameter(params, p, dataSourceId, supplierCode) if (!productParameterList.isEmpty()) { Map productParameterHashMap = productParameterList.collectEntries { [String.valueOf(it.id), jsonConvert.convertTo(it)] } redisService.hmset(keysService.getRedisKey(RedisKeys.KEY_PRODUCT_PARAMETER, supplierCode), productParameterHashMap) } }) String json = redisService.hget(keysService.getRedisKey(RedisKeys.KEY_PRODUCT_PARAMETER, supplierCode), String.valueOf(ERPUtils.RESERVE_PRODUCT_PARAMETER_ID)) ProductParameter reserveParameter = (StringUtils.isBlank(json)) ? null : jsonConvert.convertFromO(ProductParameter.class, json) as ProductParameter if ("ProductCenter".equalsIgnoreCase(sysRunMode)) { //产品中心模式,查看有没有 保留的产品参数,有则需要删除 if (reserveParameter != null) { productDao.deleteProductParameter(reserveParameter, dataSourceId, supplierCode) redisService.hdel(keysService.getRedisKey(RedisKeys.KEY_PRODUCT_PARAMETER, supplierCode), String.valueOf(ERPUtils.RESERVE_PRODUCT_PARAMETER_ID)) //还需要刷新下tableId tableIdService.addTableIdNode(TableIdNode.newBuilder() .idName("tbProductParameter.id") .tableName("tbProductParameter") .idFieldName("id") .build(), dataSourceId, String.valueOf(supplierCode)) } } else { //如果是其它模式,则增加一条记录 if (reserveParameter == null) { reserveParameter = new ProductParameter() reserveParameter.id = ERPUtils.RESERVE_PRODUCT_PARAMETER_ID reserveParameter.parameterName = "系统分界线参数" reserveParameter.parameterFieldPart = "" reserveParameter.parameterFieldOrder = "" reserveParameter.fieldType = 1 reserveParameter.selectKind = 0 reserveParameter.idDictType = 0L reserveParameter.voidFlag = 1 ProductParameter.create(reserveParameter, 0L) productDao.addProductParameterSync(reserveParameter, dataSourceId, supplierCode) redisService.hset(keysService.getRedisKey(RedisKeys.KEY_PRODUCT_PARAMETER, supplierCode), String.valueOf(reserveParameter.id), jsonConvert.convertTo(reserveParameter)) //还需要刷新下tableId tableIdService.addTableIdNode(TableIdNode.newBuilder() .idName("tbProductParameter.id") .tableName("tbProductParameter") .idFieldName("id") .build(), dataSourceId, String.valueOf(supplierCode)) } } } as Runnable } //groovy最后一个表达式的值为返回 createRunnable(tableIdService, redisService, keysService, productDao, jsonConvert, sysRunMode, dataSourceId, supplierCode)