当前位置: 首页 > article >正文

cooladmin 后端 查询记录

查询记录:pageQueryOp中列表查询的group by

node ts controller代码如下

import { CoolController, BaseController } from '@cool-midway/core';
import { Inject, Post, Get, Param } from '@midwayjs/decorator';
import { ComparePricesPlanInfoEntity } from '../../entity/comparePricesPlanInfo';
import { InventoryOrderInfoService } from '../../service/inventoryOrderInfo';
import { PlanInfoEntity } from '../../entity/planInfo';
import { ConsumableDetailEntity } from '../../../consumable/entity/detail';
import { Context } from 'vm';
import { OrderEntity } from '../../entity/order';
import { ComparePricesEntity } from '../../entity/comparePrices';
import { ComparePricesInfoEntity } from '../../entity/comparePricesInfo';
import { VendorEntity } from '../../entity/vendor';
import { QueryBuilder } from 'typeorm';

/**
 * 描述
 */
@CoolController({
    api: ['add', 'delete', 'update', 'info', 'list', 'page'],
    entity: OrderEntity,
    service: InventoryOrderInfoService,
    pageQueryOp: {
        // keyWordLikeFields: ['vendorName'],
        // 指定返回字段
        select: [
            //采购单信息
            'a.id',
            'a.state',//状态:待确认(0)、已发货(1)、已收货(2)
            'a.inspectorName',//验收人员姓名
            'a.acceptanceContent',//验收内容
            'a.resultState',//验收结果状态:未验收(0)、通过(1)、不通过(2)
            'a.reason',//通过/不通过原因
            'a.createBy',//创建者
            'a.createTime',//创建时间
            'a.code',//订单编码
            'a.title',//订单标题
            'a.content',//订单内容
            'a.remark as orderRemark',//订单备注
            //比价
            'cp.comparePricesInfoId',//比价信息ID
            'cp.consumableDetailId',//耗材ID
            //采用价格信息
            'cpinfo.quotedPrice',//报价
            'cpinfo.serviceContent',//服务内容
            'cpinfo.deliveryTime',//货期
            'cpinfo.isProposed',//拟用采纳
            'cpinfo.vendorId',//供应商ID
            // 'cpinfo.consumableDetailId',//耗材ID
            'cpinfo.planInfoId',//计划明细表ID
            'cpinfo.vcid',//供应商-耗材关联表ID
            //耗材信息
            'c.consumableNo',
            'c.consumableName',
            'c.brand',
            'c.model',
            'c.type',
            'c.remark as consumableDetailRemark',
            'c.status',
            //供应商信息
            'v.vendorCode',
            'v.vendorName',
            'v.vendorNick',
            'v.vendorEn',
            //采购计划数量
            'SUM(pinfo.number) as sumNum',
            //采购计划规格
            'pinfo.specification',
            //采购单信息
            // 'a.id',
            // 'a.planInfoId',
            // 'a.comparePricesId',
            // 'a.createTime',
            // 'a.updateTime',
            // //采购计划详情
            // 'b.planId',
            // 'b.consumableDetailId',
            // 'b.specification',
            // 'b.number',
            // 'b.budget',
            // 'b.deliveryTime',
            // // 'b.createBy',
            // // 'b.createTime',
        ],
        // 联表查询
        join: [
            //ComparePricesEntity
            {
                entity: ComparePricesEntity,
                alias: 'cp',
                condition: 'a.comparePricesId = cp.id',
                type: 'leftJoin',
            },
            //ComparePricesInfoEntity
            {
                entity: ComparePricesInfoEntity,
                alias: 'cpinfo',
                condition: 'cp.comparePricesInfoId = cpinfo.id',
                type: 'leftJoin',
            },
            //ConsumableDetailEntity
            {
                entity: ConsumableDetailEntity,
                alias: 'c',
                condition: 'cp.consumableDetailId = c.id',
                type: 'leftJoin',
            },
            //VendorEntity
            {
                entity: VendorEntity,
                alias: 'v',
                condition: 'cpinfo.vendorId = v.id',
                type: 'leftJoin',
            },
            //ComparePricesPlanInfoEntity
            {
                entity: ComparePricesPlanInfoEntity,
                alias: 'cppinfo',
                condition: 'a.comparePricesId = cppinfo.comparePricesId',
                type: 'leftJoin',
            },
            //PlanInfoEntity
            {
                entity: PlanInfoEntity,
                alias: 'pinfo',
                condition: 'cppinfo.planInfoId = pinfo.id',
                type: 'leftJoin',
            },
            // {
            //     entity: OrderEntity,
            //     alias: 'o',
            //     condition: 'a.comparePricesId = o.comparePricesId',
            //     type: 'leftJoin',
            // },
        ],
        where: async (ctx: Context) => {
            return [
                // ['a.id not in (SELECT comparePricesId from pi_purchase_order)', {}],
                // ['a.comparePricesId = :comparePricesId', { comparePricesId: ctx.request.body.comparePricesId }]
            ];
        },
        extend: (queryBuilder: QueryBuilder<any>) => {
            queryBuilder.groupBy([
                'a.id',
                'pinfo.specification',
            ]);
        },
        addOrderBy: {
            'a.createTime': 'asc',
        },
    },
})
export class InventoryOrderInfoController extends BaseController {
    @Inject()
    inventoryOrderInfoService: InventoryOrderInfoService;
}

