From 2fef20fe45a1fc901b51243bcc60682524447990 Mon Sep 17 00:00:00 2001
From: shicf <shi_chongfu@163.com>
Date: 星期五, 23 八月 2024 18:55:41 +0800
Subject: [PATCH] Merge branch '2.0.0-release' of http://nonxin.cn:8090/r/product/product-server/V2.0.0

---
 product-server-device/src/main/java/com/product/device/service/CommonInspectionService.java |  284 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 267 insertions(+), 17 deletions(-)

diff --git a/product-server-device/src/main/java/com/product/device/service/CommonInspectionService.java b/product-server-device/src/main/java/com/product/device/service/CommonInspectionService.java
index a892840..135dd44 100644
--- a/product-server-device/src/main/java/com/product/device/service/CommonInspectionService.java
+++ b/product-server-device/src/main/java/com/product/device/service/CommonInspectionService.java
@@ -1,54 +1,304 @@
 package com.product.device.service;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
+import com.product.admin.service.PublicService;
 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.idel.IDeviceInspectionService;
+import com.product.module.sys.entity.SystemUser;
+import com.product.util.BaseUtil;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.thymeleaf.util.StringUtils;
 
 
 /**
  * 璁惧鐐规
- * @Author 
+ *
+ * @Author
  * @Date 2022/3/8 16:33
  * @Desc 鍔熻兘鐩稿叧 service
  */
 @Service
