123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web
- name:work.py 农事相关
- author:rabin
- """
- from __load__ import *
- class index_path(Load):
- """
- @api {get} /work 获取农事记录列表
- @apiVersion 1.0.0
- @apiName getWorkList
- @apiGroup Farm
- @apiSuccess {Object[]} setting 基本信息
- @apiSuccess {String} setting.name 站点名
- @apiSuccess {Number} setting.farm 当前的农场ID
- @apiSuccess {Object[]} list 农事列表信息
- @apiSuccess {String} list.name 名称
- @apiSuccess {String} list.id ID
- @apiErrorExample 操作成功
- {"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}}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def get(self):
- self.data['list'] = self.service('common').list('farm_work', state=True, page=True)
- if self.data['list']:
- for key, value in enumerate(self.data['list']):
- self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d')
- category = self.service('common').one('farm_work_category', id=value['category_id'])
- self.data['list'][key]['category'] = category['name']
- land = self.service('common').one('farm_work_land', id=value['land_id'])
- self.data['list'][key]['land'] = land['name']
- self.data['list'][key]['name'] = self.data['list'][key]['workdates'] + ' - ' + land['name'] + '/' + category['name']
- self.out('yes', self.data)
- """
- @api {post} /work 更新农事记录
- @apiVersion 1.0.0
- @apiName updateWork
- @apiGroup Farm
- @apiParam {String} id 农事ID,为空则插入新记录
- @apiParam {String} update_pic 图片,多个逗号隔开
- @apiParam {String} update_category 农事方式ID
- @apiParam {String} update_land 地块ID
- @apiParam {String} update_workdate 农事时间:2017-10-10
- @apiParam {String} update_content 劳作内容
- @apiParam {String} update_amount 劳作数量
- @apiSuccess {Bool} status 状态
- @apiSuccess {String} msg 描述
- @apiSuccess {Number} code 状态码
- @apiErrorExample 操作成功
- {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def post(self):
- id = self.input('id', None)
- update = {}
- update['pic'] = self.input('update_pic')
- update['category'] = self.input('update_category')
- update['land'] = self.input('update_land')
- update['workdate'] = self.input('update_workdate')
- update['content'] = self.input('update_content')
- update['amount'] = self.input('update_amount')
- if not update['category']:
- self.out(u'请选择农事方式')
- return
- if not update['land']:
- self.out(u'请选择地块')
- return
- if not update['workdate']:
- self.out(u'请输入农事时间')
- return
- if not update['content']:
- self.out(u'请输入劳作内容')
- return
- if not update['amount']:
- self.out(u'请输入劳作数量')
- return
- update['workdate'] = Demeter.mktime(update['workdate'], '%Y-%m-%d')
- state = self.service('common').update('farm_work', id, update)
- self.out('yes', {'id':state})
- class info_path(Load):
- """
- @api {get} /work/info 获取农事信息
- @apiVersion 1.0.0
- @apiName getWork
- @apiGroup Farm
- @apiSuccess {Object[]} setting 基本信息
- @apiSuccess {String} setting.name 站点名
- @apiSuccess {Number} setting.farm 当前的农场ID
- @apiSuccess {Object[]} info 农事信息
- @apiSuccess {String} info.name 名称
- @apiSuccess {String} info.id ID
- @apiErrorExample 操作成功
- {"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}}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def get(self):
- id = self.input('id', None)
- if id:
- self.data['info'] = self.service('common').one('farm_work', {id:id})
- if self.data['info']:
- self.data['info']['workdates'] = Demeter.date(self.data['info']['workdate'], '%Y-%m-%d')
-
- self.out('yes', self.data)
- else:
- self.out('no')
- class land_path(Load):
- """
- @api {get} /work/land 获取农事地块列表
- @apiVersion 1.0.0
- @apiName getWorkLandList
- @apiGroup Farm
- @apiSuccess {Object[]} setting 基本信息
- @apiSuccess {String} setting.name 站点名
- @apiSuccess {Number} setting.farm 当前的农场ID
- @apiSuccess {Object[]} list 地块列表信息
- @apiSuccess {String} list.name 名称
- @apiSuccess {String} list.id ID
- @apiErrorExample 操作成功
- {"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"}]}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def get(self):
- self.data['list'] = self.service('common').list('farm_work_land', state=True)
- self.out('yes', self.data)
- """
- @api {post} /work/land 更新地块
- @apiVersion 1.0.0
- @apiName updateWorkLand
- @apiGroup Farm
- @apiParam {String} id 地块ID,为空则插入新记录
- @apiParam {String} update_name 地块名称
- @apiSuccess {Bool} status 状态
- @apiSuccess {String} msg 描述
- @apiSuccess {Number} code 状态码
- @apiErrorExample 操作成功
- {"status": 1, "msg": "操作成功", "code": 0, "data": {}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def post(self):
- id = self.input('id', None)
- update = {}
- update['name'] = self.input('update_name')
- if not update['name']:
- self.out(u'请输入地块名称')
- return
- state = self.service('common').update('farm_work_land', id, update)
- self.out('yes', {'id':state})
- class category_path(Load):
- """
- @api {get} /work/category 获取农事分类列表
- @apiVersion 1.0.0
- @apiName getWorkCateList
- @apiGroup Farm
- @apiSuccess {Object[]} setting 基本信息
- @apiSuccess {String} setting.name 站点名
- @apiSuccess {Number} setting.farm 当前的农场ID
- @apiSuccess {Object[]} list 分类列表信息
- @apiSuccess {String} list.name 名称
- @apiSuccess {String} list.id ID
- @apiErrorExample 操作成功
- {"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"}]}}
- @apiErrorExample 操作失败
- {"status": 2, "msg": "\u64cd\u4f5c\u5931\u8d25", "code": 0, "data": {}}
- """
- @auth
- def get(self):
- self.data['list'] = self.service('common').list('farm_work_category', state=True)
- self.out('yes', self.data)
|