name.sql 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. CREATE DEFINER=`root`@`%` PROCEDURE `updatedownloadprojname`(
  2. pastureidIN BIGINT (20),
  3. dateIN VARCHAR(50)
  4. )
  5. label:BEGIN
  6. DECLARE positionIdS
  7. INT (20);
  8. DECLARE
  9. positionNameS VARCHAR (100);
  10. DECLARE i,amount,sorts,amountsl,sortssl,havebuttons,havebuttond1 INT(11) DEFAULT 0;
  11. DECLARE msg1 TEXT;
  12. DECLARE code1 CHAR(5) DEFAULT '00000';
  13. DECLARE ids,projnames,temstr,tem,pids,idssl varCHAR(30);
  14. DECLARE t_error INTEGER DEFAULT 0;
  15. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
  16. BEGIN
  17. -- 获取异常code,异常信息
  18. GET DIAGNOSTICS CONDITION 1
  19. code1 = RETURNED_SQLSTATE, msg1 = MESSAGE_TEXT;
  20. END;
  21. #开启事务
  22. START TRANSACTION;
  23. select 1 into tem;
  24. SELECT '' INTO temstr;
  25. SELECT 0 INTO sorts;
  26. SELECT count(*) into amount FROM downloadedplan
  27. WHERE mydate = dateIN AND pastureid = pastureidIN ;
  28. WHILE amount > 0 DO
  29. SELECT amount-1 INTO amount;
  30. SELECT id,projname,pid,havebuttons INTO ids,projnames,pids,havebuttons FROM downloadedplan
  31. WHERE mydate = dateIN AND pastureid = pastureidIN
  32. ORDER BY projname,id ASC LIMIT sorts,1;
  33. IF(length(projnames) = 6) and havebuttons = 0
  34. THEN
  35. SELECT '1' INTO tem;
  36. SELECT LEFT(projnames,2) INTO temstr;
  37. WHILE (SELECT COUNT(*) FROM downloadedplan WHERE pastureid=pastureidIN and mydate = dateIN AND projname = CONCAT(LEFT(temstr,2),LPAD(tem,3,'0')))>0 do
  38. SELECT tem+1 INTO tem;
  39. end WHILE;
  40. UPDATE downloadedplan
  41. SET projname = CONCAT(LEFT(projname,2),LPAD(tem,3,'0'))
  42. WHERE pastureid=pastureidIN AND id = ids;
  43. END IF;
  44. select count(1) into amountsl FROM downloadedplan WHERE pastureid=pastureidIN and mydate = dateIN AND length(projname) > 6 and pid = pids;
  45. -- --
  46. SELECT 0 INTO sortssl;
  47. select projname into projnames from downloadedplan where id = ids;
  48. if length(projnames) < 6 THEN
  49. -- select projnames;
  50. WHILE amountsl > 0 DO
  51. SELECT 0 INTO havebuttond1;
  52. --
  53. select id,havebutton into idssl,havebuttond1 FROM downloadedplan WHERE pastureid=pastureidIN and mydate = dateIN AND length(projname) > 6 and pid = pids ORDER BY projname,id ASC LIMIT sortssl,1;
  54. --
  55. SELECT sortssl + 1 INTO sortssl;
  56. if havebuttond1 = 0 THEN
  57. UPDATE downloadedplan
  58. SET projname = CONCAT(projnames,'.', sortssl)
  59. WHERE pastureid=pastureidIN AND id = idssl;
  60. END IF;
  61. SELECT amountsl-1 INTO amountsl;
  62. END WHILE;
  63. END IF;
  64. SELECT sorts + 1 INTO sorts;
  65. END WHILE;
  66. SELECT 0 INTO sorts;
  67. SELECT 0 INTO amount;
  68. SELECT count(*) into amount FROM downloadedplan
  69. WHERE mydate = dateIN AND pastureid = pastureidIN ;
  70. WHILE amount > 0 DO
  71. SELECT id INTO ids FROM downloadedplan
  72. WHERE mydate = dateIN AND pastureid = pastureidIN
  73. ORDER BY projname asc limit sorts,1;
  74. SELECT sorts+1 INTO sorts;
  75. UPDATE downloadedplan
  76. SET sort = sorts
  77. WHERE pastureid=pastureidIN AND id = ids;
  78. SELECT amount-1 INTO amount;
  79. END WHILE;
  80. -- SELECT count(*) into amount FROM downloadedplan
  81. -- WHERE mydate = dateIN AND pastureid = pastureidIN and length(projname)>5
  82. -- ORDER BY projname,id asc;
  83. --
  84. --
  85. -- update downloadedplan
  86. -- set sort = 200 + sort
  87. -- WHERE pastureid=pastureidIN AND mydate = dateIN and LENGTH(projname)>5;
  88. --
  89. -- WHILE amount > 0 DO
  90. -- SELECT amount-1 INTO amount;
  91. --
  92. -- SELECT id,projname INTO ids,projnames FROM downloadedplan
  93. -- WHERE mydate = dateIN AND pastureid = pastureidIN AND LENGTH(projname)>5
  94. -- ORDER BY projname,id ASC LIMIT 1;
  95. --
  96. --
  97. --
  98. -- IF(temstr<>LEFT(projnames,2))
  99. -- THEN
  100. -- SELECT '1' INTO tem;
  101. -- SELECT LEFT(projnames,2) INTO temstr;
  102. -- END IF;
  103. --
  104. -- WHILE (SELECT COUNT(*) FROM downloadedplan WHERE pastureid=pastureidIN and mydate = dateIN AND projname = CONCAT(LEFT(temstr,2),LPAD(tem,3,'0')))>0 do
  105. -- SELECT tem+1 INTO tem;
  106. -- end WHILE;
  107. --
  108. -- WHILE (SELECT COUNT(*) FROM downloadedplan WHERE pastureid=pastureidIN AND mydate = dateIN AND sort = sorts)>0 DO
  109. -- SELECT sorts+1 INTO sorts;
  110. -- END WHILE;
  111. --
  112. -- UPDATE downloadedplan
  113. -- SET projname = CONCAT(LEFT(projname,2),LPAD(tem,3,'0')),
  114. -- sort = sorts
  115. -- WHERE pastureid=pastureidIN AND id = ids;
  116. --
  117. -- SELECT tem+1 INTO tem;
  118. -- SELECT sorts+1 INTO sorts;
  119. --
  120. -- END WHILE;
  121. IF code1 = '00000' THEN
  122. COMMIT;
  123. SELECT
  124. 'success' msg;
  125. ELSE
  126. ROLLBACK;
  127. SELECT
  128. msg1 msg;
  129. END IF;
  130. END