###大屏所有sql语句


###试验次数
#sql("cs")
SELECT COUNT(*)c,

#if(CREATED=='year')
to_char(e.CREATED,'yyyy')x
#end
#if(CREATED=='quarter')
to_char(e.CREATED,'q')x
#end
#if(CREATED=='month')
to_char(e.CREATED,'mm')x
#end
FROM
    tlk_examine e
        LEFT OUTER JOIN t_user t ON e.author = t.id
        LEFT OUTER JOIN t_department d ON t.defaultdepartment = d.id
        WHERE 1=1
#if(ID)
AND e.author_dept_index LIKE #para(ID, "like")
#end
#if(item_product)
AND e.item_product =#para(item_product)
#end
#if(CREATED=='year')
GROUP BY to_char(e.CREATED,'yyyy')
#end
 #if(CREATED=='quarter')
AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
GROUP BY to_char(e.CREATED,'q')
#end
#if(CREATED=='month')
AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
GROUP BY to_char(e.CREATED,'mm')
#end
ORDER BY x ASC
#end

###样机改装信息
#sql("yj")
SELECT
    ITEM_NAME,ITEM_XL_NUM,ITEM_KEY
FROM
    tlk_myjcs
WHERE item_upbh IS NULL
#if(ITEM_NAME)
AND (ITEM_NAME ||ITEM_XL_NUM) like #para(ITEM_NAME, "like")
#end
#if(begin)
	AND created BETWEEN to_date(#para(begin), 'yyyy-mm-dd hh24:mi:ss' )
	AND to_date(#para(end), 'yyyy-mm-dd hh24:mi:ss' )
#end
GROUP BY item_name,item_xl_num,item_key
#end

###实验完成率
#sql("finish_s")
select count(0)as count, case  when e.STATELABEL = '结束' then '结束' else '未结束' end AS tag  from tlk_examine e
left outer join t_user on t_user.ID=author
left outer join t_department on t_user.defaultdepartment=t_department.ID
where e.STATELABEL is not null

#if(CREATED=='year')
AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
#end
#if(CREATED=='quarter')
AND to_char(e.CREATED,'q')=to_char(sysdate,'q') AND to_char(e.CREATED,'yy')=to_char(sysdate,'yy')
#end
#if(CREATED=='month')
AND to_char(e.CREATED,'yyyy-mm')=to_char(sysdate,'yyyy-mm')
#end
group by  case  when e.STATELABEL = '结束'  then '结束' else '未结束' end
#end



###待完成试验
#sql("no_examine")
SELECT
    e.ITEM_TITLE,e.STATELABEL,e.AUDITORNAMES,t.ITEM_VTIME
FROM
    tlk_examine e  LEFT OUTER JOIN
    ( SELECT docid, round(SUM(to_number(to_date(to_char(processtime, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') - to_date(to_char(actiontime, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60)) AS item_vtime
      FROM t_relationhis GROUP BY docid) t ON t.docid=e.id
WHERE statelabel != '结束'
AND statelabel != '终止'
AND statelabel IS NOT NULL

#if(ITEM_TITLE2)
AND e.ITEM_TITLE LIKE #para(ITEM_TITLE2, "like")
#end

#if(CREATED=='year')
AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
#end
#if(CREATED=='quarter')
AND to_char(e.CREATED,'q')=to_char(sysdate,'q') AND to_char(e.CREATED,'yy')=to_char(sysdate,'yy')
#end
#if(CREATED=='month')
AND to_char(e.CREATED,'yyyy-mm')=to_char(sysdate,'yyyy-mm')
#end
ORDER BY e.CREATED DESC
#end

###已完成试验
#sql("examine")
SELECT
    e.ITEM_TITLE,
    e.ITEM_TEST_CONCLUSION
FROM
    tlk_examine e
WHERE (e.statelabel = '结束' OR e.statelabel = '终止')

#if(ITEM_TITLE1)
AND e.ITEM_TITLE LIKE #para(ITEM_TITLE1, "like")
#end

#if(CREATED=='year')
AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
#end
#if(CREATED=='quarter')
AND to_char(e.CREATED,'q')=to_char(sysdate,'q') AND to_char(e.CREATED,'yy')=to_char(sysdate,'yy')
#end
#if(CREATED=='month')
AND to_char(e.CREATED,'yyyy-mm')=to_char(sysdate,'yyyy-mm')
#end
ORDER BY e.CREATED DESC
#end


###样机信息:样机数量
#sql("yj_sl")
SELECT COUNT( * )C,
#if(CREATED=='year')
e.ITEM_PRO X
#end
#if(CREATED=='quarter')
to_char(e.CREATED, 'q' )X
#end
#if(CREATED=='month')
to_char(e.CREATED, 'mm' )X
#end
FROM tlk_myjcs e
WHERE 1 = 1
  AND e.item_upbh IS NULL
  AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
#if(ITEM_PRO)
AND e.ITEM_PRO =#para(ITEM_PRO)
#end
#if(CREATED=='year')
GROUP BY e.ITEM_PRO
#end
#if(CREATED=='quarter')
GROUP BY to_char(e.CREATED, 'q' )
ORDER BY x ASC
#end
#if(CREATED=='month')
GROUP BY to_char(e.CREATED, 'mm' )
ORDER BY x ASC
#end
#end

###样机信息:样机试验次数
#sql("yj_cs")
SELECT  COUNT(*)C,
 #if(CREATED=='year')
e.ITEM_PRO X
#end
#if(CREATED=='quarter')
to_char(e.CREATED, 'q' )X
#end
#if(CREATED=='month')
to_char(e.CREATED, 'mm' )X
#end
FROM tlk_wyjcs e
WHERE 1=1
  AND e.item_upbh is null
  AND to_char(e.CREATED,'yyyy')=to_char(sysdate,'yyyy')
#if(ITEM_PRO)
AND e.ITEM_PRO =#para(ITEM_PRO)
#end
#if(CREATED=='year')
GROUP BY e.item_pro
#end
#if(CREATED=='quarter')
GROUP BY to_char(e.CREATED, 'q' )
ORDER BY x ASC
#end
#if(CREATED=='month')
GROUP BY to_char(e.CREATED, 'mm' )
ORDER BY x ASC
#end

#end

###样机列表
#sql("yj_list")
SELECT ITEM_NAME,ITEM_VERSION,ITEM_XL_NUM,CREATED
FROM tlk_myjcs
WHERE ITEM_UPBH IS NULL
#if(ITEM_NAMES)
AND (ITEM_NAME ||ITEM_XL_NUM) LIKE #para(ITEM_NAMES, "like")
#end
#if(begin)
AND created BETWEEN to_date(#para(begin), 'yyyy-mm-dd hh24:mi:ss' )
AND to_date(#para(end), 'yyyy-mm-dd hh24:mi:ss' )
#end
order by CREATED desc
#end


###设备资产:统计
#sql("zc")
SELECT
    ( SELECT count( * ) FROM tlk_equipment ) AS ALLS,
    ( SELECT count( * ) FROM tlk_equipment WHERE item_sttxu = '封存' ) AS FC,
    ( SELECT count( * ) FROM tlk_equipment WHERE item_sttxu = '可用' ) AS KY,
    ( SELECT count( * ) FROM tlk_equipment WHERE item_toolstate = '2' ) AS SY
FROM
    tlk_equipment
WHERE ROWNUM = 1
#end
###设备资产:使用时长条形图
#sql("zc_time")
select *from(select ITEM_DEVID,ITEM_EQUNR,ITEM_EQKTX,round(NVL(SUM(to_number(to_date(to_char(ITEM_RETURNING_DATE, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss') - to_date(to_char(ITEM_BORROWING_DATE,'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss')) * 24 * 60),0)) AS item_vtime from tlk_tool_borrowing
GROUP BY ITEM_DEVID,ITEM_EQUNR,ITEM_EQKTX ORDER BY item_vtime DESC)
#end
###设备资产:使用频次条形图
#sql("zc_pc")
	 select *from(select ITEM_DEVID,ITEM_EQUNR,ITEM_EQKTX,count(*) as item_invalue from tlk_tool_borrowing group by ITEM_DEVID,ITEM_EQUNR,ITEM_EQKTX  ORDER BY item_invalue DESC)
#end

