123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import {sqlHandle} from "../config/db.js";
- import {isValue} from "../../util/index.js";
- import PageResult from "../config/page.js";
- import SourceEntity from "../entity/source-entity.js";
- const SourceService = {
- list: async ({name}) => {
- let sql = 'SELECT * FROM ship_test_source'
- let where = ['del_flag = 0']
- if (isValue(name)) {
- where.push(`name LIKE "%${name}%"`)
- }
- if (where.length > 0) {
- sql += ' ' + `WHERE ${where.join(' AND ')}`
- }
- const result = await sqlHandle(sql)
- return result.map(v => new SourceEntity(v))
- },
- page: async ({pageNum, pageSize, name}) => {
- let sql = 'SELECT * FROM ship_test_source'
- let where = ['del_flag = 0']
- if (isValue(name)) {
- where.push(`name LIKE "%${name}%"`)
- }
- if (where.length > 0) {
- sql += ' ' + `WHERE ${where.join(' AND ')}`
- }
- const result = await PageResult(sql, pageNum, pageSize, SourceEntity)
- return result
- },
- add: async (form) => {
- const sql = 'INSERT INTO ship_test_source (name, remark, sort) VALUES (?, ?, ?)'
- const sourceEntity = new SourceEntity(form)
- const values = [
- sourceEntity.name,
- sourceEntity.remark,
- sourceEntity.sort,
- ]
- const result = await sqlHandle(sql, values)
- return result
- },
- }
- export default SourceService
|