-public class CommonInspectionService extends AbstractBaseService {
+public class CommonInspectionService extends AbstractBaseService implements IDeviceInspectionService {
 
     @Autowired
     public BaseDao baseDao;
     @Autowired
     DeviceManagerService deviceManagerService;
+    @Autowired
+    PublicService publicService;
+    @Autowired
+    DeviceTaskService deviceTaskService;
     /**
      * 鑾峰彇璁惧淇℃伅 鍖呮嫭瀛愯澶�
-     * @param uuid
+     *
      * @param device_sn
      * @return
      */
     public FieldSetEntity createInspection(String device_sn) {
-    	FieldSetEntity dev=deviceManagerService.findDevice(null,device_sn);
-    	baseDao.loadPromptData(dev);
-    	if(dev !=null) {
-    		DataTableEntity dt=baseDao.listTable(DeviceConst.TABLE_PRODUCT_INSPECT_CONFIG," uuid in( select config_uuid from"+DeviceConst.TABLE_PRODUCT_INSPECT_SETTING_SUB+" where  main_uuid=(select uuid from "+DeviceConst.TABLE_PRODUCT_INSPECT_SETTING+" where device_type=? )", new String[] {dev.getString("device_type")});
-    		if(!DataTableEntity.isEmpty(dt)) {
-    			Map <String,DataTableEntity> sub=new HashMap<>();
-    			sub.put("sub", dt);
-    			dev.setSubData(sub);
-    			dev.addSubDataTable(dt);
-    		}
+        FieldSetEntity dev = deviceManagerService.findDevice( device_sn);
+        baseDao.loadPromptData(dev);
+        if (dev != null) {
+            DataTableEntity dt = baseDao.listTable(DeviceConst.TABLE_PRODUCT_DEVICE_INSPECT_ITEM_CONFIG, " uuid in( select config_uuid from" + DeviceConst.TABLE_PRODUCT_INSPECT_SETTING_SUB + " where  main_uuid=(select uuid from " + DeviceConst.TABLE_PRODUCT_INSPECT_SETTING + " where device_type=? )", new String[]{dev.getString("device_type")});
+            if (!DataTableEntity.isEmpty(dt)) {
+                Map<String, DataTableEntity> sub = new HashMap<>();
+                sub.put("sub", dt);
+                dev.setSubData(sub);
+                dev.addSubDataTable(dt);
+            }
+        }
+        return dev;
+    }
+
+    public DataTableEntity getPatrolMonthlView(FieldSetEntity fliter)  throws BaseException{
+        StringBuffer sb = new StringBuffer();
+        ArrayList<String> parme = new ArrayList<>();
+        sb.append(" SELECT a.name obName,GROUP_CONCAT( CONCAT(check_time,'&',result) ) check_time FROM(");
+        sb.append(" SELECT c.name,b.result,DATE_FORMAT( a.check_time, '%d' ) check_time FROM ");
+
+        sb.append(" "+fliter.getTableName()+" a LEFT JOIN "+fliter.getTableName()+"_sub b on a.uuid =b.record_uuid ");
+
+        sb.append(" LEFT JOIN product_device_patrol_config c on b.patrol_uuid=c.uuid where 1=1");
+
+
+        if (!StringUtils.isEmpty(fliter.getString("device_number"))) {
+            sb.append(" and a.device_number=?");
+            parme.add(fliter.getString("device_number"));
+        }
+        if (!StringUtils.isEmpty(fliter.getString("patrol_user"))) {
+            sb.append(" and a.patrol_user=?");
+            parme.add(fliter.getString("patrol_user"));
+        }
+        if (!StringUtils.isEmpty(fliter.getString("check_time"))) {
+            sb.append(" and DATE_FORMAT( a.check_time, '%Y-%m' )=?");
+            parme.add(fliter.getString("check_time").substring(0, 7));
+        } else {
+            throw new BaseException("0","骞存湀涓嶈兘涓虹┖");
+        }
+        sb.append(" GROUP BY c.name,b.result,DATE_FORMAT( a.check_time, '%d' )  ");
+        sb.append(") a GROUP BY a.name ");
+        String[] pArr = parme.toArray(new String[parme.size()]);
+        DataTableEntity dt = baseDao.listTable(sb.toString(), pArr);
+        for (int i = 0; i <dt.getRows() ; i++) {
+            FieldSetEntity fs = dt.getFieldSetEntity(i);
+            String check_time = fs.getString("check_time");
+            if (!StringUtils.isEmpty(check_time)){
+                String[] check_time_arr = check_time.split(",");
+                for (int j = 0; j <check_time_arr.length ; j++) {
+                    String[] v = check_time_arr[j].split("&");
+                    fs.setValue("m"+v[0],v[1]);
+                }
+
+            }
+        }
+        return dt;
+    }
+
+    public FieldSetEntity getInspectionSetting(String device_type) {
+        FieldSetEntity fs = baseDao.getFieldSetByFilter(DeviceConst.TABLE_PRODUCT_INSPECTION_SETTING, " device_type=? ", new String[]{device_type}, false);
+        return fs;
+    }
+
+    public DataTableEntity getTreeArchives() {
+        DataTableEntity dt = baseDao.listTable(DeviceConst.TABLE_PRODUCT_DEVICE_ARCHIVE, new String[]{});
+        return dt;
+    }
+
+    /**
+     * 淇濇寔璁惧閰嶇疆锛堢偣妫�銆佸贰妫�銆佷繚鍏伙級
+     * @param fs
+     * @return
+     */
+    @Transactional
+    public boolean saveSetting(FieldSetEntity fs) {
+        DataTableEntity subTable = fs.getSubDataTable("subTable");
+        boolean re = true;
+        for (int i = 0; i < subTable.getRows(); i++) {
+            FieldSetEntity sub = subTable.getFieldSetEntity(i);
+            sub.setTableName(fs.getTableName());
+            if (!StringUtils.isEmpty(sub.getString("~type~"))) {
+                publicService.delete(sub);
+                continue;
+            }
+            sub.setValue("device_number", fs.getString("device_number"));
+            sub.setValue("cycle", fs.getString("cycle"));
+            baseDao.executeUpdate("update product_device_maintenance_setting set device_number=? ",new String[] {fs.getString("device_number")});
+
+            if ("product_device_maintenance_setting".equals(fs.getTableName())){
+                sub.setValue("type", fs.getString("type"));
+                sub.setValue("ahead_notice_day", fs.getString("ahead_notice_day"));
+            }
+            if ("product_device_inspection_setting".equals(fs.getTableName())){
+                sub.setValue("start_time", fs.getDate("start_time"));
+                sub.setValue("warn_time", fs.getDate("warn_time"));
+            }
+            String uuid = publicService.saveFieldSetEntity(sub);
+            if (StringUtils.isEmpty(uuid)) {
+                re = false;
+            }
+        }
+        return re;
+    }
+
+    @Transactional
+    public boolean batchReview(FieldSetEntity fs) {
+        String uuid = fs.getString("uuid");
+        if (StringUtils.isEmpty(uuid)) {
+            return false;
+        }
+        String[] split = uuid.split(",");
+        boolean re = true;
+        for (int i = 0; i < split.length; i++) {
+            FieldSetEntity recordFs = new FieldSetEntity();
+            recordFs.setTableName(fs.getTableName());
+            recordFs.setValue("uuid", split[i]);
+            recordFs.setValue("check_user", SpringMVCContextHolder.getCurrentUser().getUser_id());
+            recordFs.setValue("check_time", new Date());
+            String uuids = publicService.saveFieldSetEntity(recordFs);
+            if (StringUtils.isEmpty(uuids)) {
+                re = false;
+            }
+
+        }
+        return re;
+    }
+
+    public FieldSetEntity findPatrolSetting() {
+        DataTableEntity dataTableEntity = baseDao.listTable(DeviceConst.TABLE_PRODUCT_PATROL_SETTING, "");
+        FieldSetEntity fs = new FieldSetEntity();
+        fs.setTableName(DeviceConst.TABLE_PRODUCT_PATROL_SETTING);
+
+        DataTableEntity dt = new DataTableEntity();
+
+        for (int i = 0; i < dataTableEntity.getRows(); i++) {
+            FieldSetEntity sub = dataTableEntity.getFieldSetEntity(i);
+            FieldSetEntity fsSub = new FieldSetEntity();
+            fsSub.setTableName(DeviceConst.TABLE_PRODUCT_PATROL_SETTING);
+            fsSub.setValue("patrol_config_uuid", sub.getString("patrol_config_uuid"));
+            fsSub.setValue("remark", sub.getString("remark"));
+            fsSub.setValue("uuid", sub.getString("uuid"));
+            dt.addFieldSetEntity(fsSub);
+            fs.setValue("device_number", sub.getString("device_number"));
+            fs.setValue("cycle", sub.getString("cycle"));
+
+        }
+        Map<String, DataTableEntity> sub = new HashMap<>();
+        sub.put("subTable", dt);
+        fs.setSubData(sub);
+        return fs;
+    }
+    public FieldSetEntity findInspectionSetting() {
+        DataTableEntity dataTableEntity = baseDao.listTable(DeviceConst.TABLE_PRODUCT_INSPECTION_SETTING, "");
+        FieldSetEntity fs = new FieldSetEntity();
+        fs.setTableName(DeviceConst.TABLE_PRODUCT_INSPECTION_SETTING);
+
+        DataTableEntity dt = new DataTableEntity();
+
+        for (int i = 0; i < dataTableEntity.getRows(); i++) {
+            FieldSetEntity sub = dataTableEntity.getFieldSetEntity(i);
+            FieldSetEntity fsSub = new FieldSetEntity();
+            fsSub.setTableName(DeviceConst.TABLE_PRODUCT_INSPECTION_SETTING);
+            fsSub.setValue("inspection_uuid", sub.getString("inspection_uuid"));
+            fsSub.setValue("remark", sub.getString("remark"));
+            fsSub.setValue("uuid", sub.getString("uuid"));
+            fsSub.setValue("back_type", sub.getString("back_type"));
+
+            dt.addFieldSetEntity(fsSub);
+            fs.setValue("device_number", sub.getString("device_number"));
+            fs.setValue("cycle", sub.getString("cycle"));
+            fs.setValue("start_time", sub.getString("start_time"));
+            fs.setValue("warn_time", sub.getString("warn_time"));
+
+        }
+        Map<String, DataTableEntity> sub = new HashMap<>();
+        sub.put("subTable", dt);
+        fs.setSubData(sub);
+        return fs;
+    }
+	/**
+     * 璁惧鐨勭偣妫�閰嶇疆
+     * @param asset_code
+     * @return
+     */
+    public FieldSetEntity findDeviceSetting(String device_uuid) {
+    	FieldSetEntity device=deviceManagerService.findDevice(device_uuid);
+    	String sql="select c.* from product_device_inspection_setting a join product_device_inspection_setting_sub b on a.uuid=b.main_uuid left join product_device_inspection_item_config c on b.config_uuid=c.uuid and c.is_used=1 where status=1 and a.device_uuid=? ";
+        DataTableEntity dataTableEntity = baseDao.listTable(sql,new String[] {device_uuid});
+        device.addSubDataTable(dataTableEntity);
+        return device;
+    }
+    /**
+     * 璁惧鐨勭偣妫�璁板綍
+     * @param asset_code
+     * @return
+     */
+    public FieldSetEntity findInspectionRecord(String uuid) {
+    	FieldSetEntity record=baseDao.getFieldSetEntity("product_device_inspection_record", 
+    			new String[]{"device_uuid","inspect_user","inspect_final_time","check_user","check_time","is_finish"},uuid, false);
+    	
+    	if(!FieldSetEntity.isEmpty(record)) {
+    		
+	    	FieldSetEntity device=deviceManagerService.findDevice(record.getString("device_uuid"));
+	    	record.setValue("device_uuid", device.getString("device_name"));
+	    	record.setValue("device_uuid_save_value", device.getString("uuid"));
+	    	
+	    	String sql="select s.*,c.* from product_device_inspection_setting a left join product_device_inspection_item_config c on a.inspection_item=c.uuid and c.is_used=1 left join product_device_inspection_record_sub s on s.inspect_item=c.uuid and record_uuid=?  where a.device_uuid=? ";
+	        DataTableEntity dt = baseDao.listTable(sql,new String[] {uuid,record.getString("device_uuid_save_value")});
+	        record.addSubDataTable(dt);  //鐐规椤�
+//	        record.removeSubData("product_device_inspection_record_sub");
     	}
-    	return dev;
+        return record;
+    }
+    /**
+     * 淇濆瓨鐐规淇℃伅
+     * @param fs
+     * @return
+     */
+    @Transactional
+    public String saveInspection(FieldSetEntity fs) throws BaseException{
+    	if(!FieldSetEntity.isEmpty(fs) ) {
+    		FieldSetEntity rfs=new FieldSetEntity(DeviceConst.PRODUCT_DEVICE_INSPECTION_RECORD);
+    		SystemUser user = SpringMVCContextHolder.getCurrentUser();
+    		rfs.setValue("org_level_uuid", user.getOrg_level_uuid());
+//    		rfs.setValue("device_uuid", fs.getValue("device_number"));
+    		rfs.setValue("device_uuid", fs.getValue("uuid"));
+    		rfs.setValue("is_finish", 0);
+    		rfs.setValue("use_dept", user.getOrg_level_uuid());
+    		rfs.setValue("inspect_user", user.getUser_id());
+    		rfs.setValue("inspect_final_time",new Date());
+//    		rfs.setValue("task_uuid", fieldValue);
+    		DataTableEntity dt=fs.getSubDataTable(DeviceConst.PRODUCT_DEVICE_INSPECTION_RECORD_SUB);
+    		if(!DataTableEntity.isEmpty(dt)) {
+    			rfs.addSubDataTable(dt);
+    			if(baseDao.saveFieldSetEntity(rfs)) {//鍒涘缓浠诲姟
+    				deviceTaskService.automaticCreateTask(
+    						String.format(DeviceConst.TASK_TITLE_FORMAT_SPOT_CHECK, fs.getString(DeviceConst.DEVICE_NAME))
+    						,DeviceConst.TASK_TYPE_SPOT_CHECK
+    						,rfs.getUUID()
+    						,fs.getString(DeviceConst.DEVICE_MANAGER)
+    						);
+    				
+    			}
+    		}
+    		return  rfs.getUUID();
+    	}
+    	
+    	return null;
     }
     
     
-}
+    
+}
\ No newline at end of file

--
Gitblit v1.9.2