def __init__(self, broker_ip, broker_port, topic): self.created_at = utils.getNowTime() self.id = utils.createNewId() # --- Create and initialize MQTT client self.mqttClient = mqttClient(broker_ip, broker_port, self.id) self.mqttClient.connect() self.mqttClient.subscribe(topic) self.mqttClient.start()
def updateValues(self): values = self.poll() self.temperature = values['temperature'] self.moisture = values['moisture'] self.light = values['light'] self.battery = values['battery'] self.conductivity = values['conductivity'] self.last_update = utils.getNowTime()
def updateRoles(): data = request.form data = list(data)[0] data = json.loads(data) ro = role.query.filter(role.roleid == data["roleid"], role.cid == data["cid"]).first() if ro is not None: ro.menutid = data["menutid"] ro.freeid = data["freeid"] ro.enddate = utils.getNowTime() db.session.commit() print(ro) else: return json.dumps({"result": 404}) return json.dumps({"result": 200})
def addRoles(): data = request.form data = list(data)[0] data = json.loads(data) try: ro = role.query.filter(role.roleid != '9999').order_by( db.desc(role.roleid)).first() newRoleid = int(ro.roleid) + 1 print(newRoleid) newRo = role(newRoleid, data["name"], data["cid"], data["menuvalue"], data["freevalue"], utils.getNowTime(), data["desc"]) db.session.add(newRo) db.session.commit() except Exception as e: print(e) return json.dumps({"result": 500}) return json.dumps({"result": 200})
def pay(): data = request.form data = list(data)[0] data = json.loads(data) newTransId = 1 print(str(data)) try: us = users.query.filter(users.id == data["userid"]).first() rt = rticket.query.filter(rticket.id == data.get("id")).first() rt.statue = 4 oldTr = transhis.query.order_by(db.desc(transhis.id)).first() if oldTr is not None: newTransId = int(oldTr.id)+1 tr = transhis(newTransId,rt.id,data["sumamt"],rt.transbank,utils.getNowTime().split(" ")[0],data["userid"],us.username) db.session.add(tr) db.session.commit() except Exception as e: print(e.args) return json.dumps({"code": 500, "result": "转账失败!!!"}) return json.dumps({"code": 200, "result": "转账成功!!!"})
def __init__(self, esp_ip, broker_ip, broker_port, topic): self.created_at = utils.getNowTime() self.updateConfig(esp_ip, broker_ip, broker_port, topic) self.httpClient = Http()
def saveTicketInfo(): data = request.form data = list(data)[0] data = json.loads(data) print(data) if data["state"] == 2: result = checkData(data["ticketdata"], data["userinfo"]) print(result, "-------------") if result != '': return json.dumps({"data": result, "result": 500}) try: userInfo = data["userinfo"] ticketInfo = data["ticket"] staylist = data["ticketdata"]['staylist'] carlist = data["ticketdata"]['carlist'] lunchlist = data["ticketdata"]['lunchlist'] u = users.query.filter(users.id == userInfo["id"]).first() if ticketInfo["id"] != "": rt = rticket.query.filter(rticket.id == ticketInfo["id"]).first() rt.start = ticketInfo["date1"][0:10] if ticketInfo["date1"] != '' else '' rt.end = ticketInfo["date2"][0:10] if ticketInfo["date2"] != '' else '' rt.remark = ticketInfo["desc"] rt.userid = userInfo["id"] rt.username = u.username if u is not None else '' rt.cid = userInfo["cid"] rt.statue = data["state"] rt.sumamt = data["sumamt"], rt.submitdate = utils.getNowTime().split(" ")[0], rt.transbank = ticketInfo["bank"] for index, stay in enumerate(staylist): filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "STAY", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], stay["value"]["id"], 'STAY', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' st = stayinfo.query.filter(stayinfo.id == stay["value"]["id"]).first() st.address = stay["value"]["address"] st.stime = stay["value"]["amount"] st.stime = stay["value"]["detaildate"][0:10] if stay["value"]["detaildate"] != '' else '' if paddress != '': st.paddress = paddress for index, stay in enumerate(carlist): # 路径 staic/img/cid/uid/申请单id/stay[car,lunch]/ord .jpg .png # 复制票据到img中 filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "CAR", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], stay["value"]["id"], 'CAR', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' ca = carinfo.query.filter(carinfo.id == stay["value"]["id"]).first() ca.stime = stay["value"]["detaildate"][0:10] if stay["value"]["detaildate"] != '' else '' ca.saddress = stay["value"]["startaddress"] ca.eaddress = stay["value"]["endaddress"] ca.amount = stay["value"]["amount"] if paddress != '': ca.paddress = paddress for index, lunch in enumerate(lunchlist): # 路径 staic/img/cid/uid/申请单id/stay[car,lunch]/ord .jpg .png # 复制票据到img中 filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "LUNCH", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], lunch["value"]["id"], 'LUNCH', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' lu = lunchinfo.query.filter(lunchinfo.id == lunch["value"]["id"]).first() lu.stime = lunch["value"]["detaildate"][0:10] if lunch["value"]["detaildate"] != '' else '' lu.amount = stay["value"]["amount"] if paddress != '': lu.paddress = paddress else: oldRt = rticket.query.order_by(db.desc(rticket.id)).first() if oldRt is None: newRtId = 1 else: newRtId = oldRt.id + 1 newRt = rticket(newRtId, 0, 0, 0, ticketInfo["date1"][0:10] if ticketInfo["date1"] != '' else '', ticketInfo["date2"][0:10] if ticketInfo["date2"] != '' else '', ticketInfo["desc"], userInfo["id"], u.username if u is not None else '', userInfo["cid"], data["state"], data["sumamt"], utils.getNowTime().split(" ")[0], '', '', ticketInfo["bank"]) db.session.add(newRt) # 处理住宿 oldStay = stayinfo.query.order_by(db.desc(stayinfo.id)).first() if oldStay is None: newStayId = 1 else: newStayId = oldStay.id + 1 for index, stay in enumerate(staylist): # 路径 staic/img/cid/uid/申请单id/stay[car,lunch]/ord .jpg .png # 复制票据到img中 newStayId += 1 filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "STAY", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], newRtId, 'STAY', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' newStay = stayinfo(newStayId, newRtId, stay["value"]["detaildate"][0:10] if stay["value"]["detaildate"] != '' else '', stay["value"]["address"], stay["value"]["amount"], paddress) db.session.add(newStay) oldCar = carinfo.query.order_by(db.desc(carinfo.id)).first() if oldCar is None: newCarId = 1 else: newCarId = oldCar.id + 1 for index, stay in enumerate(carlist): # 路径 staic/img/cid/uid/申请单id/stay[car,lunch]/ord .jpg .png # 复制票据到img中 newCarId += 1 filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "CAR", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], newRtId, 'CAR', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' newCar = carinfo(newCarId, newRtId, stay["value"]["detaildate"][0:10] if stay["value"]["detaildate"] != '' else '', stay["value"]["startaddress"], stay["value"]["endaddress"], stay["value"]["amount"], paddress) db.session.add(newCar) oldLunch = carinfo.query.order_by(db.desc(carinfo.id)).first() if oldLunch is None: newLunchId = 1 else: newLunchId = oldLunch.id + 1 for index, lunch in enumerate(lunchlist): newLunchId += 1 filePath = "static/imgtemp/{}{}{}{}.".format(userInfo["cid"], userInfo["id"], "LUNCH", index) newFilePath = "static/img/{}{}{}{}{}.".format(userInfo["cid"], userInfo["id"], newRtId, 'LUNCH', index) if os.path.exists(filePath + 'jpg'): shutil.copy(filePath + 'jpg', newFilePath + 'jpg') paddress = newFilePath + 'jpg' elif os.path.exists(filePath + 'png'): shutil.copy(filePath + 'png', newFilePath + 'png') paddress = newFilePath + 'png' else: paddress = '' newLunch = lunchinfo(newLunchId, newRtId, lunch["value"]["detaildate"][0:10] if lunch["value"]["detaildate"] != '' else '', lunch["value"]["amount"], paddress) db.session.add(newLunch) except Exception as e: print(e.args) return json.dumps({"result": 500, "msg": '''保存失败!!! 请联系'''}) db.session.commit() return json.dumps({"result": 200})
def setLastValue(self, value): self.last_value = value self.last_value_time = utils.getNowTime()