admin.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. /**
  2. * Created by fy on 2016/12/29.
  3. */
  4. 'use strict';
  5. const express = require('express');
  6. const router = express.Router();
  7. const fs = require('fs');
  8. const utils = require('../../lib/utils');
  9. const adminService = require('../../service/dna/admin');
  10. const excel = require('node-excel-export');
  11. router.get('/', (req, res) => {
  12. res.render('dna/admin/list');
  13. });
  14. router.route('/list').get(adminService.list).post(adminService.list);
  15. /**
  16. * 显示修改界面
  17. */
  18. router.get('/preEdit', (req, res) => {
  19. adminService.selectDnaFlowById(req.query.id, (err, rows) => {
  20. console.error(err);
  21. if (rows && rows.length == 1) {
  22. let row = rows[0];
  23. row.action = '/dna/admin/edit';
  24. res.render('dna/admin/edit', row);
  25. }
  26. });
  27. });
  28. /**
  29. * 修改信息
  30. */
  31. router.post('/edit', (req, res) => {
  32. let params = req.body;
  33. adminService.updateDnaFlowById(params, (err, result) => {
  34. if (err) throw err;
  35. console.error(err);
  36. let errMsg = JSON.stringify(err);
  37. let rowCount = null;
  38. if (result) {
  39. rowCount = result.changedRows;
  40. if (result.affectedRows == 1 && rowCount == 0) rowCount = '-1'; // 数据没有发生变化
  41. }
  42. utils.jsonpAndEnd(res, `parent.parent.editCb(${rowCount}, '${errMsg}');`);
  43. });
  44. });
  45. /**
  46. * 彻底删除数据
  47. */
  48. router.post('/delete', (req, res) => {
  49. let ids = req.body.ids;
  50. adminService.deleteDnaByIds(ids, (err, result) => {
  51. if (err)throw err;
  52. res.send({
  53. affectedRows: result.affectedRows,
  54. err: err
  55. });
  56. });
  57. });
  58. /**
  59. * 导出excel
  60. */
  61. router.post('/exportExcel', (req, res) => {
  62. adminService.listAll(req, (err, rows) => {
  63. if (err)throw err;
  64. if (rows && rows.length > 0) {
  65. let dataset = JSON.parse(JSON.stringify(rows));
  66. let styles = {
  67. title: {
  68. font: {
  69. sz: 30,
  70. bold: true
  71. }
  72. },
  73. header: {
  74. font: {
  75. color: {
  76. // rgb: 'FFFFFFFF'
  77. },
  78. sz: 14,
  79. bold: true,
  80. underline: false
  81. }
  82. },
  83. cell: {}
  84. };
  85. let heading = [
  86. [{value: 'DNA检测流程全部数据导出', style: styles.header}],
  87. ];
  88. let specification = {
  89. barcode_long: {
  90. displayName: '条码编号',
  91. headerStyle: styles.header,
  92. cellStyle: styles.cell,
  93. cellFormat: function (value, row) {
  94. return value || '';
  95. },
  96. width: '15'
  97. },
  98. hospital: {
  99. displayName: '医院名称',
  100. headerStyle: styles.header,
  101. cellStyle: styles.cell,
  102. cellFormat: function (value, row) {
  103. return value || '';
  104. },
  105. width: '15'
  106. },
  107. sample_code: {
  108. displayName: '样本编号',
  109. headerStyle: styles.header,
  110. cellStyle: styles.cell,
  111. cellFormat: function (value, row) {
  112. return value || '';
  113. },
  114. width: '15'
  115. },
  116. sample_date: {
  117. displayName: '采样日期',
  118. headerStyle: styles.header,
  119. cellStyle: styles.cell,
  120. cellFormat: function (value, row) {
  121. return value || '';
  122. },
  123. width: '15'
  124. },
  125. receive_date: {
  126. displayName: '接收日期',
  127. headerStyle: styles.header,
  128. cellStyle: styles.cell,
  129. cellFormat: function (value, row) {
  130. return value || '';
  131. },
  132. width: '15'
  133. },
  134. real_name: {
  135. displayName: '姓名',
  136. headerStyle: styles.header,
  137. cellStyle: styles.cell,
  138. cellFormat: function (value, row) {
  139. return value || '';
  140. },
  141. width: '15'
  142. },
  143. id_card: {
  144. displayName: '身份证',
  145. headerStyle: styles.header,
  146. cellStyle: styles.cell,
  147. cellFormat: function (value, row) {
  148. return value || '';
  149. },
  150. width: '15'
  151. },
  152. age: {
  153. displayName: '年龄',
  154. headerStyle: styles.header,
  155. cellStyle: styles.cell,
  156. cellFormat: function (value, row) {
  157. return value || '';
  158. },
  159. width: '15'
  160. },
  161. pregnancy_week: {
  162. displayName: '孕周',
  163. headerStyle: styles.header,
  164. cellStyle: styles.cell,
  165. cellFormat: function (value, row) {
  166. return value || '';
  167. },
  168. width: '15'
  169. },
  170. pregnancy_day: {
  171. displayName: '孕天',
  172. headerStyle: styles.header,
  173. cellStyle: styles.cell,
  174. cellFormat: function (value, row) {
  175. return value || '';
  176. },
  177. width: '15'
  178. },
  179. pregnancy_condition: {
  180. displayName: '妊娠情况',
  181. headerStyle: styles.header,
  182. cellStyle: styles.cell,
  183. cellFormat: function (value, row) {
  184. return value || '';
  185. },
  186. width: '15'
  187. },
  188. pregnancy_bad_history: {
  189. displayName: '不良孕产史',
  190. headerStyle: styles.header,
  191. cellStyle: styles.cell,
  192. cellFormat: function (value, row) {
  193. return value || '';
  194. },
  195. width: '15'
  196. },
  197. comments: {
  198. displayName: '备注',
  199. headerStyle: styles.header,
  200. cellStyle: styles.cell,
  201. cellFormat: function (value, row) {
  202. return value || '';
  203. },
  204. width: '15'
  205. },
  206. inputter: {
  207. displayName: '录入人员',
  208. headerStyle: styles.header,
  209. cellStyle: styles.cell,
  210. cellFormat: function (value, row) {
  211. return value || '';
  212. },
  213. width: '15'
  214. },
  215. input_date: {
  216. displayName: '录入日期',
  217. headerStyle: styles.header,
  218. cellStyle: styles.cell,
  219. cellFormat: function (value, row) {
  220. return value || '';
  221. },
  222. width: '15'
  223. },
  224. // changer: {
  225. // displayName: '换管人员',
  226. // headerStyle: styles.header,
  227. // cellStyle: styles.cell,
  228. // cellFormat: function (value, row) {
  229. // return value || '';
  230. // },
  231. // width: '15'
  232. // },
  233. // change_date: {
  234. // displayName: '换管日期',
  235. // headerStyle: styles.header,
  236. // cellStyle: styles.cell,
  237. // cellFormat: function (value, row) {
  238. // return value || '';
  239. // },
  240. // width: '15'
  241. // },
  242. checker: {
  243. displayName: '审批人员',
  244. headerStyle: styles.header,
  245. cellStyle: styles.cell,
  246. cellFormat: function (value, row) {
  247. return value || '';
  248. },
  249. width: '15'
  250. },
  251. check_date: {
  252. displayName: '审批日期',
  253. headerStyle: styles.header,
  254. cellStyle: styles.cell,
  255. cellFormat: function (value, row) {
  256. return value || '';
  257. },
  258. width: '15'
  259. },
  260. warehouser: {
  261. displayName: '采血管入库人',
  262. headerStyle: styles.header,
  263. cellStyle: styles.cell,
  264. cellFormat: function (value, row) {
  265. return value || '';
  266. },
  267. width: '15'
  268. },
  269. warehouse_place: {
  270. displayName: '采血管入库位置',
  271. headerStyle: styles.header,
  272. cellStyle: styles.cell,
  273. cellFormat: function (value, row) {
  274. return value || '';
  275. },
  276. width: '15'
  277. },
  278. warehouse_date: {
  279. displayName: '采血管入库时间',
  280. headerStyle: styles.header,
  281. cellStyle: styles.cell,
  282. cellFormat: function (value, row) {
  283. return value || '';
  284. },
  285. width: '15'
  286. },
  287. // barcode_short: {
  288. // displayName: '短条码编号',
  289. // headerStyle: styles.header,
  290. // cellStyle: styles.cell,
  291. // cellFormat: function (value, row) {
  292. // return value || '';
  293. // },
  294. // width: '15'
  295. // },
  296. sample_outer: {
  297. displayName: '采血管出库人',
  298. headerStyle: styles.header,
  299. cellStyle: styles.cell,
  300. cellFormat: function (value, row) {
  301. return value || '';
  302. },
  303. width: '15'
  304. },
  305. sample_out_residue: {
  306. displayName: '接收组样本剩余量',
  307. headerStyle: styles.header,
  308. cellStyle: styles.cell,
  309. cellFormat: function (value, row) {
  310. return value || '';
  311. },
  312. width: '15'
  313. },
  314. extract_handover: {
  315. displayName: '提取组接收人',
  316. headerStyle: styles.header,
  317. cellStyle: styles.cell,
  318. cellFormat: function (value, row) {
  319. return value || '';
  320. },
  321. width: '15'
  322. },
  323. extract_handover_date: {
  324. displayName: '提取组接收时间',
  325. headerStyle: styles.header,
  326. cellStyle: styles.cell,
  327. cellFormat: function (value, row) {
  328. return value || '';
  329. },
  330. width: '15'
  331. },
  332. extract_qbite_deep: {
  333. displayName: 'Qubit浓度(ng/ul)',
  334. headerStyle: styles.header,
  335. cellStyle: styles.cell,
  336. cellFormat: function (value, row) {
  337. return value || '';
  338. },
  339. width: '15'
  340. },
  341. extract_epoch_deep: {
  342. displayName: 'epoch浓度(ng/ul)',
  343. headerStyle: styles.header,
  344. cellStyle: styles.cell,
  345. cellFormat: function (value, row) {
  346. return value || '';
  347. },
  348. width: '15'
  349. },
  350. extract_purity_deep: {
  351. displayName: '纯度(%)',
  352. headerStyle: styles.header,
  353. cellStyle: styles.cell,
  354. cellFormat: function (value, row) {
  355. return value || '';
  356. },
  357. width: '15'
  358. },
  359. extract_part_size: {
  360. displayName: '片段大小(bp)',
  361. headerStyle: styles.header,
  362. cellStyle: styles.cell,
  363. cellFormat: function (value, row) {
  364. return value || '';
  365. },
  366. width: '15'
  367. },
  368. extract_part_after_break: {
  369. displayName: '打断后片段(bp)',
  370. headerStyle: styles.header,
  371. cellStyle: styles.cell,
  372. cellFormat: function (value, row) {
  373. return value || '';
  374. },
  375. width: '15'
  376. },
  377. extracter: {
  378. displayName: '提取人员',
  379. headerStyle: styles.header,
  380. cellStyle: styles.cell,
  381. cellFormat: function (value, row) {
  382. return value || '';
  383. },
  384. width: '15'
  385. },
  386. extract_date: {
  387. displayName: '提取时间',
  388. headerStyle: styles.header,
  389. cellStyle: styles.cell,
  390. cellFormat: function (value, row) {
  391. return value || '';
  392. },
  393. width: '15'
  394. },
  395. extract_checker: {
  396. displayName: '提取审核人',
  397. headerStyle: styles.header,
  398. cellStyle: styles.cell,
  399. cellFormat: function (value, row) {
  400. return value || '';
  401. },
  402. width: '15'
  403. },
  404. extract_check_date: {
  405. displayName: '提取审核时间',
  406. headerStyle: styles.header,
  407. cellStyle: styles.cell,
  408. cellFormat: function (value, row) {
  409. return value || '';
  410. },
  411. width: '15'
  412. },
  413. extract_outer: {
  414. displayName: '提取出库人',
  415. headerStyle: styles.header,
  416. cellStyle: styles.cell,
  417. cellFormat: function (value, row) {
  418. return value || '';
  419. },
  420. width: '15'
  421. },
  422. extract_out_residue: {
  423. displayName: '提取组样本剩余量',
  424. headerStyle: styles.header,
  425. cellStyle: styles.cell,
  426. cellFormat: function (value, row) {
  427. return value || '';
  428. },
  429. width: '15'
  430. },
  431. storage_handover: {
  432. displayName: '建库组接收人',
  433. headerStyle: styles.header,
  434. cellStyle: styles.cell,
  435. cellFormat: function (value, row) {
  436. return value || '';
  437. },
  438. width: '15'
  439. },
  440. storage_handover_date: {
  441. displayName: '建库组接收时间',
  442. headerStyle: styles.header,
  443. cellStyle: styles.cell,
  444. cellFormat: function (value, row) {
  445. return value || '';
  446. },
  447. width: '15'
  448. },
  449. storage_deep: {
  450. displayName: '建库浓度(ng/ul)',
  451. headerStyle: styles.header,
  452. cellStyle: styles.cell,
  453. cellFormat: function (value, row) {
  454. return value || '';
  455. },
  456. width: '15'
  457. },
  458. storage_index: {
  459. displayName: '建库index号',
  460. headerStyle: styles.header,
  461. cellStyle: styles.cell,
  462. cellFormat: function (value, row) {
  463. return value || '';
  464. },
  465. width: '15'
  466. },
  467. storage_part_size: {
  468. displayName: '建库片段大小(bp)',
  469. headerStyle: styles.header,
  470. cellStyle: styles.cell,
  471. cellFormat: function (value, row) {
  472. return value || '';
  473. },
  474. width: '15'
  475. },
  476. storager: {
  477. displayName: '建库人',
  478. headerStyle: styles.header,
  479. cellStyle: styles.cell,
  480. cellFormat: function (value, row) {
  481. return value || '';
  482. },
  483. width: '15'
  484. },
  485. storage_date: {
  486. displayName: '建库时间',
  487. headerStyle: styles.header,
  488. cellStyle: styles.cell,
  489. cellFormat: function (value, row) {
  490. return value || '';
  491. },
  492. width: '15'
  493. },
  494. storage_checker: {
  495. displayName: '建库审查人',
  496. headerStyle: styles.header,
  497. cellStyle: styles.cell,
  498. cellFormat: function (value, row) {
  499. return value || '';
  500. },
  501. width: '15'
  502. },
  503. storage_check_date: {
  504. displayName: '建库审查时间',
  505. headerStyle: styles.header,
  506. cellStyle: styles.cell,
  507. cellFormat: function (value, row) {
  508. return value || '';
  509. },
  510. width: '15'
  511. },
  512. storage_outer: {
  513. displayName: '建库组出库人',
  514. headerStyle: styles.header,
  515. cellStyle: styles.cell,
  516. cellFormat: function (value, row) {
  517. return value || '';
  518. },
  519. width: '15'
  520. },
  521. storage_out_residue: {
  522. displayName: '建库组样本剩余量',
  523. headerStyle: styles.header,
  524. cellStyle: styles.cell,
  525. cellFormat: function (value, row) {
  526. return value || '';
  527. },
  528. width: '15'
  529. },
  530. operate_handover: {
  531. displayName: '上机组接收人',
  532. headerStyle: styles.header,
  533. cellStyle: styles.cell,
  534. cellFormat: function (value, row) {
  535. return value || '';
  536. },
  537. width: '15'
  538. },
  539. operate_handover_date: {
  540. displayName: '上机组接收时间',
  541. headerStyle: styles.header,
  542. cellStyle: styles.cell,
  543. cellFormat: function (value, row) {
  544. return value || '';
  545. },
  546. width: '15'
  547. },
  548. operate_chip_code: {
  549. displayName: '上机芯片编码',
  550. headerStyle: styles.header,
  551. cellStyle: styles.cell,
  552. cellFormat: function (value, row) {
  553. return value || '';
  554. },
  555. width: '15'
  556. },
  557. operate_reads_val: {
  558. displayName: '上机reads数',
  559. headerStyle: styles.header,
  560. cellStyle: styles.cell,
  561. cellFormat: function (value, row) {
  562. return value || '';
  563. },
  564. width: '15'
  565. },
  566. operate_q30_val: {
  567. displayName: '上机q30值',
  568. headerStyle: styles.header,
  569. cellStyle: styles.cell,
  570. cellFormat: function (value, row) {
  571. return value || '';
  572. },
  573. width: '15'
  574. },
  575. operater: {
  576. displayName: '上机人',
  577. headerStyle: styles.header,
  578. cellStyle: styles.cell,
  579. cellFormat: function (value, row) {
  580. return value || '';
  581. },
  582. width: '15'
  583. },
  584. operate_date: {
  585. displayName: '上机时间',
  586. headerStyle: styles.header,
  587. cellStyle: styles.cell,
  588. cellFormat: function (value, row) {
  589. return value || '';
  590. },
  591. width: '15'
  592. },
  593. operate_checker: {
  594. displayName: '上机审查人',
  595. headerStyle: styles.header,
  596. cellStyle: styles.cell,
  597. cellFormat: function (value, row) {
  598. return value || '';
  599. },
  600. width: '15'
  601. },
  602. operate_check_date: {
  603. displayName: '上机审查时间',
  604. headerStyle: styles.header,
  605. cellStyle: styles.cell,
  606. cellFormat: function (value, row) {
  607. return value || '';
  608. },
  609. width: '15'
  610. },
  611. operate_outer: {
  612. displayName: '上机组出库人',
  613. headerStyle: styles.header,
  614. cellStyle: styles.cell,
  615. cellFormat: function (value, row) {
  616. return value || '';
  617. },
  618. width: '15'
  619. },
  620. operate_out_residue: {
  621. displayName: '上机组样本剩余量',
  622. headerStyle: styles.header,
  623. cellStyle: styles.cell,
  624. cellFormat: function (value, row) {
  625. return value || '';
  626. },
  627. width: '15'
  628. },
  629. report_handover: {
  630. displayName: '分析报告组接收人',
  631. headerStyle: styles.header,
  632. cellStyle: styles.cell,
  633. cellFormat: function (value, row) {
  634. return value || '';
  635. },
  636. width: '15'
  637. },
  638. report_handover_date: {
  639. displayName: '分析报告组接收时间',
  640. headerStyle: styles.header,
  641. cellStyle: styles.cell,
  642. cellFormat: function (value, row) {
  643. return value || '';
  644. },
  645. width: '15'
  646. },
  647. report_result: {
  648. displayName: '分析结果',
  649. headerStyle: styles.header,
  650. cellStyle: styles.cell,
  651. cellFormat: function (value, row) {
  652. return value || '';
  653. },
  654. width: '15'
  655. },
  656. report_advice: {
  657. displayName: '建议',
  658. headerStyle: styles.header,
  659. cellStyle: styles.cell,
  660. cellFormat: function (value, row) {
  661. return value || '';
  662. },
  663. width: '15'
  664. },
  665. report_is_send: {
  666. displayName: '是否发送',
  667. headerStyle: styles.header,
  668. cellStyle: styles.cell,
  669. cellFormat: function (value, row) {
  670. if (value == 1) {
  671. return '不发送';
  672. } else if (value == 2) {
  673. return '发送';
  674. } else {
  675. return '';
  676. }
  677. },
  678. width: '15'
  679. },
  680. reporter: {
  681. displayName: '分析人',
  682. headerStyle: styles.header,
  683. cellStyle: styles.cell,
  684. cellFormat: function (value, row) {
  685. return value || '';
  686. },
  687. width: '15'
  688. },
  689. report_date: {
  690. displayName: '分析时间',
  691. headerStyle: styles.header,
  692. cellStyle: styles.cell,
  693. cellFormat: function (value, row) {
  694. return value || '';
  695. },
  696. width: '15'
  697. },
  698. report_sender: {
  699. displayName: '报告发送人',
  700. headerStyle: styles.header,
  701. cellStyle: styles.cell,
  702. cellFormat: function (value, row) {
  703. return value || '';
  704. },
  705. width: '15'
  706. },
  707. report_send_date: {
  708. displayName: '报告发送时间',
  709. headerStyle: styles.header,
  710. cellStyle: styles.cell,
  711. cellFormat: function (value, row) {
  712. return value || '';
  713. },
  714. width: '15'
  715. },
  716. status: {
  717. displayName: '状态',
  718. headerStyle: styles.header,
  719. cellStyle: styles.cell,
  720. cellFormat: function (value, row) {
  721. let text = '';
  722. switch (value) {
  723. case 0:
  724. text = '已删除';
  725. break;
  726. case 1:
  727. text = '已录入';
  728. break;
  729. case 2:
  730. text = '已审批';
  731. break;
  732. case 3:
  733. text = '已入库';
  734. break;
  735. case 4:
  736. text = '已出库';
  737. break;
  738. case 5:
  739. text = '已提取';
  740. break;
  741. case 6:
  742. text = '提取合格';
  743. break;
  744. case 7:
  745. text = '提取废弃';
  746. break;
  747. case 8:
  748. text = '重提取';
  749. break;
  750. case 9:
  751. text = '提取已交接';
  752. break;
  753. case 10:
  754. text = '已建库';
  755. break;
  756. case 11:
  757. text = '建库合格';
  758. break;
  759. case 12:
  760. text = '建库废弃';
  761. break;
  762. case 13:
  763. text = '重建库';
  764. break;
  765. case 14:
  766. text = '建库已交接';
  767. break;
  768. case 15:
  769. text = '已上机';
  770. break;
  771. case 16:
  772. text = '上机合格';
  773. break;
  774. case 17:
  775. text = '上机废弃';
  776. break;
  777. case 18:
  778. text = '重上机';
  779. break;
  780. case 19:
  781. text = '上机已交接';
  782. break;
  783. case 20:
  784. text = '已分析';
  785. break;
  786. case 21:
  787. text = '报告已发送';
  788. break;
  789. default:
  790. text = '';
  791. }
  792. return text;
  793. },
  794. width: '15'
  795. }
  796. };
  797. let report = excel.buildExport(
  798. [
  799. {
  800. name: 'DNA检测流程全部数据导出',
  801. heading: heading,
  802. specification: specification,
  803. data: dataset
  804. }
  805. ]
  806. );
  807. res.attachment('DNA检测流程全部数据导出.xlsx'); // This is sails.js specific (in general you need to set headers)
  808. return res.send(report);
  809. } else {
  810. let msg = encodeURI('没有数据可导出');
  811. return utils.jsonpAndEnd(res, `alert(decodeURI('${msg}'));window.close();`)
  812. }
  813. });
  814. });
  815. module.exports = router;