Advertisement
hecrus

Generate image from JSON (Outer command)

Oct 24th, 2020
2,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 3.37 KB | None | 0 0
  1. CREATE PROCEDURE [dbo].[fm_tst-generate-coupon_saveItem]
  2.    @username nvarchar(256),
  3.    @itemID int,
  4.    @parameters ExtendedDictionaryParameter READONLY
  5.    -- либо перечислить все поля в форме (@fieldcode и т.д.) 
  6. AS
  7. BEGIN
  8.     -- сохраняем форму (добавление/обновление некой сущности)
  9.     declare @langID int
  10.     select @langID = try_cast(Value as int) from @parameters where [Key] = 'langID'
  11.  
  12.  
  13.     declare @pdiscount nvarchar(max)
  14.     select @pdiscount = Value2 from @parameters where [key]='discount'
  15.     declare @ptext nvarchar(max)
  16.     select @ptext = Value2 from @parameters where [key]='text'
  17.     declare @pdays int
  18.     select @pdays = try_cast(Value2 as int) from @parameters where [key]='days'
  19.  
  20.  
  21.     declare @url nvarchar(256) = '/uploads/'+convert(nvarchar(128), newid())+'.png',
  22.         @backImg nvarchar(128) = '/uploads/gen-images/coupon.jpg',
  23.         @date nvarchar(128) = convert(nvarchar, dateadd(day, isnull(@pdays, 0), getdate() ), 104)
  24.  
  25.    
  26.  
  27.    
  28.     -- SELECT 1 (Result, Msg, SuccessUrl, HideFormAfterSubmit, RefreshContainer)
  29.     select 1 Result, '<a href="'+@url+'" target="_blank" >' +iif(@langID=1, 'Coupon link - ', 'Картинка - ') +@url+'</a>' Msg, '' SuccessUrl, 0 HideFormAfterSubmit, '' RefreshContainer
  30.  
  31.  
  32.  
  33.  
  34.  
  35.     -- SELECT 2 Вызов внешнего действия
  36.       select 'generateImage' type, '
  37.    {
  38.        "options":{
  39.         "path":"'+@url+'",
  40.         "width":"735",
  41.         "height":"354",
  42.         "backColor":"#fff",
  43.        },
  44.        "render": [
  45.             {
  46.                 "type": "image",
  47.                 "path":"'+@backImg+'",
  48.                 "x":"0",
  49.                 "y":"0",
  50.                 "width":"735",
  51.                 "height":"354",
  52.                 "opacity":"1"
  53.             },
  54.            {
  55.                 "type": "text",
  56.                 "text":"'+iif(@langID=1, 'Discount', 'Скидка')+' '+@pdiscount+'%",
  57.                 "x":"30",
  58.                 "y":"120",
  59.                 "width":"400",
  60.                 "height":"120",
  61.                 "color":"#fff",
  62.                 "backColor":"",
  63.                 "fontSize":"38",
  64.                 "fontFamily":"Verdana"
  65.            },        
  66.            {
  67.                 "type": "line",
  68.                 "x1":"20",
  69.                 "y1":"190",
  70.                 "x2":"380",
  71.                 "y2":"190",
  72.                 "thickness":"1",
  73.                 "color":"white"
  74.             },
  75.            {
  76.                 "type": "text",
  77.                 "text":"'+iif(@langID=1, 'Coupon 124322', 'Купон 1234241')+'",
  78.                 "x":"120",
  79.                 "y":"200",
  80.                 "width":"400",
  81.                 "height":"120",
  82.                 "color":"#fff",
  83.                 "backColor":"",
  84.                 "fontSize":"18",
  85.                 "fontFamily":"Verdana"
  86.            },
  87.            {
  88.                 "type": "text",
  89.                 "text":"'+iif(@langID=1, 'Active till ', 'Действует до ')+' '+@date+'",
  90.                 "x":"20",
  91.                 "y":"10",
  92.                 "width":"400",
  93.                 "height":"120",
  94.                 "color":"#fff",
  95.                 "backColor":"",
  96.                 "fontSize":"10",
  97.                 "fontFamily":"Verdana"
  98.            },
  99.            {
  100.                 "type": "text",
  101.                 "text":"'+iif(@langID=1, 'John Smith Ltd', 'ИП Иванов И.И. ОГРН 12355152413123')+'",
  102.                 "x":"230",
  103.                 "y":"10",
  104.                 "width":"400",
  105.                 "height":"120",
  106.                 "color":"#000",
  107.                 "backColor":"",
  108.                 "fontSize":"10",
  109.                 "fontFamily":"Verdana"
  110.            },
  111.            {
  112.                 "type": "text",
  113.                 "text":"'+@ptext+'",
  114.                 "x":"20",
  115.                 "y":"300",
  116.                 "width":"400",
  117.                 "height":"120",
  118.                 "color":"#fff",
  119.                 "backColor":"",
  120.                 "fontSize":"7",
  121.                 "fontFamily":"Verdana"
  122.            }    
  123.            
  124.         ]          
  125.    }    
  126.    ' options
  127.    
  128.    
  129. END
  130.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement