叶松
2023-11-03 2d229eef4d2b3bf972e1b4e46d027acf0d080d3b
hd/pipe/engineeringManage/src/main/java/com/thhy/engineering/modules/biz/device/service/impl/TBigDeviceServiceImpl.java
@@ -16,6 +16,8 @@
import com.thhy.engineering.modules.biz.file.service.FileService;
import com.thhy.general.common.BasicResult;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.ExcelUtils;
import com.thhy.general.utils.UUIDUtils;
import com.thhy.general.utils.UserInfoUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -24,6 +26,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -37,6 +40,7 @@
    @Resource
    private FileService fileService;
    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
    @Override
    @Transactional
@@ -50,35 +54,40 @@
        if(!StringUtil.isEmpty(bigDeviceId)){
            return BasicResult.faild("11111","设备编号重复","error");
        }
        values.put("bigDeviceId","");
        values.put("bigDeviceId", UUIDUtils.create());
        values.put("companyId",companyId);
        values.put("createUser",sysUserInfo.getUserId());
        try {
            values.put("dateOfProduction",sdf.parse((String) values.get("dateOfProduction")));
            values.put("useYearMonth",sdf.parse((String) values.get("useYearMonth")));
        }catch (Exception e){}
        bigDeviceMapper.bigDeviceInsert(values);
        //大型生产设备id
        String bigDeviceId1 = values.get("bigDeviceId").toString();
        //图片 列表
        List<String> pictures = (List<String>) values.get("pictures");
        if(pictures!=null && pictures.size()>0){
            for (String p:pictures){
                HashMap<String, Object> val = new HashMap<>();
                val.put("bigDeviceId",bigDeviceId1);
                val.put("id","");
                val.put("fileType",1);
                val.put("filePath",p);
                bigDeviceMapper.picturesInsert(val);
            }
        }
        //文件
        List<String> files = (List<String>) values.get("files");
        if(files!=null && files.size()>0){
            for (String f:files){
                HashMap<String, Object> val = new HashMap<>();
                val.put("bigDeviceId",bigDeviceId1);
                val.put("id","");
                val.put("fileType",2);
                val.put("filePath",f);
                bigDeviceMapper.picturesInsert(val);
            }
        }
//        //大型生产设备id
//        String bigDeviceId1 = values.get("bigDeviceId").toString();
//        //图片 列表
//        List<String> pictures = (List<String>) values.get("pictures");
//        if(pictures!=null && pictures.size()>0){
//            for (String p:pictures){
//                HashMap<String, Object> val = new HashMap<>();
//                val.put("bigDeviceId",bigDeviceId1);
//                val.put("id","");
//                val.put("fileType",1);
//                val.put("filePath",p);
//                bigDeviceMapper.picturesInsert(val);
//            }
//        }
//        //文件
//        List<String> files = (List<String>) values.get("files");
//        if(files!=null && files.size()>0){
//            for (String f:files){
//                HashMap<String, Object> val = new HashMap<>();
//                val.put("bigDeviceId",bigDeviceId1);
//                val.put("id","");
//                val.put("fileType",2);
//                val.put("filePath",f);
//                bigDeviceMapper.picturesInsert(val);
//            }
//        }
        return BasicResult.success("添加成功");
    }
@@ -98,22 +107,6 @@
    @Override
    public BasicResult bigDeviceInfo(String bigDeviceId) {
        TBigDevice tBigDevices = bigDeviceMapper.bigDeviceInfo(bigDeviceId);
        List<TBigPath> bigPaths = bigDeviceMapper.devicePath(bigDeviceId);
        bigPaths.stream().forEach(fl->{
            JSONObject json = new JSONObject();
            json.put("fullpath",fl.getFilePath());
            BasicResult basicResult = fileService.fileinfo(json.toJSONString());
            if(basicResult.isSuccess()){
                JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString());
                for(Object obj : jsonArray){
                    JSONObject j = JSON.parseObject(obj.toString());
                    if(j.containsKey("name")&&"name".equals(j.getString("name"))){
                        fl.setFilePathName(j.getString("value"));
                    }
                }
            }
        });
        tBigDevices.setTBigPaths(bigPaths);
        return BasicResult.success(tBigDevices);
    }
@@ -136,31 +129,35 @@
        if(!StringUtil.isEmpty(bigDeviceId)&&!bigDeviceId.equals(bigDeviceId1)){
            return BasicResult.faild("11111","设备编号重复","error");
        }
        bigDeviceMapper.bigDevicePathDel(bigDeviceId1);
        List<String> pictures = (List<String>) values.get("pictures");
        if(pictures!=null && pictures.size()>0){
            for (String p:pictures){
                HashMap<String, Object> val = new HashMap<>();
                val.put("bigDeviceId",bigDeviceId1);
                val.put("id","");
                val.put("fileType",1);
                val.put("filePath",p);
                bigDeviceMapper.picturesInsert(val);
            }
        }
        //文件
        List<String> files = (List<String>) values.get("files");
        if(files!=null && files.size()>0){
            for (String f:files){
                HashMap<String, Object> val = new HashMap<>();
                val.put("bigDeviceId",bigDeviceId1);
                val.put("id","");
                val.put("fileType",2);
                val.put("filePath",f);
                bigDeviceMapper.picturesInsert(val);
            }
        }
