| | |
| | | ```bash |
| | | $ npm i |
| | | $ npm run dev |
| | | $ open http://localhost:8001/ |
| | | $ open http://localhost:/ |
| | | ``` |
| | | |
| | | 注: `npm i`如果安装失败可以尝试使用[cnpm](https://developer.aliyun.com/mirror/NPM?from=tnpm),或者切换您的镜像源 |
| | |
| | | }, |
| | | "author": "cool-js.com", |
| | | "license": "MIT" |
| | | } |
| | | } |
| | |
| | | } |
| | | }); |
| | | } |
| | | console.log(menus, "menus") |
| | | return menus; |
| | | } |
| | | |
| | |
| | | FROM |
| | | t_sys_menu a |
| | | ${this.setSql( |
| | | !isAdmin, |
| | | 'JOIN t_sys_role_menu b on a.id = b.menuId AND b.roleId in (?)', |
| | | [roleIds] |
| | | )} |
| | | !isAdmin, |
| | | 'JOIN t_sys_role_menu b on a.id = b.menuId AND b.roleId in (?)', |
| | | [roleIds] |
| | | )} |
| | | GROUP BY a.id |
| | | ORDER BY |
| | | orderNum ASC`); |
| | |
| | | * @param query |
| | | */ |
| | | async page(query) { |
| | | console.log(query, "page 打印 query") |
| | | const { keyWord, status, departmentIds = [] } = query; |
| | | const permsDepartmentArr = await this.baseSysPermsService.departmentIds( |
| | | this.ctx.admin.userId |
| | |
| | | LEFT JOIN t_sys_department d on a.departmentId = d.id |
| | | WHERE 1 = 1 |
| | | ${this.setSql( |
| | | !_.isEmpty(departmentIds), |
| | | 'and a.departmentId in (?)', |
| | | [departmentIds] |
| | | )} |
| | | !_.isEmpty(departmentIds), |
| | | 'and a.departmentId in (?)', |
| | | [departmentIds] |
| | | )} |
| | | ${this.setSql(status, 'and a.status = ?', [status])} |
| | | ${this.setSql(keyWord, 'and (a.name LIKE ? or a.username LIKE ?)', [ |
| | | `%${keyWord}%`, |
| | | `%${keyWord}%`, |
| | | ])} |
| | | `%${keyWord}%`, |
| | | `%${keyWord}%`, |
| | | ])} |
| | | ${this.setSql(true, 'and a.username != ?', ['admin'])} |
| | | ${this.setSql( |
| | | this.ctx.admin.username !== 'admin', |
| | | 'and a.departmentId in (?)', |
| | | [!_.isEmpty(permsDepartmentArr) ? permsDepartmentArr : [null]] |
| | | )} |
| | | this.ctx.admin.username !== 'admin', |
| | | 'and a.departmentId in (?)', |
| | | [!_.isEmpty(permsDepartmentArr) ? permsDepartmentArr : [null]] |
| | | )} |
| | | GROUP BY a.id |
| | | `; |
| | | return this.sqlRenderPage(sql, query); |
| | |
| | | * @param param |
| | | */ |
| | | async add(param) { |
| | | console.log(param, "param") |
| | | const exists = await this.baseSysUserEntity.findOne({ |
| | | username: param.username, |
| | | }); |
| | | console.log(exists, "exists") |
| | | if (!_.isEmpty(exists)) { |
| | | throw new CoolCommException('用户名已经存在~'); |
| | | } |
| | |
| | | import { ALL, Body, Get, Inject, Post, Provide, Query } from '@midwayjs/decorator'; |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { Taskimmediately } from '../../entity/taskimmediately'; |
| | | import { TaskimmediatelyService } from '../../../business/service/taskimmediately'; |
| | | import { Immediatetask } from '../../service/immediatetask'; |
| | | import { DataController } from '../../../base/controller/dataController'; |
| | | import { SocketHandler } from '../../../../../socket/socketHandle'; |
| | | import { RpcService } from '../../../base/service/dataapi/rpcservice'; |
| | |
| | | */ |
| | | @Provide() |
| | | @CoolController({ |
| | | api: ['delete', 'update', 'list', 'page', 'info'], |
| | | api: ['add', 'delete', 'update', 'list', 'page', 'info'], |
| | | entity: Taskimmediately, |
| | | // service: TaskimmediatelyService, |
| | | service: Immediatetask, |
| | | }) |
| | | export class TaskimmediatelyController extends DataController { |
| | | |
| | | @Inject() |
| | | taskimmediatelyService: TaskimmediatelyService; |
| | | |
| | | @Inject() |
| | | socketHandler: SocketHandler |
| | |
| | | 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]] |
| | | ) |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | @InjectEntityModel(Devicegroup) |
| | | Devicegroup: Repository<Devicegroup>; |
| | | |
| | | /** |
| | | * 描述 |
| | | */ |
| | | // async add(param: any) { |
| | | // console.log(param, "dddddddd") |
| | | // const { logic_id } = param |
| | | // const devicegroup = this.Devicegroup |
| | | // await this.Devicegroup.insert(param) |
| | | // return await super.add(param) |
| | | // } |
| | | |
| | | |
| | | async delete(logic_id: any) { |
| | | console.log(this.ctx, "ddd") |
| | | await this.nativeQuery( |
| | | 'DELETE t_base_deviceinfo,t_base_device_group FROM t_base_deviceinfo,t_base_device_group WHERE t_base_deviceinfo.logic_id = t_base_device_group.logic_id AND t_base_deviceinfo.id in (?)', |
| | | [logic_id] |
| | | ); |
| | | await this.Basedeviceinfo.delete(logic_id) |
| | | |
| | | } |
| | | |
| | | |
| | | async page(query) { |
| | | |
| | | // const { keyWord, status, departmentIds = [] } = query; |
| | | // const permsDepartmentArr = await this.Basedeviceinfo.id( |
| | | // this.ctx.admin.userId |
| | | // ); // 部门权限 |
| | | const sql = ` |
| | | SELECT a.*,b.configurator FROM t_base_deviceinfo a,t_base_device_group b WHERE 1 = 1`; |
| | | return this.sqlRenderPage(sql, query); |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | import { Provide } from '@midwayjs/decorator'; |
| | | 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 Immediatetask extends DataService { |
| | | @InjectEntityModel(Basedeviceinfo) |
| | | Basedeviceinfo: Repository<Basedeviceinfo>; |
| | | @InjectEntityModel(Devicegroup) |
| | | Devicegroup: Repository<Devicegroup>; |
| | | |
| | | |
| | | |
| | | async add(param: any) { |
| | | console.log(param, "parm") |
| | | |
| | | param.logic_ids = param.logic_ids.toString(); |
| | | return await super.add(param) |
| | | |
| | | } |
| | | } |
| | |
| | | view, |
| | | // 必须,不可移除, https://typeorm.io 打不开? https://typeorm.biunav.com/zh/ |
| | | orm, |
| | | // swagger文档 访问地址 http://127.0.0.1:8001/swagger-ui/index.html |
| | | // swagger文档 访问地址 http://127.0.0.1:/swagger-ui/index.html |
| | | { |
| | | component: swagger, |
| | | enabledEnvironment: ['local'], |