work.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web
  5. name:work.py 农事相关
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class index_path(Load):
  10. """
  11. @api {get} /work 获取农事记录列表
  12. @apiVersion 1.0.0
  13. @apiName getWorkList
  14. @apiGroup Farm
  15. @apiParam {String} page 页数
  16. @apiSuccess {Object[]} setting 基本信息
  17. @apiSuccess {String} setting.name 站点名
  18. @apiSuccess {Number} setting.farm 当前的农场ID
  19. @apiSuccess {Object[]} list 农事列表信息
  20. @apiSuccess {String} list.name 名称
  21. @apiSuccess {String} list.id ID
  22. @apiSuccess {Object[]} page 分页信息
  23. @apiSuccess {String} page.current 当前页
  24. @apiSuccess {String} page.total 总页数
  25. @apiSuccess {String} page.num 每页数据条数
  26. @apiSuccess {String} page.totalNum 总数据条数
  27. @apiErrorExample 操作成功
  28. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
  29. @apiErrorExample 操作失败
  30. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  31. """
  32. @auth
  33. def get(self):
  34. self.data['list'] = self.service('common').list('farm_work', state=True, page=True)
  35. if self.data['list']:
  36. for key, value in enumerate(self.data['list']):
  37. self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d')
  38. category = self.service('common').one('farm_work_category', id=value['category_id'])
  39. self.data['list'][key]['category'] = category['name']
  40. land = self.service('common').one('farm_work_land', id=value['land_id'])
  41. self.data['list'][key]['land'] = land['name']
  42. self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + ' - ' + land['name'] + '/' + category['name']
  43. self.out('yes', self.data)
  44. """
  45. @api {post} /work 更新农事记录
  46. @apiVersion 1.0.0
  47. @apiName updateWork
  48. @apiGroup Farm
  49. @apiParam {String} id 农事ID,为空则插入新记录
  50. @apiParam {String} update_pic 图片,多个逗号隔开
  51. @apiParam {String} update_category 农事方式ID
  52. @apiParam {String} update_land 地块ID
  53. @apiParam {String} update_workdate 农事时间:2017-10-10
  54. @apiParam {String} update_content 劳作内容
  55. @apiParam {String} update_amount 劳作数量
  56. @apiSuccess {Bool} status 状态
  57. @apiSuccess {String} msg 描述
  58. @apiSuccess {Number} code 状态码
  59. @apiErrorExample 操作成功
  60. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  61. @apiErrorExample 操作失败
  62. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  63. """
  64. @auth
  65. def post(self):
  66. id = self.input('id', None)
  67. if not id:
  68. self.out('no')
  69. return
  70. update = {}
  71. update['pic'] = self.input('update_pic')
  72. update['category'] = self.input('update_category')
  73. update['land'] = self.input('update_land')
  74. update['workdate'] = self.input('update_workdate')
  75. update['content'] = self.input('update_content')
  76. update['amount'] = self.input('update_amount')
  77. if not update['category']:
  78. self.out(u'请选择农事方式')
  79. return
  80. if not update['land']:
  81. self.out(u'请选择地块')
  82. return
  83. if not update['workdate']:
  84. self.out(u'请输入农事时间')
  85. return
  86. if not update['content']:
  87. self.out(u'请输入劳作内容')
  88. return
  89. if not update['amount']:
  90. self.out(u'请输入劳作数量')
  91. return
  92. update['workdate'] = Demeter.mktime(update['workdate'], '%Y-%m-%d')
  93. state = self.service('common').update('farm_work', id, update)
  94. self.out('yes', {'id':state})
  95. class info_path(Load):
  96. """
  97. @api {get} /work/info 获取农事信息
  98. @apiVersion 1.0.0
  99. @apiName getWork
  100. @apiGroup Farm
  101. @apiSuccess {Object[]} setting 基本信息
  102. @apiSuccess {String} setting.name 站点名
  103. @apiSuccess {Number} setting.farm 当前的农场ID
  104. @apiSuccess {Object[]} info 农事信息
  105. @apiSuccess {String} info.name 名称
  106. @apiSuccess {String} info.id ID
  107. @apiErrorExample 操作成功
  108. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"pic": "http://192.168.15.10:8087/upload/2017/08/30/455f9d6c26b5c989b32eda1809e58d5f.jpg", "method_id": null, "land_id": "249be20d-5759-5af0-9859-b770d9f44e2a", "farm_id": 1, "state": true, "amount": "100ml", "workdate": 1504105397, "category_id": "9365ea66-be55-56f7-a511-059fc85a9478", "cdate": 1504076614, "id": "19e05f00-ae55-5605-be12-86dcd2866df9"}], "page": {"current": 1, "ajax": false, "total": 1.0, "num": 15, "totalNum": 1}}}
  109. @apiErrorExample 操作失败
  110. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  111. """
  112. @auth
  113. def get(self):
  114. id = self.input('id', None)
  115. if id:
  116. self.data['info'] = self.service('common').one('farm_work', {id:id})
  117. if self.data['info']:
  118. self.data['info']['workdates'] = Demeter.date(self.data['info']['workdate'], '%Y-%m-%d')
  119. self.out('yes', self.data)
  120. else:
  121. self.out('no')
  122. class land_path(Load):
  123. """
  124. @api {get} /work/land 获取农事地块列表
  125. @apiVersion 1.0.0
  126. @apiName getWorkLandList
  127. @apiGroup Farm
  128. @apiSuccess {Object[]} setting 基本信息
  129. @apiSuccess {String} setting.name 站点名
  130. @apiSuccess {Number} setting.farm 当前的农场ID
  131. @apiSuccess {Object[]} list 地块列表信息
  132. @apiSuccess {String} list.name 名称
  133. @apiSuccess {String} list.id ID
  134. @apiErrorExample 操作成功
  135. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1504074548, "id": "249be20d-5759-5af0-9859-b770d9f44e2a", "name": "test"}]}}
  136. @apiErrorExample 操作失败
  137. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  138. """
  139. @auth
  140. def get(self):
  141. self.data['list'] = self.service('common').list('farm_work_land', state=True)
  142. self.out('yes', self.data)
  143. """
  144. @api {post} /work/land 更新地块
  145. @apiVersion 1.0.0
  146. @apiName updateWorkLand
  147. @apiGroup Farm
  148. @apiParam {String} id 地块ID,为空则插入新记录
  149. @apiParam {String} update_name 地块名称
  150. @apiSuccess {Bool} status 状态
  151. @apiSuccess {String} msg 描述
  152. @apiSuccess {Number} code 状态码
  153. @apiErrorExample 操作成功
  154. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  155. @apiErrorExample 操作失败
  156. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  157. """
  158. @auth
  159. def post(self):
  160. id = self.input('id', None)
  161. update = {}
  162. update['name'] = self.input('update_name')
  163. if not update['name']:
  164. self.out(u'请输入地块名称')
  165. return
  166. state = self.service('common').update('farm_work_land', id, update)
  167. self.out('yes', {'id':state})
  168. class category_path(Load):
  169. """
  170. @api {get} /work/category 获取农事分类列表
  171. @apiVersion 1.0.0
  172. @apiName getWorkCateList
  173. @apiGroup Farm
  174. @apiSuccess {Object[]} setting 基本信息
  175. @apiSuccess {String} setting.name 站点名
  176. @apiSuccess {Number} setting.farm 当前的农场ID
  177. @apiSuccess {Object[]} list 分类列表信息
  178. @apiSuccess {String} list.name 名称
  179. @apiSuccess {String} list.id ID
  180. @apiErrorExample 操作成功
  181. {"status": 1, "msg": "yes", "code": 0, "data": {"setting": {"farm": 1, "user": 0, "name": "\u519c\u5c0f\u76d2", "copyright": "2017 nongxiaohe.com v1.0.0", "site": "http://www.nongxiaohe.com/"}, "list": [{"state": true, "farm_id": 1, "cdate": 1504074837, "id": "9365ea66-be55-56f7-a511-059fc85a9478", "name": "\u65bd\u80a5"}]}}
  182. @apiErrorExample 操作失败
  183. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  184. """
  185. @auth
  186. def get(self):
  187. self.data['list'] = self.service('common').list('farm_work_category', state=True)
  188. self.out('yes', self.data)