Java开发笔记2(统计)
1.Controller:
/**
* 巡检统计查询设备分类名称
*
* @return 2021.9.13
*/
@GetMapping("/deviceTypeName")
public Result findDeviceTypeName() {
List<InspectionOrderDetail> typeName = inspectionWorkOrderService.findDeviceTypeName();
List<Map<String, Object>> list = new ArrayList<>();
for (InspectionOrderDetail inspectionOrderDetail : typeName){
Map<String, Object> map = new HashMap<>();
map.put("deviceCategoryid", inspectionOrderDetail.getDeviceCategoryId());
map.put("deviceCategoryName", inspectionOrderDetail.getDeviceCategoryName());
list.add(map);
}
return Result.ok(list);
}
/**
* 巡检统计查询设备名称
*
* @return 2021.9.13
*/
@GetMapping("/deviceName")
public Result findDeviceName(String deviceCategoryId) {
List<InspectionOrderDetail> deviceName = inspectionWorkOrderService.findDeviceName(getStationIds(),deviceCategoryId);
List<Map<String,Object>> list = new ArrayList<>();
for (InspectionOrderDetail inspectionOrderDetail : deviceName){
Map<String, Object> map = new HashMap<>();
map.put("deviceId",inspectionOrderDetail.getDeviceId());
map.put("deviceName",inspectionOrderDetail.getDeviceName());
list.add(map);
}
return Result.ok(list);
}
================================================================
2.Service:
/**
* 巡检统计查询设备分类名称
*
* @return
*/
List<InspectionOrderDetail> findDeviceTypeName();
/**
* 巡检统计查询设备
*
* @return
*/
List<InspectionOrderDetail> findDeviceName(Set<String> stationIds,String deviceCategoryId);
==========================================================
3.ServiceImpl:
/**
* 巡检统计查询设备分类名称
* @return
*/
@Override
public List<InspectionOrderDetail> findDeviceTypeName() {
return inspectionOrderDetailDao.findDeviceTypeName();
}
/**
* 巡检统计查询设备名称
* @return
*/
@Override
public List<InspectionOrderDetail> findDeviceName(Set<String> stationIds, String deviceCategoryId) {
StringBuffer jql = new StringBuffer();
jql.append("select d from InspectionOrderDetail d left join InspectionWorkOrder w on d.workOrderId = w.id where 1 = 1 ");
Map<String, Object> params = new HashMap<>();
//判断是否传递设备分类信息,如果没有则查当前站下对应类型的所有设备,如果有那么再加上一个设备分类过滤条件。
if (!StringUtils.isEmpty(deviceCategoryId)) {
jql.append(" and d.deviceCategoryId = :deviceCategoryId ");
params.put("deviceCategoryId",deviceCategoryId);
}
if (stationIds != null && stationIds.size() != 0){
jql.append(" and w.stationId in (:stationIds) ");
params.put("stationIds", stationIds);
}
jql.append(" group by d.deviceName ");
List<InspectionOrderDetail> listByJQL = inspectionOrderDetailDao.findListByJQL(jql.toString(), params);
return listByJQL;
}
============================================================
4.dao:
/**
* 查询设备分类id及名称
* @return
*/
@Query("select new InspectionOrderDetail(d.deviceCategoryId, d.deviceCategoryName) from InspectionOrderDetail d group by d.deviceCategoryId")
List<InspectionOrderDetail> findDeviceTypeName();
===============================================================
5.entity:
package com.cars.ict.rbpsems.entity.operation.inspect;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.Date;
/**
* 巡养工单明细
* @author zhangqiang
* @date 2019年02月26日09:26:36
*/
@Entity
@Table(name = "ope_inspect_order_detail")
public class InspectionOrderDetail {
@Id
@GenericGenerator(name = "uuid", strategy = "uuid")
@GeneratedValue(generator = "uuid")
@Column(name = "s_id")
private String id;
/**
* 工单ID
*/
@Column(name = "s_work_order_id", length = 50)
private String workOrderId;
/**
* 设备类型id
*/
@Column(name = "s_device_category_id", length = 32)
private String deviceCategoryId;
/**
* 设备类型名称
*/
@Column(name = "s_device_category_name", length = 100)
private String deviceCategoryName;
/**
* 设备id
*/
@Column(name = "s_device_id", length = 32)
private String deviceId;
/**
* 设备名称
*/
@Column(name = "s_device_name", length = 100)
private String deviceName;
/**
* 设备编码
*/
@Column(name = "s_device_code", length = 100)
private String deviceCode;
/**
* 设备位置
*/
@Column(name = "s_device_address")
private String address;
/**
* 巡养项目
*/
@Column(name = "s_inspect_project")
private String inspectionProject;
/**
* 巡养内容
*/
@Column(name = "s_inspect_content", length = 500)
private String inspectionContent;
/**
* 巡检结果 1:正常 0:异常
* 保养进度 0:已完成,1:进行中
*/
@Column(name = "i_inspect_result")
private Integer inspectionResult;
/**
* 巡养时间
*/
@Temporal(TemporalType.TIMESTAMP)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
@Column(name = "d_inspection_time")