设备故障分析

This commit is contained in:
2022-06-29 15:29:28 +08:00
parent d5a8942adf
commit f2c8ca9502
8 changed files with 949 additions and 1 deletions

View File

@@ -30,7 +30,8 @@ public enum MaterOptTypeEnum {
CXJ(19, "20", "成型剂", "('1518780034469466112')", ""),
RD_AND_PG(20, "21", "pg粉和软废", "('1503644362108702720','1503644362150645760')", ""),
YL_AND_BCP(21, "22", "原料和半成品", "('1503644353019645952','1503644359155912704')", ""),
SPARE(22, "23", "备品备件", "('1503644361789935616')", "");
SPARE(22, "23", "备品备件", "('1503644361789935616')", ""),
SBGZ(23, "24", "设备故障", "('1541964046385942528')", "");
//顺序号

View File

@@ -0,0 +1,84 @@
package org.nl.wms.sb.stat.rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.annotation.Log;
import org.nl.wms.sb.stat.service.DevicefaultcaeService;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
* @author Liuxy
* @date 2022-06-28
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "设备故障分析")
@RequestMapping("/api/devicefaultcae")
@Slf4j
public class DevicefaultcaeController {
private final DevicefaultcaeService devicefaultcaeService;
@GetMapping
@Log("设备故障分析查询")
@ApiOperation("设备故障分析查询")
//@PreAuthorize("@el.check('devicesparepartivt:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(devicefaultcaeService.queryAll(whereJson, page), HttpStatus.OK);
}
@GetMapping("/dtlQuery")
@Log("明细查询")
@ApiOperation("明细查询")
//@PreAuthorize("@el.check('devicesparepartivt:list')")
public ResponseEntity<Object> dtlQuery(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(devicefaultcaeService.dtlQuery(whereJson, page), HttpStatus.OK);
}
@PostMapping
@Log("新增设备故障分析")
@ApiOperation("新增设备故障分析")
//@PreAuthorize("@el.check('devicesparepartivt:add')")
public ResponseEntity<Object> create(@Validated @RequestBody DevicesparepartivtDto dto) {
devicefaultcaeService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改设备故障分析")
@ApiOperation("修改设备故障分析")
//@PreAuthorize("@el.check('devicesparepartivt:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody DevicesparepartivtDto dto) {
devicefaultcaeService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除设备故障分析")
@ApiOperation("删除设备故障分析")
//@PreAuthorize("@el.check('devicesparepartivt:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
devicefaultcaeService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@ApiOperation("导出数据")
@GetMapping(value = "/download")
public void download(HttpServletResponse response, @RequestParam Map whereJson) throws IOException {
devicefaultcaeService.download(whereJson, response);
}
}

View File

@@ -0,0 +1,85 @@
package org.nl.wms.sb.stat.service;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @author Liuxy
* @description 服务接口
* @date 2022-06-28
**/
public interface DevicefaultcaeService {
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
*
* @param whereJson 条件参数
* @return List<DevicesparepartivtDto>
*/
List<DevicesparepartivtDto> queryAll(Map whereJson);
/**
* 根据ID查询
*
* @param stockrecord_id ID
* @return Devicesparepartivt
*/
DevicesparepartivtDto findById(Long stockrecord_id);
/**
* 根据编码查询
*
* @param code code
* @return Devicesparepartivt
*/
DevicesparepartivtDto findByCode(String code);
/**
* 创建
*
* @param dto /
*/
void create(DevicesparepartivtDto dto);
/**
* 编辑
*
* @param dto /
*/
void update(DevicesparepartivtDto dto);
/**
* 多选删除
*
* @param ids /
*/
void deleteAll(Long[] ids);
void download(Map whereJson, HttpServletResponse response) throws IOException;
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> dtlQuery(Map whereJson, Pageable page);
}

View File

