| | |
| | | import { Provide } from '@midwayjs/decorator'; |
| | | import { BaseService } from '@cool-midway/core'; |
| | | import { BaseService, CoolCommException } from '@cool-midway/core'; |
| | | import { InjectEntityModel } from '@midwayjs/orm'; |
| | | import { Repository } from 'typeorm'; |
| | | import { DataService } from '../../base/service/dataapi/dataapi'; |
| | | import { Devicegroup } from '../entity/devicegroup'; |
| | | import { Basedeviceinfo } from '../entity/basedeviceinfo'; |
| | | import { CoolSocket } from '@cool-midway/socket'; |
| | | /** |
| | | * 设备分组 |
| | | */ |
| | | @Provide() |
| | | export class DevicegroupService extends DataService { |
| | | @InjectEntityModel(Basedeviceinfo) |
| | | Basedeviceinfo: Repository<Basedeviceinfo>; |
| | | @InjectEntityModel(Devicegroup) |
| | | devicegroup: Repository<Devicegroup> |
| | | } |
| | | Devicegroup: Repository<Devicegroup>; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param query |
| | | */ |
| | | async page(query) { |
| | | const sql = `SELECT |
| | | * |
| | | FROM |
| | | t_base_device_group a |
| | | WHERE |
| | | 1=1 |
| | | ` |
| | | return this.sqlRenderPage(sql, query); |
| | | } |
| | | |
| | | |
| | | |
| | | async add(param: any) { |
| | | let ids = param.logic_id |
| | | let deviceinfo = this.Basedeviceinfo |
| | | let data_len = deviceinfo.find() |
| | | console.log((await data_len).length, "data_len") |
| | | let id_str = '' |
| | | if (ids.length == (await data_len).length) { |
| | | throw new CoolCommException("是否更新周期任务") |
| | | // console.log("是否更新周期任务") |
| | | // return await super.add(param) |
| | | } else { |
| | | for (let x = 0; x < ids.length; x++) { |
| | | let change_message = await deviceinfo.findOne({ logic_id: ids[x] }) |
| | | if (change_message.status == 1) { |
| | | id_str += `${ids[x]},` |
| | | } |
| | | } |
| | | if (id_str == '') { |
| | | if (id_str == '') { |
| | | for (let x = 0; x < ids.length; x++) { |
| | | let change_message = await deviceinfo.findOne({ logic_id: ids[x] }) |
| | | change_message.status = 1 |
| | | await this.nativeQuery( |
| | | 'update t_base_deviceinfo set status = 1 where logic_id = ?', |
| | | [ids[x]] |
| | | ); |
| | | } |
| | | } |
| | | param.logic_id = param.logic_id.toString(); |
| | | return await super.add(param) |
| | | } else { |
| | | throw new CoolCommException(`${id_str}设备已经在其他分组中存在,请重新选择`) |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | async update(param: any): Promise<void> { |
| | | console.log(param, "param") |
| | | param.logic_id = param.logic_id.toString(); |
| | | await this.Devicegroup.update(param.id, param) |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | async delete(ids: number[]) { |
| | | console.log(ids, "ids") |
| | | for (let i = 0; i < ids.length; i++) { |
| | | let change_message = this.Devicegroup.findOne({ id: ids[i] }) |
| | | let logic_id_s = (await change_message).logic_id.split(",") |
| | | console.log(logic_id_s, "logic_ids") |
| | | await this.nativeQuery( |
| | | `update t_base_deviceinfo set status = 0 where logic_id in (?)`, |
| | | [logic_id_s] |
| | | ) |
| | | await this.nativeQuery( |
| | | `delete from t_base_device_group where id = ?`, |
| | | [ids[i]] |
| | | ) |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |