v0001_feedtemplet.sql 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ALTER TABLE `feedtemplet`
  2. ADD COLUMN `is_modify` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否可修改 0 无效 1 是 2 否',
  3. ADD COLUMN `group_data_id` bigint(11) unsigned NOT NULL DEFAULT '0' COMMENT '集团端数据ID',
  4. ADD COLUMN `group_version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '集团端版本号';
  5. ALTER TABLE `ftdetail`
  6. ADD COLUMN `is_modify` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否可修改 0 无效 1 是 2 否',
  7. ADD COLUMN `is_show` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否显示 0 无效 1 显示 2 隐藏';
  8. ALTER TABLE cowclass ADD COLUMN group_id int(11) unsigned NOT NULL DEFAULT '0' COMMENT '集团端id';
  9. ALTER TABLE feedclass ADD COLUMN group_id int(11) unsigned NOT NULL DEFAULT '0' COMMENT '集团端id';
  10. ALTER TABLE USER ADD COLUMN `imei` VARCHAR(255) DEFAULT NULL;
  11. update feedtemplet set group_version = version;
  12. ## SELECT * FROM `apisql` where sqlname = 'getFTdetailList'
  13. SELECT
  14. TRIM(ftid)ftid,TRIM(fid)fid,
  15. IFNULL((SELECT fname FROM feed WHERE pastureid =ftdetail.pastureid AND id = ftdetail.fid),ftdetail. fname) fname,
  16. fweight,islockcount,sort,feedgroup,TRIM(preftid)preftid,autosecond,TRIM(splitftpreid)splitftpreid,
  17. TRIM(ftdetail.id) id,
  18. TRIM(ftdetail.pastureid)pastureid,IFNULL(deviation,0) AS deviation
  19. FROM
  20. ftdetail
  21. WHERE ftdetail.pastureid = ? AND ( ftid=?) AND is_show = 1
  22. AND ( fweight =? OR ? = '')
  23. AND ( autosecondname =? OR ? = '')
  24. AND (islockcount =? OR ? = '')
  25. AND (sort =? OR ? = '')
  26. AND ( fname LIKE CONCAT('%',?,'%') OR ? = '')
  27. AND ( feedgroup LIKE CONCAT('%',?,'%') OR ? = '')
  28. ORDER BY ftdetail.sort,ftdetail.id;
  29. ## SELECT * FROM apisql WHERE sqlname = 'getFTList' AND ENABLE >0
  30. ## 需要更新的语句如下
  31. SELECT * FROM ( SELECT
  32. tname,tcolor,ccid,ccname,fttype, remark,`enable`,source,fttypeid,tcode,is_modify,version,
  33. TRIM(id) id,
  34. TRIM(pastureid)pastureid,
  35. isissue,
  36. (SELECT GROUP_CONCAT( DISTINCT fp.`pastureName`) FROM feedtemplet_pasture fp
  37. WHERE fp.ftid=ft.`id` AND fp.pastureid =ft.pastureid ) grouppastures,
  38. (SELECT COUNT(1) FROM feedp WHERE pastureid = ft.pastureid AND (ptsfid = ft.id OR ftid = ft.id) LIMIT 1 ) AS state,
  39. IF((SELECT COUNT(1) FROM ftdetail_issue fi
  40. WHERE fi.pastureid = ft.pastureid AND fi.ftid = ft.id)+
  41. (SELECT COUNT(1)
  42. FROM `ftdetail` ftd
  43. WHERE ftd.pastureid = ft.pastureid AND ftd.ftid = ft.id)>0,1,0) AS isadjust,ft.sort
  44. FROM
  45. feedtemplet ft
  46. WHERE pastureid = ?
  47. AND (ccname LIKE CONCAT("%",?,"%") OR ?='')
  48. AND (tname LIKE CONCAT("%",?,"%") OR ?='')
  49. AND (fttype LIKE CONCAT("%",?,"%") OR ?='')
  50. ) f
  51. WHERE (f.enable = ? OR ? = '' ) AND (isadjust = ? OR ? = '') AND (source = IF( ? = 0 ,"自定义",IF (? = 1,"集团下发未调整",IF(? = 2,"集团下发有调整",IF(? = 3 ,"导入","")))) OR ? = '')
  52. ORDER BY f.id DESC;
  53. ## SELECT * FROM apisql WHERE sqlname ='updatesysopt'
  54. ## 需要更新的语句如下sqlstr
  55. UPDATE `sysopt`
  56. SET inforvalue = CASE inforname
  57. WHEN 'isGetLastPlan' THEN ?
  58. WHEN 'isGetNextPlan' THEN ?
  59. WHEN 'isEnableSupplyFeed' THEN ?
  60. WHEN 'isEnableRemainFeed' THEN ?
  61. WHEN 'reportDigit' THEN ?
  62. WHEN 'isLockCount' THEN ?
  63. WHEN 'remainOpt' THEN ?
  64. WHEN 'waterOpt' THEN ?
  65. WHEN 'overweightWarnRate' THEN ?
  66. WHEN 'overweightBanRate' THEN ?
  67. WHEN 'repertoryWarn' THEN ?
  68. WHEN 'isfeedstorage' THEN ?
  69. WHEN 'times' THEN ?
  70. WHEN 'isEnableContract' THEN ?
  71. WHEN 'remainOptDis' THEN ?
  72. WHEN 'remainOptRate' THEN round(?/100,2)
  73. WHEN 'isSmallMaterial' THEN ?
  74. WHEN 'decimalPlaces' THEN ?
  75. WHEN 'isDataSync' THEN ?
  76. WHEN 'anyCar' THEN ?
  77. WHEN 'decimalRate' THEN ?
  78. WHEN 'accuracy' THEN ?
  79. WHEN 'sprinkleFeedTimeAllow' THEN ?
  80. WHEN 'domain' THEN ?
  81. END
  82. WHERE pastureid= ?;
  83. ## 需要更新的语句如下params
  84. # isGetLastPlan,isGetNextPlan,isEnableSupplyFeed,isEnableRemainFeed,reportDigit,isLockCount,remainOpt,waterOpt,overweightWarnRate,overweightBanRate,repertoryWarn,isfeedstorage,times,isEnableContract,remainOptDis,remainOptRate,isSmallMaterial,decimalPlaces,isDataSync,anyCar,decimalRate,accuracy,sprinkleFeedTimeAllow,domain,pastureid
  85. ## setp 1 需要增加的语句
  86. INSERT INTO sysopt (pastureid,inforname,inforvalue )VALUES (1653271339,"sprinkleFeedTimeAllow","10"),(1653271339,"domain","http://192.168.1.70:8081");
  87. ## setp 2 SELECT * FROM apisql WHERE sqlname ='getysoptList'
  88. SELECT TRIM(pastureid) pastureid,
  89. MAX(CASE
  90. WHEN inforname = 'isGetLastPlan' THEN
  91. inforvalue
  92. END
  93. ) AS isGetLastPlan,
  94. MAX(CASE
  95. WHEN inforname = 'isGetNextPlan' THEN
  96. inforvalue
  97. END
  98. ) AS isGetNextPlan,
  99. MAX(CASE
  100. WHEN inforname = 'isEnableSupplyFeed' THEN
  101. inforvalue
  102. END
  103. ) AS isEnableSupplyFeed,
  104. MAX(CASE
  105. WHEN inforname = 'isEnableRemainFeed' THEN
  106. inforvalue
  107. END
  108. ) AS isEnableRemainFeed,
  109. MAX(CASE
  110. WHEN inforname = 'reportDigit' THEN
  111. inforvalue
  112. END
  113. ) AS reportDigit,
  114. MAX(CASE
  115. WHEN inforname = 'isLockCount' THEN
  116. inforvalue
  117. END
  118. ) AS isLockCount,
  119. MAX(CASE
  120. WHEN inforname = 'remainOpt' THEN
  121. inforvalue
  122. END
  123. ) AS remainOpt,
  124. MAX(CASE
  125. WHEN inforname = 'waterOpt' THEN
  126. inforvalue
  127. END
  128. ) AS waterOpt,
  129. MAX(CASE
  130. WHEN inforname = 'overweightWarnRate' THEN
  131. inforvalue
  132. END
  133. ) AS overweightWarnRate,
  134. MAX(CASE
  135. WHEN inforname = 'overweightBanRate' THEN
  136. inforvalue
  137. END
  138. ) AS overweightBanRate,
  139. MAX(CASE
  140. WHEN inforname = 'repertoryWarn' THEN
  141. inforvalue
  142. END
  143. ) AS repertoryWarn,
  144. MAX(CASE
  145. WHEN inforname = 'isfeedstorage' THEN
  146. inforvalue
  147. END
  148. ) AS isfeedstorage,
  149. MAX(CASE
  150. WHEN inforname = 'times' THEN
  151. inforvalue
  152. END
  153. ) AS times,
  154. MAX(CASE
  155. WHEN inforname = 'isEnableContract' THEN
  156. inforvalue
  157. END
  158. ) AS isEnableContract,
  159. MAX(CASE
  160. WHEN inforname = 'remainOptDis' THEN
  161. inforvalue
  162. END
  163. ) AS remainOptDis,
  164. MAX(CASE
  165. WHEN inforname = 'remainOptRate' THEN
  166. inforvalue*100
  167. END
  168. ) AS remainOptRate,
  169. MAX(CASE
  170. WHEN inforname = 'isSmallMaterial' THEN
  171. inforvalue
  172. END
  173. ) AS isSmallMaterial,
  174. MAX(CASE
  175. WHEN inforname = 'decimalPlaces' THEN
  176. inforvalue
  177. END
  178. ) AS decimalPlaces,
  179. MAX(CASE
  180. WHEN inforname = 'isDataSync' THEN
  181. inforvalue
  182. END
  183. ) AS isDataSync,
  184. MAX(CASE
  185. WHEN inforname = 'anyCar' THEN
  186. inforvalue
  187. END
  188. ) as anyCar,
  189. MAX(CASE
  190. WHEN inforname = 'decimalRate' THEN
  191. inforvalue
  192. END
  193. ) as decimalRate,
  194. MAX(CASE
  195. WHEN inforname = 'accuracy' THEN
  196. inforvalue
  197. END
  198. ) as accuracy
  199. ,
  200. MAX(CASE
  201. WHEN inforname = 'wgSap' THEN
  202. inforvalue
  203. END
  204. ) as wgSap,
  205. MAX(CASE
  206. WHEN inforname = 'sprinkleFeedTimeAllow' THEN
  207. inforvalue
  208. END
  209. ) as sprinkleFeedTimeAllow,
  210. MAX(CASE
  211. WHEN inforname = 'domain' THEN
  212. inforvalue
  213. END
  214. ) as domain
  215. FROM `sysopt`
  216. WHERE pastureid = ?;
  217. ## 配方版本更新记录表
  218. CREATE TABLE `feed_detail_version` (
  219. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键自增id',
  220. `pasture_id` bigint(20) unsigned NOT NULL COMMENT '牧场id',
  221. `feed_template_id` bigint(20) unsigned NOT NULL DEFAULT '0' COMMENT '配方id',
  222. `group_version` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '版本号',
  223. `belong` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '配方归属 0 无效 1 归属集团端 2 归属牧场端',
  224. `created_at` bigint(20) NOT NULL DEFAULT '0' COMMENT '创建时间',
  225. `updated_at` bigint(20) NOT NULL DEFAULT '0' COMMENT '更新时间',
  226. PRIMARY KEY (`id`),
  227. KEY `idx_feed_template_id` (`feed_template_id`)
  228. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='配方版本更新记录表';
  229. CREATE TABLE `feed_detail_version_log` (
  230. `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键自增id',
  231. `pasture_id` bigint(20) unsigned NOT NULL COMMENT '牧场id',
  232. `version_id` int(11) unsigned NOT NULL COMMENT 'feed_detail_version表id',
  233. `feed_template_id` bigint(20) unsigned NOT NULL COMMENT '配方id',
  234. `forage_id` int(11) unsigned NOT NULL COMMENT '饲料id',
  235. `forage_name` varchar(255) NOT NULL DEFAULT '' COMMENT '饲料名称',
  236. `forage_group_name` varchar(155) NOT NULL DEFAULT '' COMMENT '饲料分组名称',
  237. `weight` int(11) unsigned NOT NULL COMMENT '重量',
  238. `stir_delay` int(11) unsigned NOT NULL COMMENT '搅拌延迟',
  239. `allow_error` int(11) unsigned NOT NULL COMMENT '允许误差',
  240. `is_modify` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否可修改 0 无效 1 是 2 否',
  241. `is_lock_cow_count_ratio` tinyint(1) unsigned NOT NULL DEFAULT '2' COMMENT '是否锁定牛头数比例 1 是 2 否',
  242. `sort` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
  243. `is_show` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '是否删除 0 无效 1 未删除 2 已删除',
  244. `created` datetime NOT NULL COMMENT '创建时间',
  245. `updated` datetime NOT NULL COMMENT '更新时间',
  246. PRIMARY KEY (`id`),
  247. KEY `idx_feed_template_id` (`feed_template_id`)
  248. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='集团端最新配方详情表';
  249. ALTER TABLE ftdetail DROP INDEX ftdetail_ftid,
  250. ADD UNIQUE KEY ftdetail_ftid (`ftid`,`fid`,`pastureid`,`is_show`);