@@ -0,0 +1,246 @@
package org.nl.wms.sb.stat.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.exception.BadRequestException;
import org.nl.utils.FileUtil;
import org.nl.utils.SecurityUtils;
import org.nl.wms.basedata.master.service.ClassstandardService;
import org.nl.wms.sb.stat.service.DevicefaultcaeService;
import org.nl.wms.sb.stat.service.dto.DevicesparepartivtDto;
import org.nl.wql.WQL;
import org.nl.wql.core.bean.WQLObject;
import org.nl.wql.util.WqlUtil;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
/**
* @author Liuxy
* @description 服务实现
* @date 2022-06-28
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class DevicefaultcaeServiceImpl implements DevicefaultcaeService {
private final ClassstandardService classstandardService;
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String material_type_id = MapUtil.getStr(whereJson, "material_type_id");
String class_idStr = (String) whereJson.get("class_idStr");
String device_gz = MapUtil.getStr(whereJson, "device_gz");
String class_idStr2 = (String) whereJson.get("class_idStr2");
String device_code = MapUtil.getStr(whereJson, "device_code");
String dept_id = MapUtil.getStr(whereJson, "dept_id");
String begin_time = MapUtil.getStr(whereJson, "begin_time");
String end_time = MapUtil.getStr(whereJson, "end_time");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("begin_time", begin_time);
map.put("end_time", end_time);
if (ObjectUtil.isNotEmpty(device_code)) map.put("device_code", "%"+device_code+"%");
if (ObjectUtil.isNotEmpty(dept_id)) map.put("dept_id", "%"+dept_id+"%");
//处理设备当前节点的所有子节点
if (!StrUtil.isEmpty(material_type_id)) {
map.put("material_type_id", material_type_id);
String classIds = classstandardService.getChildIdStr(material_type_id);
map.put("classIds", classIds);
} else if (ObjectUtil.isNotEmpty(class_idStr)) {
String classIds = classstandardService.getAllChildIdStr(class_idStr);
map.put("classIds", classIds);
}
//处理故障当前节点的所有子节点
if (!StrUtil.isEmpty(device_gz)) {
map.put("device_gz", device_gz);
String classIds2 = classstandardService.getChildIdStr(device_gz);
map.put("classIds2", classIds2);
} else if (ObjectUtil.isNotEmpty(class_idStr2)) {
String classIds2 = classstandardService.getAllChildIdStr(class_idStr2);
map.put("classIds2", classIds2);
}
JSONObject json = WQL.getWO("EM_DEVICEFAULTCAE01").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "re.devicerecord_id DESC");
// 处理平均故障间隔时间 && 平均故障修复时间
/* WQLObject tab = WQLObject.getWQLObject("EM_BI_DeviceRepairRequest");
JSONArray content = json.getJSONArray("content");
for (int i = 0; i < content.size(); i++) {
JSONObject jsonObject = content.getJSONObject(i);
String devicerecord_id = jsonObject.getString("devicerecord_id");
JSONArray arr = tab.query("devicerecord_id = '" + devicerecord_id + "' and is_delete = '0'").getResultJSONArray(0);
String nunm = jsonObject.getString("nunm");
String create_time_all = "0";
String finish_time_all = "0";
for (int j = 0; j < arr.size(); j++) {
JSONObject jsonObject1 = arr.getJSONObject(j);
// 去掉时间中的特殊字符
String create_time = jsonObject1.getString("create_time").replaceAll("[[\\s-:punct:]]","");
String finish_time = "0";
if (ObjectUtil.isNotEmpty(jsonObject1.getString("finish_time"))) {
finish_time = jsonObject1.getString("finish_time").replaceAll("[[\\s-:punct:]]","");
}
// 相加
create_time_all = String.valueOf(NumberUtil.add(create_time_all,create_time));
finish_time_all = String.valueOf(NumberUtil.add(finish_time_all,finish_time));
}
BigDecimal avgRep_time = NumberUtil.div(String.valueOf(NumberUtil.sub(finish_time_all, create_time_all)), nunm);
jsonObject.put("avgRep_time",String.valueOf(avgRep_time));
}
json.put("content",content);*/
return json;
}
@Override
public List<DevicesparepartivtDto> queryAll(Map whereJson) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(DevicesparepartivtDto.class);
return null;
}
@Override
public DevicesparepartivtDto findById(Long stockrecord_id) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = wo.query("stockrecord_id = '" + stockrecord_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DevicesparepartivtDto.class);
}
return null;
}
@Override
public DevicesparepartivtDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DevicesparepartivtDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DevicesparepartivtDto dto) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
dto.setStockrecord_id(IdUtil.getSnowflake(1, 1).nextId());
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DevicesparepartivtDto dto) {
DevicesparepartivtDto entity = this.findById(dto.getStockrecord_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("em_bi_devicesparepartivt");
for (Long stockrecord_id : ids) {
JSONObject param = new JSONObject();
param.put("stockrecord_id", String.valueOf(stockrecord_id));
param.put("is_delete", "1");
param.put("update_optid", currentUserId);
param.put("update_optname", nickName);
param.put("update_time", now);
wo.update(param);
}
}
@Override
public void download(Map whereJson, HttpServletResponse response) throws IOException {
String begin_time = MapUtil.getStr(whereJson, "begin_time");
String end_time = MapUtil.getStr(whereJson, "end_time");
String devicerecord_id = MapUtil.getStr(whereJson, "devicerecord_id");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "2");
map.put("begin_time",begin_time);
map.put("end_time",end_time);
map.put("devicerecord_id",devicerecord_id);
JSONArray rows = WQL.getWO("EM_DEVICEFAULTCAE01").addParamMap(map).process().getResultJSONArray(0);
for (int j = 0; j < rows.size(); j++) {
JSONObject jsonObject = rows.getJSONObject(j);
if (ObjectUtil.isEmpty("outsourceaskfor_optid")) {
jsonObject.put("outsourceaskfor_optid","");
} else {
jsonObject.put("outsourceaskfor_optid","");
}
}
List<Map<String, Object>> list = new ArrayList<>();
for (int i = 0; i < rows.size(); i++) {
JSONObject jo = rows.getJSONObject(i);
Map<String, Object> dtl_map = new LinkedHashMap<>();
dtl_map.put("报修时间", jo.getString("create_time"));
dtl_map.put("使用部门", jo.getString("name"));
dtl_map.put("故障类型", jo.getString("class_name"));
dtl_map.put("受理时间", jo.getString("process_time"));
dtl_map.put("开始维修", jo.getString("real_start_date"));
dtl_map.put("结束维修", jo.getString("real_end_date"));
dtl_map.put("是否委外", jo.getString("outsourceaskfor_optid"));
dtl_map.put("生产验收", jo.getString("confirm_time"));
dtl_map.put("维修确认", jo.getString("audit_time"));
dtl_map.put("生产配合人", jo.getString("product_person_name"));
dtl_map.put("维修人", jo.getString("update_optname"));
list.add(dtl_map);
}
FileUtil.downloadExcel(list, response);
}
@Override
public Map<String, Object> dtlQuery(Map whereJson, Pageable page) {
String begin_time = MapUtil.getStr(whereJson, "begin_time");
String end_time = MapUtil.getStr(whereJson, "end_time");
String devicerecord_id = MapUtil.getStr(whereJson, "devicerecord_id");
HashMap<String, String> map = new HashMap<>();
map.put("flag", "2");
map.put("begin_time",begin_time);
map.put("end_time",end_time);
map.put("devicerecord_id",devicerecord_id);
JSONObject json = WQL.getWO("EM_DEVICEFAULTCAE01").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "re.fault_time DESC");
return json;
}
}

