IotInspectRouteMapper.xml 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="cn.iocoder.yudao.module.pms.dal.mysql.inspect.IotInspectRouteMapper">
  4. <!--
  5. 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  6. 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  7. 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  8. 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  9. -->
  10. <select id="getRoute"
  11. resultType="cn.iocoder.yudao.module.pms.dal.dataobject.inspect.IotInspectRouteDO">
  12. select * from (SELECT
  13. r.route_name,
  14. d.device_name,
  15. d.id as device_id,
  16. r.id,
  17. r.item_json,
  18. r.create_time,
  19. d.dept_id,d.device_code,
  20. d.brand_name
  21. FROM
  22. rq_iot_inspect_route r
  23. LEFT JOIN rq_iot_device d
  24. ON d.asset_class IN (
  25. SELECT id FROM rq_iot_product_classify
  26. WHERE id = r.device_classify OR parent_id = r.device_classify
  27. )
  28. LEFT JOIN rq_iot_product_classify p
  29. ON d.asset_class = p.id
  30. WHERE
  31. NOT EXISTS (
  32. SELECT 1 FROM rq_iot_inspect_route i
  33. WHERE i.device_id = d.id
  34. )
  35. AND d.id IS NOT NULL and r.deleted=0 and d.deleted=0 and p.deleted=0 and r.brand is null
  36. union all
  37. select route_name, device_name, device_id,id,item_json,create_time,dept_id,device_code,brand_name from rqiot.rq_iot_inspect_route
  38. where device_id is not null and deleted=0
  39. union all
  40. select li.route_name,de.device_name,de.id device_id, li.id, li.item_json, li.create_time, de.dept_id, de.device_code,li.brand_name from rq_iot_inspect_route li left join rq_iot_device de on li.brand=de.brand where li.brand is not null and li.deleted=0 and de.deleted=0
  41. )fin
  42. <where>
  43. <if test="reqVO.deviceName!=null and reqVO.deviceName!=''">
  44. and fin.device_name LIKE CONCAT('%',#{reqVO.deviceName},'%')
  45. </if>
  46. <if test="reqVO.deviceCode!=null and reqVO.deviceCode!=''">
  47. and fin.device_code LIKE CONCAT('%',#{reqVO.deviceCode},'%')
  48. </if>
  49. <if test="reqVO.routeName!=null and reqVO.routeName!=''">
  50. and fin.route_name LIKE CONCAT('%',#{reqVO.routeName},'%')
  51. </if>
  52. <if test="reqVO.brandName!=null and reqVO.brandName!=''">
  53. and fin.brand_name LIKE CONCAT('%',#{reqVO.brandName},'%')
  54. </if>
  55. <if test="reqVO.deptId!=null and reqVO.deptId!=''">
  56. and fin.dept_id LIKE CONCAT('%',#{reqVO.deptId},'%')
  57. </if>
  58. </where>
  59. </select>
  60. </mapper>