work.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. @apiSuccess {Object[]} setting 基本信息
  16. @apiSuccess {String} setting.name 站点名
  17. @apiSuccess {Number} setting.farm 当前的农场ID
  18. @apiSuccess {Object[]} list 农事列表信息
  19. @apiSuccess {String} list.name 名称
  20. @apiSuccess {String} list.id ID
  21. @apiErrorExample 操作成功
  22. {"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}}}
  23. @apiErrorExample 操作失败
  24. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  25. """
  26. @auth
  27. def get(self):
  28. self.data['list'] = self.service('common').list('farm_work', state=True, page=True)
  29. if self.data['list']:
  30. for key, value in enumerate(self.data['list']):
  31. self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d')
  32. category = self.service('common').one('farm_work_category', id=value['category_id'])
  33. self.data['list'][key]['category'] = category['name']
  34. land = self.service('common').one('farm_work_land', id=value['land_id'])
  35. self.data['list'][key]['land'] = land['name']
  36. self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + ' - ' + land['name'] + '/' + category['name']
  37. self.out('yes', self.data)
  38. """
  39. @api {post} /work 更新农事记录
  40. @apiVersion 1.0.0
  41. @apiName updateWork
  42. @apiGroup Farm
  43. @apiParam {String} id 农事ID,为空则插入新记录
  44. @apiParam {String} update_pic 图片,多个逗号隔开
  45. @apiParam {String} update_category 农事方式ID
  46. @apiParam {String} update_land 地块ID
  47. @apiParam {String} update_workdate 农事时间:2017-10-10
  48. @apiParam {String} update_content 劳作内容
  49. @apiParam {String} update_amount 劳作数量
  50. @apiSuccess {Bool} status 状态
  51. @apiSuccess {String} msg 描述
  52. @apiSuccess {Number} code 状态码
  53. @apiErrorExample 操作成功
  54. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  55. @apiErrorExample 操作失败
  56. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  57. """
  58. @auth
  59. def post(self):
  60. id = self.input('id', None)
  61. update = {}
  62. update['pic'] = self.input('update_pic')
  63. update['category'] = self.input('update_category')
  64. update['land'] = self.input('update_land')
  65. update['workdate'] = self.input('update_workdate')
  66. update['content'] = self.input('update_content')
  67. update['amount'] = self.input('update_amount')
  68. if not update['category']:
  69. self.out(u'请选择农事方式')
  70. return
  71. if not update['land']:
  72. self.out(u'请选择地块')
  73. return
  74. if not update['workdate']:
  75. self.out(u'请输入农事时间')
  76. return
  77. if not update['content']:
  78. self.out(u'请输入劳作内容')
  79. return
  80. if not update['amount']:
  81. self.out(u'请输入劳作数量')
  82. return
  83. update['workdate'] = Demeter.mktime(update['workdate'], '%Y-%m-%d')
  84. state = self.service('common').update('farm_work', id, update)
  85. self.out('yes', {'id':state})
  86. class info_path(Load):
  87. """
  88. @api {get} /work/info 获取农事信息
  89. @apiVersion 1.0.0
  90. @apiName getWork
  91. @apiGroup Farm
  92. @apiSuccess {Object[]} setting 基本信息
  93. @apiSuccess {String} setting.name 站点名
  94. @apiSuccess {Number} setting.farm 当前的农场ID
  95. @apiSuccess {Object[]} info 农事信息
  96. @apiSuccess {String} info.name 名称
  97. @apiSuccess {String} info.id ID
  98. @apiErrorExample 操作成功
  99. {"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}}}
  100. @apiErrorExample 操作失败
  101. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  102. """
  103. @auth
  104. def get(self):
  105. id = self.input('id', None)
  106. if id:
  107. self.data['info'] = self.service('common').one('farm_work', {id:id})
  108. if self.data['info']:
  109. self.data['info']['workdates'] = Demeter.date(self.data['info']['workdate'], '%Y-%m-%d')
  110. self.out('yes', self.data)
  111. else:
  112. self.out('no')
  113. class land_path(Load):
  114. """
  115. @api {get} /work/land 获取农事地块列表
  116. @apiVersion 1.0.0
  117. @apiName getWorkLandList
  118. @apiGroup Farm
  119. @apiSuccess {Object[]} setting 基本信息
  120. @apiSuccess {String} setting.name 站点名
  121. @apiSuccess {Number} setting.farm 当前的农场ID
  122. @apiSuccess {Object[]} list 地块列表信息
  123. @apiSuccess {String} list.name 名称
  124. @apiSuccess {String} list.id ID
  125. @apiErrorExample 操作成功
  126. {"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"}]}}
  127. @apiErrorExample 操作失败
  128. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  129. """
  130. @auth
  131. def get(self):
  132. self.data['list'] = self.service('common').list('farm_work_land', state=True)
  133. self.out('yes', self.data)
  134. """
  135. @api {post} /work/land 更新地块
  136. @apiVersion 1.0.0
  137. @apiName updateWorkLand
  138. @apiGroup Farm
  139. @apiParam {String} id 地块ID,为空则插入新记录
  140. @apiParam {String} update_name 地块名称
  141. @apiSuccess {Bool} status 状态
  142. @apiSuccess {String} msg 描述
  143. @apiSuccess {Number} code 状态码
  144. @apiErrorExample 操作成功
  145. {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
  146. @apiErrorExample 操作失败
  147. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  148. """
  149. @auth
  150. def post(self):
  151. id = self.input('id', None)
  152. update = {}
  153. update['name'] = self.input('update_name')
  154. if not update['name']:
  155. self.out(u'请输入地块名称')
  156. return
  157. state = self.service('common').update('farm_work_land', id, update)
  158. self.out('yes', {'id':state})
  159. class category_path(Load):
  160. """
  161. @api {get} /work/category 获取农事分类列表
  162. @apiVersion 1.0.0
  163. @apiName getWorkCateList
  164. @apiGroup Farm
  165. @apiSuccess {Object[]} setting 基本信息
  166. @apiSuccess {String} setting.name 站点名
  167. @apiSuccess {Number} setting.farm 当前的农场ID
  168. @apiSuccess {Object[]} list 分类列表信息
  169. @apiSuccess {String} list.name 名称
  170. @apiSuccess {String} list.id ID
  171. @apiErrorExample 操作成功
  172. {"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"}]}}
  173. @apiErrorExample 操作失败
  174. {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
  175. """
  176. @auth
  177. def get(self):
  178. self.data['list'] = self.service('common').list('farm_work_category', state=True)
  179. self.out('yes', self.data)