View File

@@ -0,0 +1,134 @@
[交易说明]
交易名: 设备故障分析分页查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.classIds TYPEAS f_string
输入.classIds2 TYPEAS f_string
输入.device_code TYPEAS s_string
输入.dept_id TYPEAS s_string
输入.begin_time TYPEAS s_string
输入.end_time TYPEAS s_string
输入.devicerecord_id TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT
count(re.devicerecord_id) AS nunm,
MAX(dept.name) AS dept_name,
MAX(class.class_name) AS class_name,
MAX(file.device_code) AS device_code,
MAX(file.device_model) AS device_model,
re.devicerecord_id
FROM
EM_BI_DeviceRepairRequest re
LEFT JOIN EM_BI_EquipmentFile file ON file.devicerecord_id = re.devicerecord_id
LEFT JOIN md_pb_classstandard class ON file.material_type_id = class.class_id
LEFT JOIN md_pb_classstandard class2 ON re.device_faultclass_id = class2.class_id
LEFT JOIN sys_dept dept ON file.use_deptid = dept.dept_id
WHERE
re.is_delete = '0'
OPTION 输入.classIds <> ""
class.class_id in 输入.classIds
ENDOPTION
OPTION 输入.classIds2 <> ""
class2.class_id in 输入.classIds2
ENDOPTION
OPTION 输入.device_code <> ""
(file.device_code like 输入.device_code or
file.device_name like 输入.device_code)
ENDOPTION
OPTION 输入.dept_id <> ""
(dept.code like 输入.dept_id or
dept.name like 输入.dept_id)
ENDOPTION
OPTION 输入.begin_time <> ""
re.fault_time >= 输入.begin_time
ENDOPTION
OPTION 输入.end_time <> ""
re.fault_time <= 输入.end_time
ENDOPTION
group by re.devicerecord_id
ENDSELECT
ENDPAGEQUERY
ENDIF
IF 输入.flag = "2"
PAGEQUERY
SELECT
re.*,
dept.name,
class.class_name,
pari.real_start_date,
pari.real_end_date,
pari.outsourceaskfor_optid,
pari.confirm_time,
pari.audit_time,
pari.product_person_name,
pari.update_optname
FROM
EM_BI_DeviceRepairRequest re
LEFT JOIN EM_BI_EquipmentFile file ON file.devicerecord_id = re.devicerecord_id
LEFT JOIN md_pb_classstandard class ON re.device_faultclass_id = class.class_id
LEFT JOIN sys_dept dept ON file.use_deptid = dept.dept_id
LEFT JOIN EM_BI_DeviceRepairMst pari ON pari.source_bill_id = re.request_id
WHERE
re.is_delete = '0'
OPTION 输入.devicerecord_id <> ""
re.devicerecord_id = 输入.devicerecord_id
ENDOPTION
OPTION 输入.begin_time <> ""
re.fault_time >= 输入.begin_time
ENDOPTION
OPTION 输入.end_time <> ""
re.fault_time <= 输入.end_time
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF