v0002_alter_bigpartpurchase.sql 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. ALTER TABLE `bigpartpurchase`
  2. ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 无效 1 暂估 2 垫付',
  3. ADD COLUMN `funder_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '垫资人id';
  4. ALTER TABLE `bigpartuse` ADD COLUMN greenFodderNumber varchar(255) NOT NULL DEFAULT '' COMMENT '青贮单号';
  5. # SELECT * FROM apisql WHERE sqlname = 'insertBigPartUse'
  6. INSERT INTO bigpartuse (
  7. pastureId,
  8. departmentId,
  9. useForm,
  10. listType,
  11. applicatId,
  12. receiveTime,
  13. empId,
  14. useType,
  15. oddCode,
  16. note,
  17. greenFodderNumber
  18. ) VALUES ( ?,(select departmentId from bigpartapply where applyCode = ? ),?,?,?,?,?,?,?,?,?)
  19. # pastureId,oddCode,useForm,listType,applicatId,receiveTime,empId,useType,oddCode,note,greenFodderNumber
  20. # SELECT * FROM apisql WHERE sqlname = 'getpartpurchaseList'
  21. SELECT
  22. bpp.providerId,
  23. pr.providerName,
  24. bpp.`buyStatu`,
  25. DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
  26. bpp.`CGChargeId`,
  27. DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
  28. bpp.`chargeId`,
  29. bpp.`createTime`,
  30. bpp.`departmentId`,
  31. bpp.`employeId`,
  32. bpp.`flowCompeleted`,
  33. bpp.`flowworkNote`,
  34. bpp.`id`,
  35. bpp.`isUrgent`,
  36. DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
  37. bpp.`KGChargeId`,
  38. bpp.`orderNumber`,
  39. bpp.`pastureId`,
  40. bpp.`statue`,
  41. bpp.`workflowId`,
  42. bpp.`workflowNote`,
  43. bpp.purchase_type, # 这次加字段
  44. bpp.funder_id, # 这次加字段
  45. p.`name` pastureName,
  46. e.empname ,
  47. e6.empname funderName, # 这次加字段
  48. e1.empname KGChargePerson,
  49. e2.empname chargePerson,
  50. e3.empname CGChargePerson,
  51. d.`name` AS departmentName,
  52. DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
  53. e4.empname equipmentPerson,
  54. bpp.equipment,
  55. DATE_FORMAT(bpp.equipmentdate,'%Y-%m-%d %H:%i:%s') equipmentdate ,
  56. e5.empname fieldPerson,
  57. DATE_FORMAT(bpp.fielddate,'%Y-%m-%d %H:%i:%s') fielddate,
  58. if((select sum(price*amount) from partpurchase where bigid = bpp.id )> 5000 ,1,
  59. if((select sum(if(price>3000,1,0)) from partpurchase where bigid = bpp.id)>0,1,0)) as priceClass
  60. FROM
  61. bigpartpurchase bpp
  62. LEFT JOIN pasture p
  63. ON p.id = bpp.pastureId
  64. LEFT JOIN emp e
  65. ON e.id = bpp.employeId
  66. LEFT JOIN department d
  67. ON d.id = bpp.departmentId
  68. LEFT JOIN emp e1
  69. ON e1.id = bpp.KGChargeId
  70. LEFT JOIN emp e2
  71. ON e2.id = bpp.chargeId
  72. LEFT JOIN emp e3
  73. ON e3.id = bpp.CGChargeId
  74. LEFT JOIN emp e4
  75. ON e4.id = bpp.equipment
  76. LEFT JOIN emp e5
  77. ON e5.id = bpp.field
  78. LEFT JOIN emp e6
  79. ON e6.id = bpp.funder_id
  80. LEFT JOIN provider pr
  81. ON pr.id = bpp.providerId
  82. WHERE
  83. ((bpp.employeId = ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  84. LEFT JOIN user_role ur
  85. ON ur.`user_id`= u.`id`
  86. LEFT JOIN role r
  87. ON r.`id` = ur.`role_id`
  88. LEFT JOIN role_menu rm
  89. ON r.`id` = rm.`role_id`
  90. LEFT JOIN menu m
  91. ON m.`id` = rm.`menu_id`
  92. WHERE u.`empid` = ? AND m.`path`=? ),0) IN (1,2,3))
  93. AND (bpp.departmentId IN (SELECT id FROM department WHERE pastureId =? AND id IN (
  94. SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ss.www,',',b.seq+1),',',-1) AS 'ids'
  95. FROM
  96. (SELECT @i:=1 i,IFNULL((SELECT GROUP_CONCAT(department_id)SSSS
  97. FROM role_department WHERE role_id = (SELECT MAX(r.id) FROM `user` u
  98. LEFT JOIN user_role ur
  99. ON ur.`user_id`= u.`id`
  100. LEFT JOIN role r
  101. ON r.`id` = ur.`role_id`
  102. LEFT JOIN role_menu rm
  103. ON r.`id` = rm.`role_id`
  104. LEFT JOIN role_department rd
  105. ON r.`id` = rd.`role_id`
  106. LEFT JOIN menu m
  107. ON m.`id` = rm.`menu_id`
  108. WHERE u.`empid` = ? AND m.`path`=?) AND department_id IN (SELECT id FROM department WHERE pastureId = ?)),?) www) ss
  109. JOIN sequence b ON b.seq < (LENGTH(ss.www) - LENGTH(REPLACE(ss.www,',',''))+1)
  110. WHERE ss.i =1
  111. GROUP BY ids
  112. )
  113. )
  114. OR bpp.employeId = ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  115. LEFT JOIN user_role ur
  116. ON ur.`user_id`= u.`id`
  117. LEFT JOIN role r
  118. ON r.`id` = ur.`role_id`
  119. LEFT JOIN role_menu rm
  120. ON r.`id` = rm.`role_id`
  121. LEFT JOIN menu m
  122. ON m.`id` = rm.`menu_id`
  123. WHERE u.`empid` =? AND m.`path`=?),0) IN (2,3))
  124. AND (p.`id` = ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  125. LEFT JOIN user_role ur
  126. ON ur.`user_id`= u.`id`
  127. LEFT JOIN role r
  128. ON r.`id` = ur.`role_id`
  129. LEFT JOIN role_menu rm
  130. ON r.`id` = rm.`role_id`
  131. LEFT JOIN menu m
  132. ON m.`id` = rm.`menu_id`
  133. WHERE u.`empid` = ? AND m.`path`=? ),0) = 3))
  134. AND
  135. (
  136. bpp.orderNumber LIKE CONCAT("%", ?, "%")
  137. OR ? = ''
  138. )
  139. AND (
  140. p.`name` = ?
  141. OR ? = '现代牧业'
  142. )
  143. AND (
  144. bpp.departmentId = ?
  145. OR ? = ''
  146. )AND (
  147. (bpp.createTime >= ? AND bpp.createTime <= ? )
  148. OR ? = ''
  149. )
  150. AND (
  151. IF (?=0,bpp.statue IN (2,3,5) ,
  152. IF(?=1,bpp.statue=7,bpp.statue IN (4,6,8))
  153. )
  154. OR ? = ''
  155. )
  156. AND
  157. (
  158. e.empname LIKE CONCAT("%", ?, "%")
  159. OR ? = ''
  160. )
  161. AND (bpp.purchase_type = ? OR ? = '')
  162. ORDER BY bpp.id DESC
  163. ## loginId,loginId,menu,loginpastureId,loginId,menu,loginpastureId,logindeptId,loginId,loginId,menu,loginpastureId,loginId,menu,orderNumber ,orderNumber ,pastureName,pastureName,departmentId ,departmentId,startTime,stopTime,startTime,stuteSH,stuteSH,stuteSH,empName,empName,purchase_type
  164. ## 合同管理增加两个字段
  165. ALTER TABLE `contract`
  166. ADD COLUMN lifeCycle varchar(255) NOT NULL DEFAULT '' COMMENT '使用周期',
  167. ADD COLUMN ContractVarianceItem varchar(255) NOT NULL DEFAULT '' COMMENT '合同差异性';
  168. INSERT INTO contract(
  169. bigId,
  170. pastureId,
  171. pastureName,
  172. partId,
  173. partName,
  174. partCode,
  175. specification,
  176. price,
  177. brandId,
  178. brand,
  179. planAmount,
  180. remark,
  181. unit,
  182. enable,
  183. changeId,
  184. taxcode,
  185. lifeCycle, ## 这次新增的字段
  186. contractVarianceItem ## 这次新增的字段
  187. )VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,0,if(?='',null,?),?,?,?);
  188. ## bigId,pastureId,pastureName,partId,partName,partCode,specification,price,brandId,brand,planAmount,remark,unit,contractId,contractId,taxcode,lifeCycle,contractVarianceItem
  189. ## SELECT * FROM apisql WHERE sqlname = "getcontratListBybigV2"
  190. SELECT
  191. CONCAT('uploads/thumbnail/',ep.`picpath`,'/',ep.`newpicname`) picpath,
  192. CONCAT('uploads/image/',ep.`picpath`,'/',ep.`newpicname`) srcpath,
  193. b.`brandName`,c.lifeCycle,c.contractVarianceItem,
  194. c.id,c.bigId,c.pastureId,c.pastureName,c.partId,c.partName,c.partCode,c.specification,
  195. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM c.price))) price,c.brandId,c.brand,c.inventoryType,c.planAmount,c.remark,c.enable,c.unit,c.isZeroStock
  196. FROM
  197. contract c
  198. INNER JOIN bigcontract bc
  199. ON bc.id = c.`bigId`
  200. LEFT JOIN brand b
  201. ON b.id = c.`brandId`
  202. LEFT JOIN parts ps
  203. ON ps.id = c.`partId`
  204. LEFT JOIN eq_pic ep
  205. ON ep.id = ps.picpath
  206. WHERE bc.`pastureId`=? AND bc.`providerId` = ? AND bc.`stopTime`=? AND bc.`flag` =? AND bc.isZeroStock = ?
  207. AND bc.statue =? and c.enable = 1
  208. AND (
  209. c.partCode LIKE CONCAT("%", ?, "%")
  210. OR ? = ''
  211. )
  212. AND (
  213. c.partName LIKE CONCAT("%", ?, "%")
  214. OR ? = ''
  215. )
  216. AND (
  217. c.specification LIKE CONCAT("%", ?, "%")
  218. OR ? = ''
  219. )
  220. ORDER BY c.partCode;
  221. # SELECT * FROM apisql WHERE sqlname = "insertDiesel
  222. INSERT INTO diesel (pastureId,selTime,oilClass,oilAmount,eqId,eqCode,deptId,note,nowPrice,oilcardId,cardNumber,price,empId,inputId,oilType,oilName)VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);
  223. # pastureId,selTime,oilClass,oilAmount,eqId,eqCode,departmentId,note,nowPrice,oilcardId,cardNumber,price,empId,inputId,oilType,oilName
  224. ALTER TABLE `diesel`
  225. ADD COLUMN `oilType` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '柴油类型 0: 空 1: 0# 2: -10# 3: -20# 4: -30# 5: -35#',
  226. ADD COLUMN `oilName` varchar(255) NOT NULL DEFAULT '' COMMENT '柴油类型名称';
  227. # SELECT * FROM apisql WHERE sqlname = "updateDieselExecData"
  228. update diesel
  229. set oilAmount= ?,
  230. note = ?,
  231. nowPrice = ?,
  232. price=?,
  233. oilType = ?,
  234. oilName = ?
  235. where id = ?;
  236. # oilAmount, note, nowPrice, price,oilType,oilName, id
  237. # SELECT * FROM apisql WHERE sqlname = "getDieselList"
  238. SELECT (@i:=@i+1) i,d.id,d.oilcardId,p.name pastureName,dp.name departName, d.cardNumber,o.cardType ,DATE_FORMAT(d.selTime,'%Y-%m-%d') as selTime,a.eqCode as assetNumber ,a.eqName assetName,d.empId employName,d.oilClass,d.empId,
  239. d.oilName,
  240. d.oilAmount,d.price,d.nowPrice,d.note,ff.empname empname,d.inputId
  241. from (SELECT @i:=0) AS i,diesel d
  242. LEFT JOIN oilcard o ON d.oilcardId = o.id
  243. INNER JOIN pasture p on d.pastureId = p.id
  244. left JOIN department dp on d.deptId= dp.id
  245. LEFT JOIN emp ff ON d.inputId = ff.id
  246. LEFT JOIN equipment a ON a.id= o.eqId
  247. where (p.name like concat("%",?,"%") or ? ='现代牧业')
  248. and (dp.name like concat("%",?,"%") or ? ='')
  249. and (d.cardNumber like concat("%",?,"%") or ? ='')
  250. and (o.cardCode like concat("%",?,"%") or ? ='')
  251. AND (a.eqCode like concat("%",?,"%") or ? ='') AND (a.eqName like concat("%",?,"%") or ? ='')
  252. AND (d.empId like concat("%",?,"%") or ? ='') AND (d.oilClass like concat("%",?,"%") or ? ='')
  253. and (d.selTime between ? and ? or ?='')
  254. ORDER BY d.selTime DESC,d.id DESC;
  255. # SELECT * FROM apisql WHERE sqlname = "getPartuseDetailList" // 备件出库-出库记录查询修改备件名称模糊查询
  256. SELECT
  257. e1.`empname`,
  258. d.`name` AS departmentName,
  259. bpu.`listType`,
  260. bpu.`useForm`,
  261. IFNULL(pv.`providerName`,(SELECT provider.providerName FROM part_repertory
  262. INNER JOIN provider ON provider.id = part_repertory.providerId
  263. WHERE part_repertory.contractId = pu.contractId LIMIT 1)) providerName,
  264. w.`warehoseCode`,
  265. pu.`partCode`,
  266. pu.`partName`,
  267. b.`brandName`,
  268. pu.`specification`,
  269. pu.`unit`,
  270. (pu.`checkoutNumber`-pu.`quitNumber`) checkoutNumber,
  271. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pu.`price`))) price,
  272. round( TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pu.`price`)))*(pu.`checkoutNumber`-pu.`quitNumber`) ,2)sumPrice,
  273. pu.`eqName`,
  274. pu.`eqCode`,
  275. pu.useTypeV,
  276. pu.reportery,
  277. p.`name` pastureName,
  278. e.empname AS appliname,
  279. e.id employeId,
  280. DATE_FORMAT(bpu.receiveTime, '%Y/%m/%d') creatTime,pu.note
  281. FROM
  282. partuse pu
  283. inner JOIN bigpartuse bpu
  284. ON pu.`bigId` =bpu.`id`
  285. LEFT JOIN pasture p
  286. ON p.id = bpu.pastureId
  287. LEFT JOIN emp e
  288. ON e.id = bpu.applicatId
  289. LEFT JOIN emp e1
  290. ON e1.id = bpu.`empId`
  291. LEFT JOIN department d
  292. ON d.id = bpu.`departmentId`
  293. LEFT JOIN contract c
  294. ON c.`id` = pu.`contractId`
  295. LEFT JOIN bigcontract bc
  296. ON bc.`id` = c.`bigId`
  297. LEFT JOIN provider pv
  298. ON bc.`providerId` = pv.`id`
  299. LEFT JOIN warehouse w
  300. ON w.id = pu.locationId
  301. LEFT JOIN brand b
  302. ON b.id = pu.brandId
  303. WHERE (
  304. bpu.useForm LIKE CONCAT("%", ?, "%")
  305. OR ? = ''
  306. )
  307. AND (
  308. bpu.`useType` = ?
  309. OR ? = ''
  310. )
  311. AND (
  312. (bpu.receiveTime >= ? AND bpu.receiveTime <= ?)
  313. OR ? = ''
  314. )
  315. AND (
  316. p.`name` = ?
  317. OR ? = '现代牧业'
  318. )
  319. AND (
  320. d.`id` =?
  321. OR ? = ''
  322. )
  323. AND (
  324. pu.partCode=?
  325. OR ? = ''
  326. )
  327. AND (
  328. pu.partName like concat("%",?,"%") or ? =''
  329. )
  330. AND (
  331. bc.`providerId`=?
  332. OR ? = ''
  333. )
  334. AND (
  335. pu.`eqName`=?
  336. OR ? = ''
  337. )
  338. AND (
  339. if(?='',
  340. ''='',
  341. (select assetCode from equipment where equipment.eqcode = pu.eqcode) like concat(?,'%')
  342. )
  343. )
  344. ORDER BY bpu.receiveTime DESC,bpu.id desc;
  345. SELECT (@i:=@i+1) i,d.id,d.oilcardId,p.name pastureName,dp.name departName, d.cardNumber,o.cardType ,DATE_FORMAT(d.selTime,'%Y-%m-%d') as selTime,a.eqCode as assetNumber ,a.eqName assetName,d.empId employName,d.oilClass,d.empId,
  346. d.oilName,
  347. d.oilAmount,d.price,d.nowPrice,d.note,ff.empname empname,d.inputId
  348. from (SELECT @i:=0) AS i,diesel d
  349. LEFT JOIN oilcard o ON d.oilcardId = o.id
  350. INNER JOIN pasture p on d.pastureId = p.id
  351. left JOIN department dp on d.deptId= dp.id
  352. LEFT JOIN emp ff ON d.inputId = ff.id
  353. LEFT JOIN equipment a ON a.id= o.eqId
  354. where (p.name like concat("%",?,"%") or ? ='现代牧业')
  355. and (dp.name like concat("%",?,"%") or ? ='')
  356. and (d.cardNumber like concat("%",?,"%") or ? ='')
  357. and (o.cardCode like concat("%",?,"%") or ? ='')
  358. AND (a.eqCode like concat("%",?,"%") or ? ='') AND (a.eqName like concat("%",?,"%") or ? ='')
  359. AND (d.empId like concat("%",?,"%") or ? ='') AND (d.oilClass like concat("%",?,"%") or ? ='')
  360. and (d.selTime between ? and ? or ?='')
  361. ORDER BY d.selTime DESC,d.id DESC;
  362. # SELECT * FROM apisql WHERE sqlname = "getPartlaideDetailList" // 备件入库-入库记录查询修改备件名称模糊查询
  363. SELECT
  364. emp.empname,
  365. b.`brandName`,
  366. w.`warehoseCode`,
  367. pv.`providerName`,
  368. DATE_FORMAT(bpl.storageTime, '%Y/%m/%d') creatTime,
  369. p.`name` pastureName,
  370. bpl.`laidCode`,
  371. pl.`partCode`,
  372. pl.`partName`,
  373. pl.`specification`,
  374. pl.`unit`,
  375. pl.storageAmount,
  376. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pl.`price`))) price ,
  377. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pl.`sumPrice`))) sumPrice
  378. FROM
  379. partlaid pl
  380. inner JOIN bigpartlaid bpl
  381. ON bpl.`id` = pl.`bigId`
  382. LEFT JOIN brand b
  383. ON b.id = pl.brandId
  384. LEFT JOIN warehouse w
  385. ON w.id = pl.locationId
  386. LEFT JOIN pasture p
  387. ON p.id = bpl.`pastureId`
  388. left JOIN provider pv
  389. ON pv.id = pl.`providerId`
  390. left join emp
  391. on emp.id = bpl.empId
  392. WHERE (
  393. bpl.laidCode LIKE CONCAT("%", ?, "%")
  394. OR ? = ''
  395. )
  396. AND (
  397. p.`name` LIKE CONCAT("%", ?, "%")
  398. OR ? = '现代牧业'
  399. )
  400. AND (
  401. (bpl.storageTime >= ? AND bpl.storageTime <= ?)
  402. OR ? = ''
  403. )
  404. AND (
  405. pl.partCode=?
  406. OR ? = ''
  407. )
  408. AND ( pl.partName like concat("%",?,"%") or ? ='')
  409. AND (
  410. pl.providerId=?
  411. OR ? = ''
  412. )
  413. ORDER BY bpl.storageTime DESC, bpl.`id` DESC;