具体的SQL执行语句:

SELECT
	a.id,
	a.state,
	a.inspectorName,
	a.acceptanceContent,
	a.resultState,
	a.reason,
	a.createBy,
	a.createTime,
	a.CODE,
	a.title,
	a.content,
	a.remark AS orderRemark,
	cp.comparePricesInfoId,
	cp.consumableDetailId,
	cpinfo.quotedPrice,
	cpinfo.serviceContent,
	cpinfo.deliveryTime,
	cpinfo.isProposed,
	cpinfo.vendorId,
	cpinfo.planInfoId,
	cpinfo.vcid,
	c.consumableNo,
	c.consumableName,
	c.brand,
	c.model,
	c.type,
	c.remark AS consumableDetailRemark,
	c.STATUS,
	v.vendorCode,
	v.vendorName,
	v.vendorNick,
	v.vendorEn,
	SUM( pinfo.number ) AS sumNum,
	pinfo.specification 
FROM
	`pi_purchase_order` `a`
	LEFT JOIN `pi_compare_prices` `cp` ON `a`.`comparePricesId` = `cp`.`id`
	LEFT JOIN `pi_compare_prices_info` `cpinfo` ON `cp`.`comparePricesInfoId` = `cpinfo`.`id`
	LEFT JOIN `consumable_detail` `c` ON `cp`.`consumableDetailId` = `c`.`id`
	LEFT JOIN `pi_vendor` `v` ON `cpinfo`.`vendorId` = `v`.`id`
	LEFT JOIN `pi_compare_prices_plan_info` `cppinfo` ON `a`.`comparePricesId` = `cppinfo`.`comparePricesId`
	LEFT JOIN `pi_plan_info` `pinfo` ON `cppinfo`.`planInfoId` = `pinfo`.`id` 
GROUP BY
	`a`.`id`,
	pinfo.specification 
ORDER BY
	`a`.`createTime` ASC,
	`createTime` DESC


http://www.kler.cn/a/394003.html

相关文章:

  • WordPress HTTPS 配置问题解决方案
  • 性能测试|JMeter接口与性能测试项目
  • ubuntu20.04安装FLIR灰点相机BFS-PGE-16S2C-CS的ROS驱动
  • Android OpenGL ES详解——立方体贴图
  • 【日志】392.判断子序列
  • 若依笔记(八):Docker容器化并部署到公网
  • 关于sass在Vue3中编写bem框架报错以及警告问题记录
  • 035_Progress_Dialog_in_Matlab中的进度条对话框
  • Linux各种解压命令汇总
  • 数字图像处理(c++ opencv):图像复原与重建-常见的滤波方法--自适应滤波器
  • 传奇996_20——Ui对应的id介绍
  • 软件测试面试题(800道)【附带答案】持续更新...
  • Ubuntu 18.04 配置sources.list源文件(无法安全地用该源进行更新,所以默认禁用该源)
  • 中仕公考怎么样?事业编面试不去有影响吗?
  • 力扣题解(统计满足k约束的子字符串数目)
  • kafka中topic的数据抽取不到hdfs上问题解决
  • 什么是‌‌‌‌‌‌C#,有什么特点
  • 怎么选择香港服务器的线路?解决方案
  • Flutter Getx状态管理
  • React中常用的hook函数(四)——useRef、useNavigate、useLocation和useSearchParams
  • 后端-实现excel的导出功能(超详细讲解)
  • 【Pytorch】神经网络介绍|激活函数|使用pytorch搭建方法
  • .Net Core根据文件名称自动注入服务
  • Vim 编辑器学习笔记
  • wordpress functions文件的作用及详细说明
  • 网络安全:守护数字世界的坚固防线