| | |
| | | package com.product.device.service; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import com.beust.jcommander.internal.Lists; |
| | | import com.product.core.config.CoreConst; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.core.transfer.Transactional; |
| | | import com.product.device.config.DeviceCode; |
| | | import com.product.device.config.DeviceConst; |
| | | import com.product.device.service.ide.IDeviceMainenanceService; |
| | | import com.product.device.service.idel.IDeviceMainenanceService; |
| | | import com.product.module.sys.entity.SystemUser; |
| | | import com.product.task.device.service.DeviceManagerTaskService; |
| | | |
| | | import com.product.util.BaseUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * 设备维修 |
| | | * @Author |
| | | * |
| | | * @Author |
| | | * @Date 2022/3/8 16:33 |
| | | * @Desc 功能相关 service |
| | | */ |
| | | @Service |
| | | public class DeviceMainenanceService extends AbstractBaseService implements IDeviceMainenanceService { |
| | | |
| | | @Autowired |
| | | public BaseDao baseDao; |
| | | @Autowired |
| | | DeviceManagerService deviceManagerService; |
| | | @Autowired |
| | | DeviceManagerTaskService deviceManagerTaskService; |
| | | @Autowired |
| | | public BaseDao baseDao; |
| | | @Autowired |
| | | DeviceManagerService deviceManagerService; |
| | | @Autowired |
| | | DeviceManagerTaskService deviceManagerTaskService; |
| | | |
| | | /** |
| | | * 获取设备信息 包括子设备 |
| | | * @param uuid |
| | | * @param device_sn |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public String saveDeviceFailure(FieldSetEntity fs) { |
| | | SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); |
| | | if(fs!=null) { |
| | | fs.setValue("org_level_uuid", currentUser.getOrg_level_uuid()); |
| | | } |
| | | fs.setTableName(DeviceConst.TABLE_PRODUCT_REPAIR_FAILURE); |
| | | boolean b=baseDao.saveFieldSetEntity(fs); |
| | | if(b) { |
| | | //修改设备的状态为停机维修 |
| | | deviceManagerService.deviceStatusChange(fs.getString("asset_code"), "2"); |
| | | /** |
| | | * 获取设备信息 包括子设备 |
| | | * |
| | | * @return |
| | | */ |
| | | @Transactional |
| | | public String saveDeviceFailure(FieldSetEntity fs) { |
| | | SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); |
| | | if (fs != null) { |
| | | fs.setValue("org_level_uuid", currentUser.getOrg_level_uuid()); |
| | | } |
| | | fs.setTableName(DeviceConst.TABLE_PRODUCT_REPAIR_FAILURE); |
| | | boolean b = baseDao.saveFieldSetEntity(fs); |
| | | if (b) { |
| | | //修改设备的状态为停机维修 |
| | | deviceManagerService.deviceStatusChange(fs.getString("asset_code"), "2"); |
| | | // //上报任务生成 |
| | | // deviceManagerTaskService.createTask(); |
| | | //设备运行记录 |
| | | deviceManagerService.appendDeivceManageLog(fs.getString("asset_code"),fs.getString("created_by"),"","设备故障上报","product_device_repair_failure_record",fs.getString("uuid")); |
| | | } |
| | | |
| | | return fs.getString(CoreConst.UUID); |
| | | } |
| | | /** |
| | | * 创建维修任务,第一次可能选中的是调度人,也可能是维修人员 |
| | | * @param fs |
| | | */ |
| | | public void createMaintainTask(FieldSetEntity fs) { |
| | | |
| | | deviceManagerTaskService.createTask(); |
| | | } |
| | | //设备运行记录 |
| | | deviceManagerService.appendDeivceManageLog(fs.getString("asset_code"), fs.getString("created_by"), "", "设备故障上报", "product_device_repair_failure_record", fs.getString("uuid")); |
| | | } |
| | | |
| | | return fs.getString(CoreConst.UUID); |
| | | } |
| | | |
| | | /** |
| | | * 创建维修任务,第一次可能选中的是调度人,也可能是维修人员 |
| | | * |
| | | * @param fs |
| | | */ |
| | | public void createMaintainTask(FieldSetEntity fs) { |
| | | |
| | | deviceManagerTaskService.createTask(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取本年已完成的保养记录 |
| | | */ |
| | | public DataTableEntity getMaintainByCurrentYear(FieldSetEntity fse) { |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("\nSELECT b.*,a.plan_maintenance_time,a.maintenance_user,a.maintenance_time,a.check_user,a.check_time FROM `product_device_maintenance_record` a "); |
| | | sql.append("\nINNER JOIN `product_device_info` b ON a. device_uuid=b.uuid "); |
| | | sql.append("\nwhere length(a.check_user)>0 "); |
| | | String elevatorVariety = fse.getString("elevator_variety"); |
| | | String maintenanceUnit = fse.getString("maintenance_unit"); |
| | | List<Object> params = StringUtils.isAnyEmpty(elevatorVariety, maintenanceUnit) ? new ArrayList<>() : null; |
| | | if (!StringUtils.isEmpty(elevatorVariety)) { |
| | | String[] split = elevatorVariety.split(","); |
| | | sql.append("\nAND ").append(BaseUtil.buildQuestionMarkFilter("b.elevator_variety", split.length, true)); |
| | | params.addAll(CollectionUtil.toList(split)); |
| | | } |
| | | if (!StringUtils.isEmpty(maintenanceUnit)) { |
| | | sql.append("\nAND b.maintenance_unit=? "); |
| | | params.add(elevatorVariety); |
| | | } |
| | | Integer cpage = fse.getInteger(DeviceConst.CPAGE); |
| | | Integer pageSize = fse.getInteger(DeviceConst.PAGESIZE); |
| | | //查询已复核过的记录 |
| | | sql.append(" order by a.maintenance_time desc "); |
| | | DataTableEntity result = baseDao.listTable(sql.toString(), params.toArray(), pageSize, cpage); |
| | | result.getMeta().addAliasTable("product_device_info", "b"); |
| | | result.getMeta().addAliasTable("product_device_maintenance_record", "a"); |
| | | baseDao.loadPromptData(result); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | public DataTableEntity getMaintainMonth(FieldSetEntity fse) { |
| | | Integer cpage = fse.getInteger(DeviceConst.CPAGE); |
| | | Integer pageSize = fse.getInteger(DeviceConst.PAGESIZE); |
| | | StringBuilder sql = new StringBuilder(); |
| | | sql.append("\nSELECT b.*,a.maintenance_user, a.plan_finish_time FROM `product_device_maintenance_plan_sub`a "); |
| | | sql.append("\nINNER JOIN `product_device_info`b ON a.device_uuid = b.uuid "); |
| | | //sql查询plan_finish_time时间是否属于当月 |
| | | sql.append("\nWHERE MONTH(a.plan_finish_time) = MONTH(NOW()) AND a.is_finish=1"); |
| | | String elevatorVariety = fse.getString("elevator_variety"); |
| | | String maintenanceUnit = fse.getString("maintenance_unit"); |
| | | List<Object> params = StringUtils.isAnyEmpty(elevatorVariety, maintenanceUnit) ? new ArrayList<>() : null; |
| | | if (!StringUtils.isEmpty(elevatorVariety)) { |
| | | String[] split = elevatorVariety.split(","); |
| | | sql.append("\nAND ").append(BaseUtil.buildQuestionMarkFilter("b.elevator_variety", split.length, true)); |
| | | params.addAll(CollectionUtil.toList(split)); |
| | | } |
| | | if (!StringUtils.isEmpty(maintenanceUnit)) { |
| | | sql.append("\nAND b.maintenance_unit=? "); |
| | | params.add(elevatorVariety); |
| | | } |
| | | DataTableEntity result = baseDao.listTable(sql.toString(), params.toArray(), pageSize, cpage); |
| | | result.getMeta().addAliasTable("product_device_info", "b"); |
| | | result.getMeta().addAliasTable("product_device_maintenance_plan_sub", "a"); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 维保记录复核 |
| | | */ |
| | | public boolean maintenanceReview(FieldSetEntity fse) { |
| | | String uuids = fse.getString("uuids"); |
| | | if (StringUtils.isBlank(uuids)) { |
| | | throw new BaseException(DeviceCode.SYSTEM_FORM_COUNT); |
| | | } |
| | | |
| | | String[] split = (SpringMVCContextHolder.getCurrentUserId() + "," + uuids).split(","); |
| | | return baseDao.executeUpdate("update `product_device_maintenance_record` set check_time=now(),check_user=? where is_finish=1 and " + BaseUtil.buildQuestionMarkFilter("uuid", split.length - 1, true), split); |
| | | } |
| | | |
| | | /** |
| | | * 维保单位年度维保统计 |
| | | * |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public DataTableEntity yearMaintenance(FieldSetEntity fse) { |
| | | // 电梯品种 |
| | | String elevatorVariety = null; |
| | | // 维保单位 |
| | | String maintenanceUnit = null; |
| | | if (fse != null) { |
| | | elevatorVariety = fse.getString("elevator_variety"); |
| | | maintenanceUnit = fse.getString("maintenance_unit"); |
| | | } |
| | | StringBuilder sql = new StringBuilder(128); |
| | | sql.append("\nSELECT u.`name`,count(r.uuid) record_count"); |
| | | sql.append("\nFROM product_device_maintenance_unit u"); |
| | | sql.append("\nLEFT JOIN product_device_info a on a.maintenance_unit=u.uuid"); |
| | | sql.append("\nLEFT JOIN product_device_maintenance_record r on r.device_uuid=a.uuid"); |
| | | StringBuilder filterSql = new StringBuilder(32); |
| | | List<String> param = Lists.newArrayList(); |
| | | if (!StringUtils.isEmpty(elevatorVariety)) { |
| | | String[] arr = elevatorVariety.split(","); |
| | | filterSql.append(BaseUtil.buildQuestionMarkFilter("elevator_variety", arr.length, true)); |
| | | param.addAll(Arrays.asList(arr)); |
| | | } |
| | | if (!StringUtils.isEmpty(maintenanceUnit)) { |
| | | if (filterSql.length() > 0) { |
| | | filterSql.append(" AND "); |
| | | } |
| | | String[] arr = maintenanceUnit.split(","); |
| | | filterSql.append(BaseUtil.buildQuestionMarkFilter("maintenance_unit", arr.length, true)); |
| | | param.addAll(Arrays.asList(arr)); |
| | | } |
| | | if (filterSql.length() > 0) { |
| | | sql.append("\nWHERE ").append(filterSql); |
| | | } |
| | | sql.append("\nGROUP BY u.uuid"); |
| | | return baseDao.listTable(sql.toString(), param.toArray()); |
| | | } |
| | | |
| | | /** |
| | | * 维保单位年度维保任务完成情况 |
| | | * |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public DataTableEntity yearMaintenanceFinish(FieldSetEntity fse) { |
| | | // 电梯品种 |
| | | String elevatorVariety = null; |
| | | // 维保单位 |
| | | String maintenanceUnit = null; |
| | | if (fse != null) { |
| | | elevatorVariety = fse.getString("elevator_variety"); |
| | | maintenanceUnit = fse.getString("maintenance_unit"); |
| | | } |
| | | StringBuilder sql = new StringBuilder(128); |
| | | sql.append("\nSELECT T.*,CASE WHEN record_count = 0 THEN 0 ELSE ROUND(finish_count / record_count, 4) END finish_rate"); |
| | | sql.append("\nFROM ("); |
| | | sql.append("\n SELECT u.name,a.device_number,a.device_unit,a.device_code,d.manufacture_company,count(r.uuid) record_count, count(r.is_finish) + 1 finish_count"); |
| | | sql.append("\n FROM product_device_maintenance_unit u"); |
| | | sql.append("\n JOIN product_device_info a on a.maintenance_unit=u.uuid"); |
| | | sql.append("\n JOIN product_device_archives d on a.archives_uuid=d.uuid"); |
| | | sql.append("\n JOIN product_device_maintenance_record r on r.device_uuid=a.uuid"); |
| | | StringBuilder filterSql = new StringBuilder(32); |
| | | List<String> param = Lists.newArrayList(); |
| | | if (!StringUtils.isEmpty(elevatorVariety)) { |
| | | String[] arr = elevatorVariety.split(","); |
| | | filterSql.append(BaseUtil.buildQuestionMarkFilter("elevator_variety", arr.length, true)); |
| | | param.addAll(Arrays.asList(arr)); |
| | | } |
| | | if (!StringUtils.isEmpty(maintenanceUnit)) { |
| | | if (filterSql.length() > 0) { |
| | | filterSql.append(" AND "); |
| | | } |
| | | String[] arr = maintenanceUnit.split(","); |
| | | filterSql.append(BaseUtil.buildQuestionMarkFilter("maintenance_unit", arr.length, true)); |
| | | param.addAll(Arrays.asList(arr)); |
| | | } |
| | | if (filterSql.length() > 0) { |
| | | sql.append("\n WHERE ").append(filterSql); |
| | | } |
| | | sql.append("\n GROUP BY 1,2,3,4,5"); |
| | | sql.append("\n) T"); |
| | | return baseDao.listTable(sql.toString(), param.toArray()); |
| | | } |
| | | |
| | | /** |
| | | * 设备的保养配置 |
| | | * |
| | | * @param asset_code 设备编号 |
| | | * @param manceType 保养类型 |
| | | * @return |
| | | */ |
| | | public FieldSetEntity findDeviceMaintenanceSetting(String uuid, String manceType) { |
| | | |
| | | FieldSetEntity device = deviceManagerService.findDevice(uuid); |
| | | |
| | | FieldSetEntity record = new FieldSetEntity("product_device_maintenance_record"); |
| | | record.setValue("device_uuid", device.getString("device_name")); |
| | | record.setValue("device_number", device.getString("device_number")); |
| | | record.setValue("device_uuid_save_value", device.getString("uuid")); |
| | | String sql = "select c.item_uuid,c.content ,c.criterion from product_device_maintenance_setting a left join product_device_maintenance_item_config b on\r\n" |
| | | + "a.maintenance_item=b.uuid join \r\n" |
| | | + "product_device_maintenance_item_detail c on b.uuid= c.item_uuid\r\n" |
| | | + "where device_uuid=? and maintenance_type=? and c.is_used=1 \r\n" |
| | | + "order by item_uuid"; |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sql, new String[]{uuid, manceType}); |
| | | record.addSubDataTable(dataTableEntity); |
| | | |
| | | return record; |
| | | } |
| | | } |