//        bigDeviceMapper.bigDevicePathDel(bigDeviceId1);
//
//        List<String> pictures = (List<String>) values.get("pictures");
//        if(pictures!=null && pictures.size()>0){
//            for (String p:pictures){
//                HashMap<String, Object> val = new HashMap<>();
//                val.put("bigDeviceId",bigDeviceId1);
//                val.put("id","");
//                val.put("fileType",1);
//                val.put("filePath",p);
//                bigDeviceMapper.picturesInsert(val);
//            }
//        }
//        //文件
//        List<String> files = (List<String>) values.get("files");
//        if(files!=null && files.size()>0){
//            for (String f:files){
//                HashMap<String, Object> val = new HashMap<>();
//                val.put("bigDeviceId",bigDeviceId1);
//                val.put("id","");
//                val.put("fileType",2);
//                val.put("filePath",f);
//                bigDeviceMapper.picturesInsert(val);
//            }
//        }
        try {
            values.put("dateOfProduction",sdf.parse((String) values.get("dateOfProduction")));
            values.put("useYearMonth",sdf.parse((String) values.get("useYearMonth")));
        }catch (Exception e){}
        bigDeviceMapper.bigDeviceUpdate(values);
        return BasicResult.success("修改成功");
    }
@@ -179,50 +176,23 @@
        String companyId = sysUserInfo.getCompanyId();
        values.put("companyId",companyId);
        List<TBigDevice> tBigDevices = bigDeviceMapper.bigDeviceList(values);
        List<BigDeviceExcelDto> bigDeviceExcelDtos = new ArrayList<>();
        for (TBigDevice bigDevice : tBigDevices){
            BigDeviceExcelDto bigDeviceExcelDto = new BigDeviceExcelDto();
            bigDeviceExcelDto.setBigDeviceName(bigDevice.getBigDeviceName());
            bigDeviceExcelDto.setBigDeviceModel(bigDevice.getBigDeviceModel());
            bigDeviceExcelDto.setBigNumber(bigDevice.getBigNumber());
            bigDeviceExcelDto.setBigTypeName(bigDevice.getBigTypeName());
            bigDeviceExcelDto.setBigPosition(bigDevice.getBigPosition());
            if(bigDevice.getBigState()!=null&&bigDevice.getBigState()==1){
                bigDeviceExcelDto.setBigState("在线");
            }else{
                bigDeviceExcelDto.setBigState("离线");
        tBigDevices.forEach(t->{
            if ("1".equals(t.getBigType())){
                t.setBigTypeName("特种设备");
            }else if ("2".equals(t.getBigType())){
                t.setBigTypeName("一般设备");
            }
            bigDeviceExcelDto.setRealName(bigDevice.getRealName());
            bigDeviceExcelDto.setSupplierName(bigDevice.getSupplierName());
            bigDeviceExcelDto.setKeyCabinet(bigDevice.getKeyCabinet());
            bigDeviceExcelDto.setUseLife(bigDevice.getUseLife());
            bigDeviceExcelDtos.add(bigDeviceExcelDto);
        }
        ExcelWriter excel = new ExcelWriter();//定义excel
        excel.addHeaderAlias("bigDeviceName", "设备名称");
        excel.addHeaderAlias("bigDeviceModel", "规格型号");
        excel.addHeaderAlias("bigNumber", "设备编号");
        excel.addHeaderAlias("bigTypeName", "设备类型");
        excel.addHeaderAlias("bigPosition", "安装位置");
        excel.addHeaderAlias("bigState", "设备状态");
        excel.addHeaderAlias("realName", "操作工人");
        excel.addHeaderAlias("supplierName", "供应商");
        excel.addHeaderAlias("keyCabinet", "钥匙柜编号");
        excel.addHeaderAlias("useLife", "使用年限");
        response.setContentType("application/vnd.ms-excel;charset=UTF-8");
        response.setHeader("Content-Disposition", "attachment;filename=test.xls");
        OutputStream out = null;
        try {
            out = response.getOutputStream();
            excel.write(bigDeviceExcelDtos);
            excel.flush(out, true);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭writer,释放内存
            excel.close();
        }
        IoUtil.close(out);
            if (t.getUseStatus() == 1){
                t.setUseStatusName("良好");
            }else if (t.getUseStatus() == 2){
                t.setUseStatusName("老化");
            }
            if (t.getIsNeed() == 1){
                t.setIsNeedName("是");
            }else if (t.getIsNeed() == 2){
                t.setIsNeedName("否");
            }
        });
        ExcelUtils.downExcel(tBigDevices,TBigDevice.class,response,"设备信息管理");
    }
}