From f373bbf83d9d2a7e5f96118d7dcd658c9fea8bc8 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期四, 14 八月 2025 17:27:44 +0800 Subject: [PATCH] 2025.8.14 1. 新增文件导入场景信息接口 2. 新增导出接口文档接口 --- src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ResponseUtils.java | 44 + src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ScenseService.kt | 2 src/main/kotlin/cn/flightfeather/supervision/lightshare/web/OpenApiWordController.java | 105 ++ src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt | 15 src/main/kotlin/cn/flightfeather/supervision/common/exception/BizException.kt | 6 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt | 9 src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ProblemlistController.kt | 3 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/OpenApiWordServiceImpl.java | 884 ++++++++++++++++++++++ src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ScenseController.kt | 4 src/test/kotlin/cn/flightfeather/supervision/business/autooutput/AopEvaluationTest.kt | 24 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/OpenApiWordService.java | 18 src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Table.java | 163 ++++ src/main/kotlin/cn/flightfeather/supervision/common/api2word/JavaConfig.java | 47 + src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/RequestUtils.java | 29 src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/SceneRep.kt | 71 + src/main/kotlin/cn/flightfeather/supervision/lightshare/web/DeviceController.kt | 2 src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt | 78 + src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ModelAttrUtils.java | 72 + src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Request.java | 87 ++ src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/JsonUtils.java | 66 + src/main/resources/mapper/ds1/SceneConstructionSiteMapper.xml | 1 src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt | 141 ++- src/main/kotlin/cn/flightfeather/supervision/common/utils/ExcelUtil.kt | 5 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt | 14 src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Response.java | 48 + src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/RegionRep.kt | 8 src/main/resources/templates/word.html | 212 +++++ src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/ModelAttr.java | 107 ++ src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt | 4 src/main/kotlin/cn/flightfeather/supervision/config/CorsConfig.kt | 2 src/main/resources/application.yml | 1 src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/MenuUtils.java | 25 src/main/kotlin/cn/flightfeather/supervision/domain/ds1/entity/SceneConstructionSite.java | 16 33 files changed, 2,208 insertions(+), 105 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt index e8f9e4e..c7db9cf 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt @@ -29,8 +29,10 @@ * 璁剧疆鏁版嵁婧� */ fun setResource(topTaskGuid: String?, sceneType: Int, districtName: String?, townCode: String?) { - val config = AopDataConfig(topTaskGuid = topTaskGuid, sceneType = sceneType, districtName = districtName, - townCode = townCode) + val config = AopDataConfig( + topTaskGuid = topTaskGuid, sceneType = sceneType, districtName = districtName, + townCode = townCode + ) evaluationScene.config = config val check = aopSceneTypeCheck.checkSceneType(sceneType) if (check.first) { @@ -60,8 +62,10 @@ fun setResource(subtask: Subtask) { val scene = aopDbMapper.scenseMapper.selectByPrimaryKey(subtask.scenseid) val sceneType = scene.typeid?.toInt() - val config = AopDataConfig(topTaskGuid = subtask.tguid, sceneType = sceneType, - districtName = subtask.districtname, townCode = subtask.towncode) + val config = AopDataConfig( + topTaskGuid = subtask.tguid, sceneType = sceneType, + districtName = subtask.districtname, townCode = subtask.towncode + ) evaluationScene.config = config // val check = aopSceneTypeCheck.checkSceneType(sceneType) this.mode = 0 @@ -72,7 +76,7 @@ /** * 杞鏁版嵁婧� */ - fun loop(callback: (index:Int, evaluationScene: EvaluationScene) -> Unit) { + fun loop(callback: (index: Int, evaluationScene: EvaluationScene) -> Unit) { when (mode) { 0 -> { sceneSourceList.forEachIndexed { i, scene -> @@ -84,6 +88,7 @@ } while (evaluationScene.gotoNextSubTask()) } } + 1 -> { userSourceList.forEachIndexed { i, user -> evaluationScene.clear() @@ -109,6 +114,7 @@ callback(i, evaluationScene) } } + 1 -> { userSourceList.forEachIndexed { i, user -> evaluationScene.clear() @@ -149,7 +155,7 @@ } // 鍗曚釜璇勪及瀵硅薄 - inner class EvaluationScene(){ + inner class EvaluationScene() { var index = 0 var config: AopDataConfig? = null @@ -160,7 +166,7 @@ fun setDefaultScene(s: Scense?) { scene.value = s - userInfoTZ.fetch = {_,_ -> + userInfoTZ.fetch = { _, _ -> val svUserId = aopDbMapper.userinfoMapper.selectByExample(Example(Userinfo::class.java).apply { createCriteria().andEqualTo("dGuid", scene.value?.guid) })?.takeIf { m -> m.isNotEmpty() }?.get(0)?.guid @@ -173,7 +179,7 @@ fun setDefaultUserTZ(u: UserinfoTZ?) { userInfoTZ.value = u - scene.fetch = {_,_ -> + scene.fetch = { _, _ -> val svUserId = aopDbMapper.userMapMapper.selectByExample(Example(UserMap::class.java).apply { createCriteria().andEqualTo("tzUserId", userInfoTZ.value?.guid) })?.takeIf { m -> m.isNotEmpty() }?.get(0)?.svUserId @@ -182,15 +188,16 @@ } } - val userInfo = InfoProxy<Userinfo>{_,_ -> + val userInfo = InfoProxy<Userinfo> { _, _ -> scene.value?.guid ?: return@InfoProxy null return@InfoProxy aopDbMapper.userinfoMapper.selectOne(Userinfo().apply { dGuid = scene.value?.guid }) } + //宸℃煡浠诲姟淇℃伅 var subTaskIndex = 0 - val subTask = InfoProxy<Subtask> {_,_ -> + val subTask = InfoProxy<Subtask> { _, _ -> return@InfoProxy if (subTaskList.value?.isNotEmpty() == true) { subTaskList.value?.get(subTaskIndex) } else { @@ -198,7 +205,7 @@ } } - val subTaskList = InfoProxy<List<Subtask>> {_,_ -> + val subTaskList = InfoProxy<List<Subtask>> { _, _ -> return@InfoProxy aopDbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply { createCriteria().andEqualTo("scenseid", scene.value?.guid) // .andBetween("planstarttime", config?.startTime, config?.endTime) @@ -207,25 +214,28 @@ } //鐜板満宸℃煡淇℃伅 - val inspection = InfoProxy<Inspection>{_,_ -> + val inspection = InfoProxy<Inspection> { _, _ -> val inspection = Inspection() inspection.stguid = subTask.value?.stguid return@InfoProxy aopDbMapper.inspectionMapper.selectOne(inspection) } //鍚勫満鏅壒鏈夌殑鍩烘湰淇℃伅 - val baseScene = InfoProxy<BaseScene> {_,_ -> + val baseScene = InfoProxy<BaseScene> { _, _ -> return@InfoProxy when (config?.sceneType.toString()) { // 鐩戠绯荤粺 Constant.SceneType.TYPE1.value -> { aopDbMapper.sceneConstructionSiteMapper.selectByPrimaryKey(scene.value?.guid) } + Constant.SceneType.TYPE2.value -> { aopDbMapper.sceneWharfMapper.selectByPrimaryKey(scene.value?.guid) } + Constant.SceneType.TYPE3.value -> { aopDbMapper.sceneMixingPlantMapper.selectByPrimaryKey(scene.value?.guid) } + Constant.SceneType.TYPE14.value -> { aopDbMapper.sceneStorageYardMapper.selectByPrimaryKey(scene.value?.guid) } @@ -233,15 +243,17 @@ Constant.SceneType.TYPE5.value -> { aopDbMapper.restaurantBaseInfoMapper.selectByPrimaryKey(userInfoTZ.value?.guid) } + Constant.SceneType.TYPE6.value -> { aopDbMapper.vehicleBaseInfoMapper.selectByPrimaryKey(userInfoTZ.value?.guid) } + else -> null } } //鍏蜂綋鐨勯棶棰� - val problems = InfoProxy<MutableList<Problemlist>> {_,_ -> + val problems = InfoProxy<MutableList<Problemlist>> { _, _ -> if (noRecord()) return@InfoProxy mutableListOf() return@InfoProxy aopDbMapper.problemlistMapper.selectByExample(Example(Problemlist::class.java).apply { createCriteria().andEqualTo("stguid", subTask.value?.stguid) @@ -249,7 +261,7 @@ } //璇勪及鎬诲垎 - val evaluation = InfoProxy<Evaluation> {_,_ -> + val evaluation = InfoProxy<Evaluation> { _, _ -> if (noRecord()) return@InfoProxy null return@InfoProxy aopDbMapper.evaluationMapper.selectByExample(Example(Evaluation::class.java).apply { @@ -258,7 +270,7 @@ } //璇勪及缁嗗垯寰楀垎 - val itemevaluationList = InfoProxy<MutableList<Itemevaluation>> {_,_ -> + val itemevaluationList = InfoProxy<MutableList<Itemevaluation>> { _, _ -> return@InfoProxy aopDbMapper.itemevaluationMapper.selectByExample(Example(Itemevaluation::class.java).apply { createCriteria().andEqualTo("stguid", subTask.value?.stguid) }) @@ -289,6 +301,14 @@ createCriteria() .andEqualTo("tasktypeid", 99) .andEqualTo("scensetypeid", scene.value?.typeid) + and(createCriteria().orEqualTo("provincecode", scene.value?.provincecode).orIsNull("provincecode")) + and(createCriteria().orEqualTo("citycode", scene.value?.citycode).orIsNull("citycode")) + and(createCriteria().orEqualTo("districtcode", scene.value?.districtcode).orIsNull("districtcode")) + and(createCriteria().orEqualTo("towncode", scene.value?.towncode).orIsNull("towncode")) + orderBy("towncode").desc() + .orderBy("districtcode").desc() + .orderBy("citycode").desc() + .orderBy("provincecode").desc() }) if (rule.isNotEmpty()) { this@EvaluationScene.baseRule.value = rule[0] @@ -349,7 +369,7 @@ val rules = InfoProxy<MutableList<Pair<EvaluationSubRuleVo, MutableList<EvaluationSubRuleVo>>>>() //蹇呭~鍙拌处鏁伴噺 - val ledgerCount = InfoProxy<Int>(config?.sceneType.toString()) {_, cacheMap -> + val ledgerCount = InfoProxy<Int>(config?.sceneType.toString()) { _, cacheMap -> val tzSceneType = Constant.SceneType.typeMap(scene.value?.typeid) val list = aopDbMapper.ledgerSubTypeMapper.selectCountByExample(Example(LedgerSubType::class.java).apply { createCriteria().andEqualTo("lScenetype", tzSceneType).andEqualTo("lNeedupdate", true) @@ -359,7 +379,7 @@ } //鐢ㄦ埛瀹為檯鎻愪氦鍙拌处鏁伴噺 - val ledgerRecords = InfoProxy<List<LedgerRecord>> {_,_ -> + val ledgerRecords = InfoProxy<List<LedgerRecord>> { _, _ -> return@InfoProxy aopDbMapper.ledgerRecordMapper.selectByExample(Example(LedgerRecord::class.java).apply { createCriteria().andEqualTo("lrYear", config?.year) .andEqualTo("lrMonth", config?.month) @@ -378,9 +398,12 @@ orderBy("planstarttime").desc() }) if (r.isNotEmpty()) { - val thisMonth = LocalDateTime.ofInstant(subTask.value?.planstarttime?.toInstant(), ZoneId.systemDefault()) - .withDayOfMonth(1).toLocalDate() - val lastMonth = LocalDateTime.ofInstant(r[0]?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1).toLocalDate() + val thisMonth = + LocalDateTime.ofInstant(subTask.value?.planstarttime?.toInstant(), ZoneId.systemDefault()) + .withDayOfMonth(1).toLocalDate() + val lastMonth = + LocalDateTime.ofInstant(r[0]?.planstarttime?.toInstant(), ZoneId.systemDefault()).withDayOfMonth(1) + .toLocalDate() if (lastMonth.plusMonths(1).isEqual(thisMonth)) { last.subTask.value = r[0] } @@ -458,12 +481,13 @@ if (defaultValue != null) { return defaultValue } else if (!fetched && _value == null) { - _value = if (cacheMap.containsKey(key) && LocalDateTime.now().minusDays(1).isBefore(cacheTimeStamp)) { - cacheMap[key] - } else { - cacheTimeStamp = LocalDateTime.now() - fetch(defaultValue, cacheMap) - } + _value = + if (cacheMap.containsKey(key) && LocalDateTime.now().minusDays(1).isBefore(cacheTimeStamp)) { + cacheMap[key] + } else { + cacheTimeStamp = LocalDateTime.now() + fetch(defaultValue, cacheMap) + } fetched = true } return _value diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt b/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt index 71e8712..a015e47 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/import/SceneImport.kt @@ -3,8 +3,10 @@ import cn.flightfeather.supervision.common.exception.BizException import cn.flightfeather.supervision.common.utils.Constant import cn.flightfeather.supervision.common.utils.ExcelUtil -import cn.flightfeather.supervision.domain.ds1.entity.Scense +import cn.flightfeather.supervision.domain.ds1.entity.* import cn.flightfeather.supervision.domain.ds1.repository.RegionRep +import cn.flightfeather.supervision.lightshare.vo.SceneDetail +import com.google.gson.Gson import org.apache.poi.ss.usermodel.CellType import org.springframework.stereotype.Component import java.io.InputStream @@ -17,9 +19,10 @@ class SceneImport( private val regionRep: RegionRep, ) { + // 鍦烘櫙鍏辨湁淇℃伅 private val headers = listOf( - ExcelUtil.MyHeader("缂栧彿锛堣嫢涓嶅~鍐欙紝鍒欐寜鐓ч『搴忚嚜鍔ㄦ坊鍔狅級", CellType.NUMERIC), + ExcelUtil.MyHeader("缂栧彿锛堝彲鐪佺暐锛�", CellType.NUMERIC, true), ExcelUtil.MyHeader("鍚嶇О", CellType.STRING), ExcelUtil.MyHeader("绫诲瀷", CellType.STRING), ExcelUtil.MyHeader("鍦板潃", CellType.STRING), @@ -33,51 +36,107 @@ ExcelUtil.MyHeader("鑱旂郴鐢佃瘽", CellType.STRING) ) + // 宸ュ湴淇℃伅 + private val headersType1 = listOf( + ExcelUtil.MyHeader("宸ョ▼绫诲瀷", CellType.STRING), + ExcelUtil.MyHeader("寤鸿鐘舵��", CellType.STRING), + ExcelUtil.MyHeader("鏂藉伐闃舵", CellType.STRING), + ExcelUtil.MyHeader("寮�宸ユ椂闂�", CellType.STRING), + ExcelUtil.MyHeader("瀹屽伐鏃堕棿", CellType.STRING), + ExcelUtil.MyHeader("鍓╀綑宸ユ湡", CellType.STRING), + ExcelUtil.MyHeader("鍗犲湴闈㈢Н", CellType.NUMERIC), + ExcelUtil.MyHeader("鏂藉伐闈㈢Н", CellType.NUMERIC), + ExcelUtil.MyHeader("姣忔湀鏂藉伐闈㈢Н", CellType.NUMERIC), + ExcelUtil.MyHeader("涓氫富鍗曚綅", CellType.STRING), + ExcelUtil.MyHeader("涓氫富鍗曚綅鑱旂郴浜�", CellType.STRING), + ExcelUtil.MyHeader("涓氫富鍗曚綅鑱旂郴鐢佃瘽", CellType.STRING), + ExcelUtil.MyHeader("鏂藉伐鍗曚綅", CellType.STRING), + ExcelUtil.MyHeader("鏂藉伐鍗曚綅鑱旂郴浜�", CellType.STRING), + ExcelUtil.MyHeader("鏂藉伐鍗曚綅鑱旂郴鐢佃瘽", CellType.STRING), + ExcelUtil.MyHeader("瀹夊叏鍛�", CellType.STRING), + ExcelUtil.MyHeader("瀹夊叏鍛樼數璇�", CellType.STRING), + ) + /** * 閫氳繃鏂囦欢璇诲彇鍦烘櫙淇℃伅 */ - fun readFromFile(file: InputStream): List<Scense> { - val result = mutableListOf<Scense>() + fun readFromFile(file: InputStream): List<SceneDetail> { + val result = mutableListOf<SceneDetail>() try { ExcelUtil.readXLXS(file, headers) { - val data = Scense().apply { - guid = null - name = it.getCell(1)?.stringCellValue?.trim() - typeid = null - type = it.getCell(2)?.stringCellValue?.trim() - scensesubtypeid = null - scensesubtype = null - location = it.getCell(3)?.stringCellValue?.trim() - longitude = it.getCell(4)?.numericCellValue?.toBigDecimal() - latitude = it.getCell(5)?.numericCellValue?.toBigDecimal() - provincecode = null - provincename = it.getCell(6)?.stringCellValue?.trim() - citycode = null - cityname = it.getCell(7)?.stringCellValue?.trim() - districtcode = null - districtname = it.getCell(8)?.stringCellValue?.trim() - towncode = null - townname = it.getCell(9)?.stringCellValue?.trim() - contactst = it.getCell(11)?.stringCellValue?.trim() - contactswx = null - contacts = it.getCell(10)?.stringCellValue?.trim() - createdate = Date() - updatedate = Date() - extension1 = "1" - extension2 = null - index = it.getCell(5)?.stringCellValue?.trim()?.toInt() - remark = null + val data = SceneDetail().apply { + scense = Scense().apply { + guid = null + name = it.getCell(1)?.stringCellValue?.trim() + typeid = null + type = it.getCell(2)?.stringCellValue?.trim() + scensesubtypeid = null + scensesubtype = null + location = it.getCell(3)?.stringCellValue?.trim() + longitude = it.getCell(4)?.numericCellValue?.toBigDecimal() + latitude = it.getCell(5)?.numericCellValue?.toBigDecimal() + provincecode = null + provincename = it.getCell(6)?.stringCellValue?.trim() + citycode = null + cityname = it.getCell(7)?.stringCellValue?.trim() + districtcode = null + districtname = it.getCell(8)?.stringCellValue?.trim() + towncode = null + townname = it.getCell(9)?.stringCellValue?.trim() + contactst = it.getCell(11)?.stringCellValue?.trim() + contactswx = null + contacts = it.getCell(10)?.stringCellValue?.trim() + createdate = Date() + updatedate = Date() + extension1 = "1" + extension2 = null + index = it.getCell(0)?.numericCellValue?.toInt() + remark = null + } + scense?.typeid = Constant.SceneType.getByName(scense?.type)?.value?.toByte() + ?: throw BizException(errorStr(it.rowNum + 1, 3, "鍦烘櫙绫诲瀷涓嶅瓨鍦�")) + scense?.provincecode = regionRep.findProvince(scense?.provincename)?.provincecode + ?: throw BizException(errorStr(it.rowNum + 1, 7, "鐪佷唤閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) + scense?.citycode = regionRep.findCity(scense?.cityname)?.citycode + ?: throw BizException(errorStr(it.rowNum + 1, 8, "鍩庡競閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) + scense?.districtcode = regionRep.findDistrict(scense?.districtname)?.districtcode + ?: throw BizException(errorStr(it.rowNum + 1, 9, "鍖哄幙閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) + scense?.towncode = regionRep.findTown(scense?.townname)?.towncode + ?: throw BizException(errorStr(it.rowNum + 1, 10, "琛楅晣閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) + + when (scense?.typeid.toString()) { + Constant.SceneType.TYPE1.value -> { + subScene = SceneConstructionSite().apply { + csProjectType = it.getCell(12)?.stringCellValue?.trim() + csStatus = it.getCell(13)?.stringCellValue?.trim() + siExtension1 = it.getCell(14)?.stringCellValue?.trim() + csStartTime = it.getCell(15)?.stringCellValue?.trim() + csEndTime = it.getCell(16)?.stringCellValue?.trim() + csLeftTime = it.getCell(17)?.stringCellValue?.trim() + csFloorSpace = it.getCell(18)?.numericCellValue?.toString() + csConstructionArea = it.getCell(19)?.numericCellValue?.toString() + csConstructionAreaPerMonth = it.getCell(20)?.numericCellValue?.toString() + csEmployerUnit = it.getCell(21)?.stringCellValue?.trim() + csEmployerContacts = it.getCell(22)?.stringCellValue?.trim() + csEmployerContactsTel = it.getCell(23)?.stringCellValue?.trim() + csConstructionUnit = it.getCell(24)?.stringCellValue?.trim() + csConstructionContacts = it.getCell(25)?.stringCellValue?.trim() + csConstructionContactsTel = it.getCell(26)?.stringCellValue?.trim() + csSecurityOfficer = it.getCell(27)?.stringCellValue?.trim() + csSecurityOfficerTel = it.getCell(28)?.stringCellValue?.trim() + } + } + Constant.SceneType.TYPE2.value -> { + + } + Constant.SceneType.TYPE3.value -> { + + } + Constant.SceneType.TYPE14.value -> { + + } + } } - data.typeid = Constant.SceneType.getByName(data.type)?.value?.toByte() - ?: throw BizException(errorStr(it.rowNum + 1, 2, "鍦烘櫙绫诲瀷涓嶅瓨鍦�")) - data.provincecode = regionRep.findProvince(data.provincename)?.provincecode - ?: throw BizException(errorStr(it.rowNum + 1, 6, "鐪佷唤閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) - data.citycode = regionRep.findCity(data.cityname)?.citycode - ?: throw BizException(errorStr(it.rowNum + 1, 7, "鍩庡競閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) - data.districtcode = regionRep.findDistrict(data.districtname)?.districtcode - ?: throw BizException(errorStr(it.rowNum + 1, 8, "鍖哄幙閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) - data.towncode = regionRep.findTown(data.townname)?.towncode - ?: throw BizException(errorStr(it.rowNum + 1, 9, "琛楅晣閿欒鎴栫郴缁熸湭鏇鹃厤缃�")) result.add(data) } diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/JavaConfig.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/JavaConfig.java new file mode 100644 index 0000000..858793e --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/JavaConfig.java @@ -0,0 +1,47 @@ +package cn.flightfeather.supervision.common.api2word; + +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.StringHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import javax.net.ssl.SSLContext; +import java.nio.charset.StandardCharsets; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +/** + * Created by XiuYin.Cui on 2018/6/21. + */ +@Configuration +public class JavaConfig { + + @Bean + public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true; + SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom() + .loadTrustMaterial(null, acceptingTrustStrategy) + .build(); + SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext); + CloseableHttpClient httpClient = HttpClients.custom() + .setSSLSocketFactory(csf) + .build(); + HttpComponentsClientHttpRequestFactory requestFactory = + new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClient); + + //60s + requestFactory.setConnectTimeout(60 * 1000); + requestFactory.setReadTimeout(60 * 1000); + RestTemplate restTemplate = new RestTemplate(requestFactory); + restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); + return restTemplate; + } +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/ModelAttr.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/ModelAttr.java new file mode 100644 index 0000000..63a078c --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/ModelAttr.java @@ -0,0 +1,107 @@ +package cn.flightfeather.supervision.common.api2word.model; + +import org.apache.commons.lang3.StringUtils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * 杩斿洖灞炴�� + * + * @author kevin + */ +public class ModelAttr implements Serializable { + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public Boolean getRequire() { + return require; + } + + public void setRequire(Boolean require) { + this.require = require; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public List<ModelAttr> getProperties() { + return properties; + } + + public void setProperties(List<ModelAttr> properties) { + this.properties = properties; + } + + public boolean isCompleted() { + return isCompleted; + } + + public void setCompleted(boolean isCompleted) { + this.isCompleted = isCompleted; + } + + public static long getSerialversionuid() { + return serialVersionUID; + } + + private static final long serialVersionUID = -4074067438450613643L; + + /** + * 绫诲悕 + */ + private String className = StringUtils.EMPTY; + /** + * 灞炴�у悕 + */ + private String name = StringUtils.EMPTY; + /** + * 绫诲瀷 + */ + private String type = StringUtils.EMPTY; + /** + * 鏄惁蹇呭~ + */ + private Boolean require = false; + /** + * 灞炴�ф弿杩� + */ + private String description; + /** + * 宓屽灞炴�у垪琛� + */ + private List<ModelAttr> properties = new ArrayList<>(); + + /** + * 鏄惁鍔犺浇瀹屾垚锛岄伩鍏嶅惊鐜紩鐢� + */ + private boolean isCompleted = false; +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Request.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Request.java new file mode 100644 index 0000000..4fc44a8 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Request.java @@ -0,0 +1,87 @@ +package cn.flightfeather.supervision.common.api2word.model; + +import java.io.Serializable; + +/** + * Created by XiuYin.Cui on 2018/1/11. + */ +public class Request implements Serializable{ + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getParamType() { + return paramType; + } + + public void setParamType(String paramType) { + this.paramType = paramType; + } + + public Boolean getRequire() { + return require; + } + + public void setRequire(Boolean require) { + this.require = require; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public ModelAttr getModelAttr() { + return modelAttr; + } + + public void setModelAttr(ModelAttr modelAttr) { + this.modelAttr = modelAttr; + } + + /** + * 鍙傛暟鍚� + */ + private String name; + + /** + * 鏁版嵁绫诲瀷 + */ + private String type; + + /** + * 鍙傛暟绫诲瀷 + */ + private String paramType; + + /** + * 鏄惁蹇呭~ + */ + private Boolean require; + + /** + * 璇存槑 + */ + private String remark; + + /** + * 澶嶆潅瀵硅薄寮曠敤 + */ + private ModelAttr modelAttr; +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Response.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Response.java new file mode 100644 index 0000000..6dc3a1a --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Response.java @@ -0,0 +1,48 @@ +package cn.flightfeather.supervision.common.api2word.model; + +import java.io.Serializable; + +/** + * Created by XiuYin.Cui on 2018/1/11. + */ +public class Response implements Serializable{ + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + /** + * 杩斿洖鍙傛暟 + */ + private String description; + + /** + * 鍙傛暟鍚� + */ + private String name; + + /** + * 澶囨敞 + */ + private String remark; +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Table.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Table.java new file mode 100644 index 0000000..ca59c40 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/model/Table.java @@ -0,0 +1,163 @@ +package cn.flightfeather.supervision.common.api2word.model; + +import java.util.List; + +/** + * Created by XiuYin.Cui on 2018/1/11. + */ +public class Table { + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getRequestForm() { + return requestForm; + } + + public void setRequestForm(String requestForm) { + this.requestForm = requestForm; + } + + public String getResponseForm() { + return responseForm; + } + + public void setResponseForm(String responseForm) { + this.responseForm = responseForm; + } + + public String getRequestType() { + return requestType; + } + + public void setRequestType(String requestType) { + this.requestType = requestType; + } + + public List<Request> getRequestList() { + return requestList; + } + + public void setRequestList(List<Request> requestList) { + this.requestList = requestList; + } + + public List<Response> getResponseList() { + return responseList; + } + + public void setResponseList(List<Response> responseList) { + this.responseList = responseList; + } + + public String getRequestParam() { + return requestParam; + } + + public void setRequestParam(String requestParam) { + this.requestParam = requestParam; + } + + public String getResponseParam() { + return responseParam; + } + + public void setResponseParam(String responseParam) { + this.responseParam = responseParam; + } + + public ModelAttr getModelAttr() { + return modelAttr; + } + + public void setModelAttr(ModelAttr modelAttr) { + this.modelAttr = modelAttr; + } + + /** + * 澶ф爣棰� + */ + private String title; + /** + * 灏忔爣棰� + */ + private String tag; + /** + * url + */ + private String url; + + /** + * 鎻忚堪 + */ + private String description; + + /** + * 璇锋眰鍙傛暟鏍煎紡 + */ + private String requestForm; + + /** + * 鍝嶅簲鍙傛暟鏍煎紡 + */ + private String responseForm; + + /** + * 璇锋眰鏂瑰紡 + */ + private String requestType; + + /** + * 璇锋眰浣� + */ + private List<Request> requestList; + + /** + * 杩斿洖浣� + */ + private List<Response> responseList; + + /** + * 璇锋眰鍙傛暟 + */ + private String requestParam; + + /** + * 杩斿洖鍙傛暟 + */ + private String responseParam; + + /** + * 杩斿洖灞炴�у垪琛� + */ + private ModelAttr modelAttr = new ModelAttr(); +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/JsonUtils.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/JsonUtils.java new file mode 100644 index 0000000..1999749 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/JsonUtils.java @@ -0,0 +1,66 @@ +package cn.flightfeather.supervision.common.api2word.utils; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + +import java.io.IOException; +import java.util.List; + +/** + * @author cuixiuyin + * @Date: 2018/11/05 + */ + +public class JsonUtils { + + private static ObjectMapper objectMapper = new ObjectMapper(); + + static { + objectMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true); + objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true); + objectMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true); + } + + public static <T> T readValue(String jsonStr, Class<T> clazz) throws IOException { + return objectMapper.readValue(jsonStr, clazz); + } + + public static <T> List<T> readListValue(String jsonStr, Class<T> clazz) throws IOException { + JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, clazz); + return objectMapper.readValue(jsonStr, javaType); + } + + public static ArrayNode readArray(String jsonStr) throws IOException { + JsonNode node = objectMapper.readTree(jsonStr); + if (node.isArray()) { + return (ArrayNode) node; + } + return null; + } + + public static JsonNode readNode(String jsonStr) throws IOException { + return objectMapper.readTree(jsonStr); + } + + public static String writeJsonStr(Object obj) throws JsonProcessingException { + return objectMapper.writeValueAsString(obj); + } + + public static ObjectNode createObjectNode() { + return objectMapper.createObjectNode(); + } + + public static ArrayNode createArrayNode() { + return objectMapper.createArrayNode(); + } + +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/MenuUtils.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/MenuUtils.java new file mode 100644 index 0000000..7e8eb99 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/MenuUtils.java @@ -0,0 +1,25 @@ +package cn.flightfeather.supervision.common.api2word.utils; + +/** + * @author : cuixiuyin + * @date : 2019/8/31 + */ +public class MenuUtils { + + public static Integer count = 0; + public static String menuStr = "null"; + + public static boolean isMenu(String tags) { + if (menuStr.equals(tags)) { + count++; + } else { + menuStr = tags; + count = 0; + } + if (count == 0) { + return true; + } else { + return false; + } + } +} diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ModelAttrUtils.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ModelAttrUtils.java new file mode 100644 index 0000000..21d9510 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ModelAttrUtils.java @@ -0,0 +1,72 @@ +package cn.flightfeather.supervision.common.api2word.utils; + + +import cn.flightfeather.supervision.common.api2word.model.ModelAttr; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +/** + * @author ivenhan + * @Date: 2020/10/15 + */ + +public class ModelAttrUtils { + + // 灏佽schema - properties涓嬫煇涓叿浣損roperty瀵硅薄 + public static ModelAttr propertyModelAttr(Map<String, Map<String, Object>> property) { + ModelAttr modeAttr = new ModelAttr(); + + Map<String, Object> modeProperties = (Map<String, Object>) property.get("properties"); + ArrayList modeRequired = (ArrayList) property.get("required"); + List<ModelAttr> attrList = new ArrayList<>(); + + if (modeProperties != null) { + Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator(); + + //瑙f瀽灞炴�� + while (mIt.hasNext()) { + Entry<String, Object> mEntry = mIt.next(); + Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue(); + ModelAttr child = new ModelAttr(); + child.setName(mEntry.getKey()); + child.setType((String) attrInfoMap.get("type")); + if (attrInfoMap.get("format") != null) { + child.setType(child.getType() + "(" + attrInfoMap.get("format") + ")"); + } + child.setType(StringUtils.defaultIfBlank(child.getType(), "object")); + + Object ref = attrInfoMap.get("$ref"); + Object items = attrInfoMap.get("items"); + + if (items != null && ((Map) items).get("$ref") == null) { + ModelAttr refModel = propertyModelAttr((Map<String, Map<String, Object>>)items); + if (refModel != null) { + child.setProperties(refModel.getProperties()); + } + child.setType(child.getType()); + } + + child.setDescription((String) attrInfoMap.get("description")); + + child.setRequire(false); + if (modeRequired != null && modeRequired.contains(mEntry.getKey())) { + child.setRequire(true); + } + + attrList.add(child); + } + } + + Object title = property.get("title"); + Object description = property.get("description"); + modeAttr.setClassName(title == null ? "" : title.toString()); + modeAttr.setDescription(description == null ? "" : description.toString()); + modeAttr.setProperties(attrList); + return modeAttr; + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/RequestUtils.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/RequestUtils.java new file mode 100644 index 0000000..6a6b644 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/RequestUtils.java @@ -0,0 +1,29 @@ +package cn.flightfeather.supervision.common.api2word.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.util.Map; + + +/** + * @author : ivenhan + * @date : 2020/10/16 + */ +public class RequestUtils { + + public static void validateRequestKey(Map<String, Map> content) throws JsonProcessingException { + Map<String, Map> applicationJSON = content.get("application/json"); + if (applicationJSON == null) { + throw new JsonProcessingException("content瀛楁 缂哄皯 application/json 瀛楁") {}; + } + + Map<String, Map> schema = applicationJSON.get("schema"); + if (schema == null) { + throw new JsonProcessingException("content瀛楁 application/json 缂哄皯 schema 瀛楁") {}; + } + + if (schema.get("type") == null) { + throw new JsonProcessingException("content瀛楁 application/json 瀛楁 schema 瀛楁 缂哄皯 type瀛楁") {}; + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ResponseUtils.java b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ResponseUtils.java new file mode 100644 index 0000000..a574eb9 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/common/api2word/utils/ResponseUtils.java @@ -0,0 +1,44 @@ +package cn.flightfeather.supervision.common.api2word.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +/** + * @author : ivenhan + * @date : 2020/10/16 + */ +public class ResponseUtils { + + public static void validateResponseKey(Map<String, Map> content) throws JsonProcessingException { + Map<String, Map> applicationJSON = content.get("application/json"); + if (applicationJSON == null) { + throw new JsonProcessingException("content 瀛楁缂哄皯 application/json 瀛楁") {}; + } + + Map<String, Map> schema = applicationJSON.get("schema"); + if (schema == null) { + throw new JsonProcessingException("content 瀛楁 application/json 瀛楁 缂哄皯 schema 瀛楁") {}; + } + + if (schema.get("type") == null) { + throw new JsonProcessingException("content 瀛楁 application/json 瀛楁 schema 瀛楁 缂哄皯 type瀛楁") {}; + } + + Map items = schema.get("items"); + Map properties = schema.get("properties"); + if (items == null && properties == null) { + throw new JsonProcessingException("content 瀛楁 application/json 瀛楁 schema 瀛楁 缂哄皯 properties 鎴栬�� items 瀛楁") {}; + } + + + Set<Entry<String, Map>> contentValues = content.entrySet(); + + int size = contentValues.size(); + if ((applicationJSON.get("examples") != null && size > 2) || (applicationJSON.get("examples") == null && size > 1) ) { + throw new JsonProcessingException("content 瀛楁瀛樺湪闄� application/json 鎴栬�� examples 瀛楁涔嬪鐨勫叾浠栧瓧娈�") {}; + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/exception/BizException.kt b/src/main/kotlin/cn/flightfeather/supervision/common/exception/BizException.kt index 24118cc..ec4a233 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/common/exception/BizException.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/common/exception/BizException.kt @@ -5,9 +5,9 @@ */ class BizException : Exception { constructor():super() - constructor(message: String) : super(message) - constructor(message: String, cause: Throwable?) : super(message, cause) + constructor(message: String?) : super(message) + constructor(message: String?, cause: Throwable?) : super(message, cause) constructor(cause: Throwable?) : super(cause) - constructor(message: String, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) + constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super(message, cause, enableSuppression, writableStackTrace) } \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/common/utils/ExcelUtil.kt b/src/main/kotlin/cn/flightfeather/supervision/common/utils/ExcelUtil.kt index fc653ac..abfda36 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/common/utils/ExcelUtil.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/common/utils/ExcelUtil.kt @@ -36,6 +36,7 @@ class MyHeader( var name: String, val type: CellType, + val ignore: Boolean = false ) private fun cellTypeName(type: CellType): String = when (type) { @@ -74,8 +75,8 @@ iterator.forEach { // 妫�鏌ュ綋鍓嶈姣忎釜鍗曞厓鏍肩被鍨嬫槸鍚︿笌琛ㄥご瀹氫箟鍖归厤 headers.forEachIndexed { i, h -> - val t = it.getCell(i + 1).cellType - if (t != CellType.BLANK || t != h.type) { + val t = it.getCell(i)?.cellType ?: CellType.BLANK + if (t != CellType.BLANK && !h.ignore && t != h.type) { throw BizException("绗�${it.rowNum + 1}琛岋紝绗�${i + 1}鍒楀崟鍏冩牸鏍煎紡閿欒锛屽簲璇ヤ负${cellTypeName(h.type)}") } } diff --git a/src/main/kotlin/cn/flightfeather/supervision/config/CorsConfig.kt b/src/main/kotlin/cn/flightfeather/supervision/config/CorsConfig.kt index 50a22c2..8811d8c 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/config/CorsConfig.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/config/CorsConfig.kt @@ -2,10 +2,12 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile import org.springframework.web.cors.CorsConfiguration import org.springframework.web.cors.UrlBasedCorsConfigurationSource import org.springframework.web.filter.CorsFilter +@Profile("dev", "test") @Configuration class CorsConfig { diff --git a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/entity/SceneConstructionSite.java b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/entity/SceneConstructionSite.java index dcbfff7..78ecb94 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/entity/SceneConstructionSite.java +++ b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/entity/SceneConstructionSite.java @@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty; import javax.persistence.*; +import java.util.Date; @Table(name = "sm_t_scene_construction_site") @JsonInclude(JsonInclude.Include.NON_NULL) @@ -26,10 +27,10 @@ private String csProjectType; /** - * 鏂藉伐闃舵 + * 寤鸿鐘舵�� */ @Column(name = "CS_Status") - @ApiModelProperty("鏂藉伐闃舵") + @ApiModelProperty("寤鸿鐘舵��") private String csStatus; /** @@ -129,6 +130,9 @@ @Column(name = "CS_Security_Officer_Tel") @ApiModelProperty("瀹夊叏鍛樼數璇�") private String csSecurityOfficerTel; + + @Column(name = "CS_Update_Time") + private Date csUpdateTime; @Column(name = "SI_Extension1") private String siExtension1; @@ -448,6 +452,14 @@ this.csSecurityOfficerTel = csSecurityOfficerTel; } + public Date getCsUpdateTime() { + return csUpdateTime; + } + + public void setCsUpdateTime(Date csUpdateTime) { + this.csUpdateTime = csUpdateTime; + } + /** * @return SI_Extension1 */ diff --git a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/RegionRep.kt b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/RegionRep.kt index 5e789d8..b2918b7 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/RegionRep.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/RegionRep.kt @@ -39,25 +39,25 @@ } fun findProvince(name: String?): Province? { - return findCache(name) { + return findCache("Province$name") { provinceMapper.selectOne(Province().apply { provincename = name }) } } fun findCity(name: String?): City? { - return findCache(name) { + return findCache("City$name") { cityMapper.selectOne(City().apply { cityname = name }) } } fun findDistrict(name: String?): District? { - return findCache(name) { + return findCache("District$name") { districtMapper.selectOne(District().apply { districtname = name }) } } fun findTown(name: String?): Town? { - return findCache(name) { + return findCache("Town$name") { townMapper.selectOne(Town().apply { townname = name }) } } diff --git a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/SceneRep.kt b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/SceneRep.kt index 56e16a5..7a8e29e 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/SceneRep.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/SceneRep.kt @@ -1,10 +1,11 @@ package cn.flightfeather.supervision.domain.ds1.repository import cn.flightfeather.supervision.common.exception.BizException +import cn.flightfeather.supervision.common.utils.Constant import cn.flightfeather.supervision.common.utils.UUIDGenerator -import cn.flightfeather.supervision.domain.ds1.entity.Scense -import cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper -import cn.flightfeather.supervision.domain.ds1.mapper.UserinfoMapper +import cn.flightfeather.supervision.domain.ds1.entity.* +import cn.flightfeather.supervision.domain.ds1.mapper.* +import com.google.gson.Gson import org.springframework.stereotype.Repository import tk.mybatis.mapper.entity.Example import java.util.* @@ -17,6 +18,11 @@ private val scenseMapper: ScenseMapper, private val userinfoMapper: UserinfoMapper, private val subTaskRep: SubTaskRep, + val sceneConstructionSiteMapper: SceneConstructionSiteMapper, + val sceneDeviceMapper: SceneDeviceMapper, + val sceneMixingPlantMapper: SceneMixingPlantMapper, + val sceneStorageYardMapper: SceneStorageYardMapper, + val sceneWharfMapper: SceneWharfMapper, ) { fun insert(scene: Scense?):Int { @@ -26,6 +32,65 @@ return scenseMapper.insertSelective(scene) } + fun insertOrUpdateSubScene(typeId: Int?, guid: String?, subScene: BaseScene?): Pair<Boolean, Int> { + var r = 0 + var isUpdate = false + subScene ?: return false to 0 + + when (typeId.toString()) { + Constant.SceneType.TYPE1.value -> { + if ((subScene as SceneConstructionSite).getsGuid() == null) { + subScene.setsGuid(guid) + } + subScene.csUpdateTime = Date() + val record = sceneConstructionSiteMapper.selectByPrimaryKey(subScene.getsGuid()) + r = if (record == null) { + sceneConstructionSiteMapper.insert(subScene) + } else { + sceneConstructionSiteMapper.updateByPrimaryKeySelective(subScene) + } + } + + Constant.SceneType.TYPE2.value -> { + if ((subScene as SceneWharf).getsGuid() == null) { + subScene.setsGuid(guid) + } + val record = sceneWharfMapper.selectByPrimaryKey(subScene.getsGuid()) + r = if (record == null) { + sceneWharfMapper.insert(subScene) + } else { + sceneWharfMapper.updateByPrimaryKeySelective(subScene) + } + } + + Constant.SceneType.TYPE3.value -> { + if ((subScene as SceneMixingPlant).getsGuid() == null) { + subScene.setsGuid(guid) + } + val record = sceneMixingPlantMapper.selectByPrimaryKey(subScene.getsGuid()) + r = if (record == null) { + sceneMixingPlantMapper.insert(subScene) + } else { + sceneMixingPlantMapper.updateByPrimaryKeySelective(subScene) + } + } + + Constant.SceneType.TYPE14.value -> { + if ((subScene as SceneStorageYard).getsGuid() == null) { + subScene.setsGuid(guid) + } + val record = sceneStorageYardMapper.selectByPrimaryKey(subScene.getsGuid()) + isUpdate = record != null + r = if (record == null) { + sceneStorageYardMapper.insert(subScene) + } else { + sceneStorageYardMapper.updateByPrimaryKeySelective(subScene) + } + } + } + return isUpdate to r + } + fun findScene(userId: String?): Scense? { val user = userinfoMapper.selectByPrimaryKey(userId) ?: throw BizException("鐢ㄦ埛id涓嶅瓨鍦�") return scenseMapper.selectByPrimaryKey(user.dGuid) diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/OpenApiWordService.java b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/OpenApiWordService.java new file mode 100644 index 0000000..b52c4f8 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/OpenApiWordService.java @@ -0,0 +1,18 @@ +package cn.flightfeather.supervision.lightshare.service; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.Map; + +/** + * Created by XiuYin.Cui on 2018/1/12. + */ +public interface OpenApiWordService { + + Map<String,Object> tableList(String swaggerUrl); + + Map<String, Object> tableListFromString(String jsonStr) throws IOException; + + Map<String, Object> tableList(MultipartFile jsonFile) throws IOException; +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ScenseService.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ScenseService.kt index d1cbf61..a6d5a1d 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ScenseService.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ScenseService.kt @@ -49,7 +49,7 @@ /** * 閫氳繃鏂囦欢鎵归噺瀵煎叆鍦烘櫙淇℃伅 */ - fun importSceneInfo(file: MultipartFile): Boolean + fun importSceneInfo(files: Array<MultipartFile>): Boolean /** * 鍒涘缓鍦烘櫙淇℃伅 diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt index 29475cb..37e8bab 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt @@ -88,7 +88,7 @@ } return true } catch (e: Exception) { - throw BizException("鍑虹幇绯荤粺鍐呴儴閿欒") + throw BizException(e.message, e.cause) } } @@ -107,7 +107,7 @@ } return true } catch (e: Exception) { - throw BizException("鍑虹幇绯荤粺鍐呴儴閿欒") + throw BizException(e.message, e.cause) } } @@ -117,9 +117,10 @@ val sceneType = evaVo.scensetypeid?.toInt() ?: throw BizException("鍦烘櫙绫诲瀷鏈缃紝鏃犳硶鏇存柊鍒嗘暟") val source = AopDataSource(aopDbMapper, aopSceneTypeCheck) source.setResource(taskId, sceneType, null, null) + try { source.loop() { _, evaluationScene -> - if (evaluationScene.noRecord()) throw BizException("宸℃煡浠诲姟涓嶅瓨鍦�") + if (evaluationScene.noRecord()) return@loop evaVo.subTaskEvaList?.find { it.subTaskId == evaluationScene.subTask.value?.stguid }?.let {stEva -> @@ -131,7 +132,7 @@ } return true } catch (e: Exception) { - throw BizException("鍑虹幇绯荤粺鍐呴儴閿欒") + throw BizException(e.message, e.cause) } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/OpenApiWordServiceImpl.java b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/OpenApiWordServiceImpl.java new file mode 100644 index 0000000..f048e33 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/OpenApiWordServiceImpl.java @@ -0,0 +1,884 @@ +package cn.flightfeather.supervision.lightshare.service.impl; + + +import cn.flightfeather.supervision.common.api2word.model.ModelAttr; +import cn.flightfeather.supervision.common.api2word.model.Request; +import cn.flightfeather.supervision.common.api2word.model.Response; +import cn.flightfeather.supervision.common.api2word.model.Table; +import cn.flightfeather.supervision.common.api2word.utils.JsonUtils; +import cn.flightfeather.supervision.lightshare.service.OpenApiWordService; +import com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +/** + * @Author XiuYin.Cui + * @Date 2018/1/12 + **/ +@SuppressWarnings({"unchecked", "rawtypes"}) +@Service +public class OpenApiWordServiceImpl implements OpenApiWordService { + + @Autowired + private RestTemplate restTemplate; + + @Override + public Map<String, Object> tableList(String swaggerUrl) { + Map<String, Object> resultMap = new HashMap<>(); + try { + String jsonStr = restTemplate.getForObject(swaggerUrl, String.class); + resultMap = tableListFromString(jsonStr); + // log.debug(JsonUtils.writeJsonStr(resultMap)); + } catch (Exception e) { + } + return resultMap; + } + + @Override + public Map<String, Object> tableListFromString(String jsonStr) throws IOException { + Map<String, Object> resultMap = new HashMap<>(); + List<Table> result = new ArrayList<>(); + try { + Map<String, Object> map = getResultFromString(result, jsonStr); + Map<String, List<Table>> tableMap = result.stream().parallel().collect(Collectors.groupingBy(Table::getTitle)); + resultMap.put("tableMap", new TreeMap<>(tableMap)); + resultMap.put("info", map.get("info")); + + // log.debug(JsonUtils.writeJsonStr(resultMap)); + } catch (Exception e) { + throw e; + } + return resultMap; + } + + @Override + public Map<String, Object> tableList(MultipartFile jsonFile) throws IOException { + Map<String, Object> resultMap = new HashMap<>(); + try { + String jsonStr = new String(jsonFile.getBytes()); + resultMap = tableListFromString(jsonStr); + // log.debug(JsonUtils.writeJsonStr(resultMap)); + } catch (Exception e) { + throw e; + } + return resultMap; + } + + private Map<String, Object> getResultFromString(List<Table> result, String jsonStr) throws IOException { + // convert JSON string to Map + Map<String, Object> map = JsonUtils.readValue(jsonStr, HashMap.class); + + //瑙f瀽model + Map<String, ModelAttr> definitinMap = parseComponents(map); + + //瑙f瀽paths + Map<String, Map<String, Object>> paths = (Map<String, Map<String, Object>>) map.get("paths"); + + //鑾峰彇鍏ㄥ眬璇锋眰鍙傛暟鏍煎紡浣滀负榛樿璇锋眰鍙傛暟鏍煎紡 + List<String> defaultConsumes = (List) map.get("consumes"); + + //鑾峰彇鍏ㄥ眬鍝嶅簲鍙傛暟鏍煎紡浣滀负榛樿鍝嶅簲鍙傛暟鏍煎紡 + List<String> defaultProduces = (List) map.get("produces"); + + if (paths != null) { + + Iterator<Entry<String, Map<String, Object>>> it = paths.entrySet().iterator(); + while (it.hasNext()) { + Entry<String, Map<String, Object>> path = it.next(); + + // 0. 鑾峰彇璇ヨ矾鐢变笅鎵�鏈夎姹傛柟寮忕殑鍏叡鍙傛暟 + Map<String, Object> methods = (Map<String, Object>) path.getValue(); + List<LinkedHashMap> commonParameters = (ArrayList) methods.get("parameters"); + + Iterator<Entry<String, Object>> it2 = path.getValue().entrySet().iterator(); + // 1.璇锋眰璺緞 + String url = path.getKey(); + String requestType = null; + while (it2.hasNext()) { + try { + Entry<String, Object> request = it2.next(); + + // 2.璇锋眰鏂瑰紡锛岀被浼间负 get,post,delete,put 杩欐牱 + requestType = request.getKey(); + + if ("parameters".equals(requestType)) { + continue; + } + + Map<String, Object> content = (Map<String, Object>) request.getValue(); + + // 4. 澶ф爣棰橈紙绫昏鏄庯級 + String title = String.valueOf(((List) content.get("tags")).get(0)); + + // 5.灏忔爣棰� 锛堟柟娉曡鏄庯級 + String tag = String.valueOf(content.get("summary")); + + // 6.鎺ュ彛鎻忚堪 + Object descObj = content.get("description"); + String description = descObj == null ? tag : descObj.toString(); + + // 7. 璇锋眰浣� + List<LinkedHashMap> parameters = (ArrayList) content.get("parameters"); + + if (!CollectionUtils.isEmpty(parameters)) { + if (commonParameters != null) { + parameters.addAll(commonParameters); + } + } else { + if (commonParameters != null) { + parameters = commonParameters; + } + } + + // 8.杩斿洖浣� + Map<String, Object> responses = (LinkedHashMap) content.get("responses"); + + // 9.璇锋眰鍙傛暟鏍煎紡锛岀被浼间簬 multipart/form-data + List<String> requestParamsFormates = getRequestParamsFormate(content); + String requestForm = StringUtils.join(requestParamsFormates, ","); + + // 鍙栧嚭鏉ョ姸鎬佹槸200鏃剁殑杩斿洖鍊� + Map<String, Object> obj = (Map<String, Object>) responses.get("200"); + Map<String, Object> requestBody = (Map<String, Object>) content.get("requestBody"); + + // 10.杩斿洖鍙傛暟鏍煎紡锛岀被浼间簬 application/json + List<String> responseParamsFormates = getResponseParamsFormate(obj); + String responseForm = StringUtils.join(responseParamsFormates, ","); + + //灏佽Table + Table table = new Table(); + + table.setTitle(title); + table.setUrl(url); + table.setTag(tag); + table.setDescription(description); + table.setRequestForm(requestForm); + table.setResponseForm(responseForm); + table.setRequestType(requestType); + table.setRequestList(processRequestList(parameters, requestBody, definitinMap)); + + table.setResponseList(processResponseCodeList(responses, definitinMap)); + if (obj != null && obj.get("content") != null) { + table.setModelAttr(processResponseModelAttrs(obj, definitinMap)); + } + + //绀轰緥 + table.setRequestParam(processRequestParam(table.getRequestList())); + table.setResponseParam(processResponseParam1(obj, definitinMap)); + + result.add(table); + } catch (Exception e) { + e.printStackTrace(); +// StringWriter sw = new StringWriter(); +// PrintWriter pw = new PrintWriter(sw); +// e.printStackTrace(pw); +// throw new JsonProcessingException(url + "鎺ュ彛鏍煎紡涓嶆纭�: " + requestType + "璇锋眰 " + e.getMessage()) {}; + } + } + } + } + return map; + } + + /** + * 璇锋眰鍙傛暟鏍煎紡锛� 绫讳技浜� multipart/form-data + */ + private List<String> getRequestParamsFormate(Map<String, Object> obj) { + Map<String, Object> requestBody = (LinkedHashMap) obj.get("requestBody"); + List<String> requestTypes = new ArrayList(); + if (requestBody != null) { + Map<String, Map> content = (LinkedHashMap) requestBody.get("content"); + Set keys = content.keySet(); + return new ArrayList<String>(keys); + } + return requestTypes; + } + + /** + * 杩斿洖鍙傛暟鏍煎紡锛岀被浼间簬 application/json + * @throws Exception + */ + private List<String> getResponseParamsFormate(Map<String, Object> responseObj) { + Map<String, Map> content = (LinkedHashMap) responseObj.get("content"); + List<String> responseTypes = new ArrayList(); + if (content != null) { + Set keys = content.keySet(); + return new ArrayList<String>(keys); + } + return responseTypes; + } + + /** + * 澶勭悊璇锋眰鍙傛暟鍒楄〃 + * + * @param parameters + * @param definitinMap + * @return + * @throws JsonProcessingException + */ + private List<Request> processRequestList(List<LinkedHashMap> parameters, Map<String, Object> requestBody, Map<String, ModelAttr> definitinMap) { + List<Request> requestList = new ArrayList<>(); + if (!CollectionUtils.isEmpty(parameters)) { + for (Map<String, Object> param : parameters) { + Object in = param.get("in"); + Request request = new Request(); + request.setName(String.valueOf(param.get("name"))); + + Map<String, String> schema1 = (Map) param.get("schema"); + + request.setType(schema1 == null ? " " : schema1.get("type").toString()); + // request.setType(param.get("type") == null ? "object" : param.get("type").toString()); + if (param.get("format") != null) { + request.setType(request.getType() + "(" + param.get("format") + ")"); + } + request.setParamType(String.valueOf(in)); + // 鑰冭檻瀵硅薄鍙傛暟绫诲瀷 + if (in != null && "body".equals(in)) { + Map<String, Object> schema = (Map) param.get("schema"); + Object ref = schema.get("$ref"); + // 鏁扮粍鎯呭喌鍙﹀澶勭悊 + if (schema.get("type") != null && "array".equals(schema.get("type"))) { + ref = ((Map) schema.get("items")).get("$ref"); + request.setType("array"); + } + if (ref != null) { + request.setType(request.getType() + ":" + ref.toString().replaceAll("#/definitions/", "")); + request.setModelAttr(definitinMap.get(ref)); + } + } + // 鏄惁蹇呭~ + request.setRequire(false); + if (param.get("required") != null) { + request.setRequire((Boolean) param.get("required")); + } + // 鍙傛暟璇存槑 + request.setRemark(String.valueOf(param.get("description"))); + requestList.add(request); + } + } + + if (requestBody != null) { + Map<String, Map> content = (LinkedHashMap) requestBody.get("content"); + +// try { +// RequestUtils.validateRequestKey(content); +// } catch(Exception e) { +// throw new JsonProcessingException("requestybody 瀛楁 " + e.getMessage()) {}; +// } + + Iterator<Entry<String, Map>> applications = content.entrySet().iterator(); + while (applications.hasNext()) { + Entry<String, Map> application = applications.next(); + + if (application.getValue() != null) { + Request request = new Request(); + + Map<String, Object> schema = (Map<String, Object>) application.getValue().get("schema"); + request.setName(" "); + request.setType(schema == null ? " " : (schema.get("type") == null ? " " : schema.get("type").toString())); + request.setParamType("body"); + + Object ref = schema.get("$ref"); + + if (schema.get("type") != null && "array".equals(schema.get("type"))) { + ref = ((Map) schema.get("items")).get("$ref"); + request.setType("array"); + } + if (ref != null) { + // request.setType(request.getType() + ":" + ref.toString().replaceAll("#/definitions/", "")); + request.setType("object"); + request.setModelAttr(definitinMap.get(ref)); + } + if (schema.get("properties") != null) { + ArrayList<String> requiredArr = new ArrayList<String>(); + if (schema.get("required") != null) { + requiredArr = (ArrayList<String>) schema.get("required"); + } + request.setModelAttr(getRequestSchemaModelAttr(schema, requiredArr)); + } + + // 鏄惁蹇呭~ + request.setRequire(true); + + // 鍙傛暟璇存槑 + requestList.add(request); + } + } + } + return requestList; + } + + + /** + * 澶勭悊杩斿洖鐮佸垪琛� + * + * @param responses 鍏ㄩ儴鐘舵�佺爜杩斿洖瀵硅薄 + * @return + */ + private List<Response> processResponseCodeList(Map<String, Object> responses, Map<String, ModelAttr> definitinMap ) { + List<Response> responseList = new ArrayList<>(); + Iterator<Entry<String, Object>> resIt = responses.entrySet().iterator(); + while (resIt.hasNext()) { + Entry<String, Object> entry = resIt.next(); + Response response = new Response(); + // 鐘舵�佺爜 200 201 401 403 404 杩欐牱 + response.setName(entry.getKey()); + LinkedHashMap<String, Object> statusCodeInfo = (LinkedHashMap) entry.getValue(); + response.setDescription(String.valueOf(statusCodeInfo.get("description"))); + + Map<String, Map> content = (Map) statusCodeInfo.get("content"); + + if (content != null) { +// try { +// ResponseUtils.validateResponseKey(content); +// } catch(Exception e) { +// throw new JsonProcessingException("response瀛楁 " + entry.getKey() + "瀛楁 " + e.getMessage()) {}; +// } + // responses鍐呭application澶氫釜閬嶅巻澶勭悊 + Iterator<Entry<String, Map>> applications = content.entrySet().iterator(); + + while (applications.hasNext()) { + Entry<String, Map> application = applications.next(); + + if (application.getValue() != null) { + Object schema = application.getValue().get("schema"); + if (schema != null) { + Object originalRef = ((LinkedHashMap) schema).get("originalRef"); + response.setRemark(originalRef == null ? "" : originalRef.toString()); + } + responseList.add(response); + } + } + } else { + String ref = String.valueOf(statusCodeInfo.get("$ref")); + + if (ref != "null" && ref != "") { + ModelAttr modelAttr = definitinMap.get(ref); + response.setDescription(modelAttr.getDescription()); + } + + responseList.add(response); + } + } + return responseList; + } + + /** + * 澶勭悊杩斿洖灞炴�у垪琛� + * + * @param responseObj + * @param definitinMap + * @return + */ + private ModelAttr processResponseModelAttrs(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) { + Map<String, Map> content = (Map) responseObj.get("content"); + //鍏朵粬绫诲瀷 + ModelAttr modelAttr = new ModelAttr(); + + Iterator<Entry<String, Map>> applications = content.entrySet().iterator(); + + while (applications.hasNext()) { + Entry<String, Map> application = applications.next(); + + if (application.getValue() != null) { + + Map<String, Object> schema = (Map<String, Object>) application.getValue().get("schema"); + String type = (String) schema.get("type"); + String ref = null; + //鏁扮粍 + if ("array".equals(type)) { + Map<String, Object> items = (Map<String, Object>) schema.get("items"); + if (items != null && items.get("$ref") != null) { + ref = (String) items.get("$ref"); + } + } + //瀵硅薄 + if (schema.get("$ref") != null) { + ref = (String) schema.get("$ref"); + } + + //鍏朵粬绫诲瀷 + modelAttr.setType(StringUtils.defaultIfBlank(type, StringUtils.EMPTY)); + + if (StringUtils.isNotBlank(ref) && definitinMap.get(ref) != null) { + modelAttr = definitinMap.get(ref); + } + + // 鏈娇鐢╮ef鏂瑰紡 浣跨敤properties鏂瑰紡 + if (schema.get("properties") != null) { + modelAttr = getSchemaModelAttr(schema); + } + } + } + return modelAttr; + } + + /** + * 瑙f瀽components + * + * @param map + * @return + */ + private Map<String, ModelAttr> parseComponents(Map<String, Object> map) { + Map<String, Object> definitions = (Map<String, Object>) map.get("components"); + Map<String, ModelAttr> definitinMap = new HashMap<>(256); + if (definitions != null) { + Iterator<String> modelNameIt = definitions.keySet().iterator(); + /** + "components": { + "requestBodies": {}, + "schemas": {} + } + */ + while (modelNameIt.hasNext()) { + String modeName = modelNameIt.next(); + /** + "schemas": { + "cat":{}, + "dog":{}, + } + */ + Map<String, Map<String, Object>> modeContent = (Map<String, Map<String, Object>>) definitions.get(modeName); + + if (modeContent != null) { + Iterator<String> modeContentIt = modeContent.keySet().iterator(); + + while (modeContentIt.hasNext()) { + String componentsGrandChildName = modeContentIt.next(); + + getAndPutModelAttr(modeContent, definitinMap, modeName, componentsGrandChildName); + } + } + } + } + return definitinMap; + } + + /** + * 閫掑綊鐢熸垚ModelAttr + * 瀵�$ref绫诲瀷璁剧疆鍏蜂綋灞炴�� + */ + private ModelAttr getAndPutModelAttr(Map<String, Map<String, Object>> swaggerMap, Map<String, ModelAttr> resMap, String parentName, String modeName) { + ModelAttr modeAttr; + if ((modeAttr = resMap.get("#/components/" + parentName + "/" + modeName)) == null) { + modeAttr = new ModelAttr(); + resMap.put("#/components/" + parentName + "/" + modeName, modeAttr); + } else if (resMap.get("#/components/" + parentName + "/" + modeName) != null) { + return resMap.get("#/components/" + parentName + "/" + modeName); + } + Map<String, Object> modeProperties = (Map<String, Object>) swaggerMap.get(modeName).get("properties"); + List<ModelAttr> attrList = new ArrayList<>(); + // 鑾峰彇required瀛楁锛岄亶鍘唒roperties娣诲姞鏄惁蹇呭~灞炴�� + ArrayList modeRequired = (ArrayList) swaggerMap.get(modeName).get("required"); + + if (modeProperties != null) { + Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator(); + + //瑙f瀽灞炴�� + while (mIt.hasNext()) { + Entry<String, Object> mEntry = mIt.next(); + Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue(); + ModelAttr child = new ModelAttr(); + child.setName(mEntry.getKey()); + child.setType((String) attrInfoMap.get("type")); + if (attrInfoMap.get("format") != null) { + child.setType(child.getType() + "(" + attrInfoMap.get("format") + ")"); + } + child.setType(StringUtils.defaultIfBlank(child.getType(), "object")); + + Object ref = attrInfoMap.get("$ref"); + Object items = attrInfoMap.get("items"); + if (ref != null || (items != null && (ref = ((Map) items).get("$ref")) != null)) { + String refName = ref.toString(); + //鎴彇 #/components/ 鍚庨潰鐨� + String clsName = refName.substring(21); + ModelAttr refModel = getAndPutModelAttr(swaggerMap, resMap, parentName, clsName); + if (refModel != null) { + child.setProperties(refModel.getProperties()); + } + child.setType(child.getType() + ":" + clsName); + } + child.setDescription((String) attrInfoMap.get("description")); + + child.setRequire(false); + if (modeRequired != null && modeRequired.contains(mEntry.getKey())) { + child.setRequire(true); + } + + attrList.add(child); + } + } + + Object title = swaggerMap.get(modeName).get("title"); + Object description = swaggerMap.get(modeName).get("description"); + modeAttr.setClassName(title == null ? "" : title.toString()); + modeAttr.setDescription(description == null ? "" : description.toString()); + modeAttr.setProperties(attrList); + return modeAttr; + } + + /** + * 閫掑綊鐢熸垚ModelAttr + * 澶勭悊schema瀵硅薄 + * 澶勭悊requestBody鐩存帴杩斿洖灞炴�у�兼儏鍐� + */ + private ModelAttr getRequestSchemaModelAttr(Map<String, Object> schemaMap, ArrayList requiredArr) { + ModelAttr modeAttr = new ModelAttr(); + Map<String, Object> modeProperties = (Map<String, Object>) schemaMap.get("properties"); + + if ("array".equals(schemaMap.get("type"))) { + Map items = (Map<String, Object>) schemaMap.get("items"); + + if (items != null) { + modeProperties = (Map<String, Object>) items.get("properties"); + } + } + + if (modeProperties == null) { + return null; + } + Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator(); + + List<ModelAttr> attrList = new ArrayList<>(); + //瑙f瀽灞炴�� + while (mIt.hasNext()) { + Entry<String, Object> mEntry = mIt.next(); + Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue(); + ModelAttr child = new ModelAttr(); + child.setName(mEntry.getKey()); + child.setType((String) attrInfoMap.get("type")); + if (attrInfoMap.get("format") != null) { + child.setType(child.getType() + "(" + attrInfoMap.get("format") + ")"); + } + child.setType(StringUtils.defaultIfBlank(child.getType(), "object")); + + Object properties = attrInfoMap.get("properties"); + Object ref = attrInfoMap.get("$ref"); + Object items = attrInfoMap.get("items"); + if (properties != null || (items != null)) { + ArrayList<String> childRequiredArr = new ArrayList<String>(); + if (attrInfoMap.get("required") != null) { + childRequiredArr = (ArrayList<String>) attrInfoMap.get("required"); + } + ModelAttr refModel = getRequestSchemaModelAttr(attrInfoMap, childRequiredArr); + if (refModel != null) { + child.setProperties(refModel.getProperties()); + } + child.setType((String) attrInfoMap.get("type")); + } + child.setRequire(true); + if (!requiredArr.contains(mEntry.getKey())) { + child.setRequire(false); + } + child.setDescription((String) attrInfoMap.get("description")); + attrList.add(child); + } + modeAttr.setClassName(""); + modeAttr.setDescription(""); + modeAttr.setProperties(attrList); + return modeAttr; + } + + /** + * 閫掑綊鐢熸垚ModelAttr + * 澶勭悊schema瀵硅薄 + * 澶勭悊responseData鐩存帴杩斿洖灞炴�у�兼儏鍐� + */ + private ModelAttr getSchemaModelAttr(Map<String, Object> schemaMap) { + ModelAttr modeAttr = new ModelAttr(); + Map<String, Object> modeProperties = (Map<String, Object>) schemaMap.get("properties"); + + if ("array".equals(schemaMap.get("type"))) { + Map items = (Map<String, Object>) schemaMap.get("items"); + + if (items != null) { + modeProperties = (Map<String, Object>) items.get("properties"); + } + } + + if (modeProperties == null) { + return null; + } + Iterator<Entry<String, Object>> mIt = modeProperties.entrySet().iterator(); + + List<ModelAttr> attrList = new ArrayList<>(); + //瑙f瀽灞炴�� + while (mIt.hasNext()) { + Entry<String, Object> mEntry = mIt.next(); + Map<String, Object> attrInfoMap = (Map<String, Object>) mEntry.getValue(); + ModelAttr child = new ModelAttr(); + child.setName(mEntry.getKey()); + + child.setType((String) attrInfoMap.get("type")); + if (attrInfoMap.get("format") != null) { + child.setType(child.getType() + "(" + attrInfoMap.get("format") + ")"); + } + child.setType(StringUtils.defaultIfBlank(child.getType(), "object")); + + Object properties = attrInfoMap.get("properties"); + Object ref = attrInfoMap.get("$ref"); + Object items = attrInfoMap.get("items"); + if (properties != null || (items != null)) { + ModelAttr refModel = getSchemaModelAttr(attrInfoMap); + if (refModel != null) { + child.setProperties(refModel.getProperties()); + } + child.setType((String) attrInfoMap.get("type")); + } + child.setDescription((String) attrInfoMap.get("description")); + attrList.add(child); + } + modeAttr.setClassName(""); + modeAttr.setDescription(""); + modeAttr.setProperties(attrList); + return modeAttr; + } + + /** + * 澶勭悊杩斿洖鍊� + * + * @param responseObj + * @return + */ + private String processResponseParam(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) throws JsonProcessingException { + Map<String, Map> content = (Map) responseObj.get("content"); + if (content != null) { + Iterator<Entry<String, Map>> applications = content.entrySet().iterator(); + while (applications.hasNext()) { + Entry<String, Map> application = applications.next(); + + if (application.getValue() != null) { + Map<String, Object> applicationContent = (Map<String, Object>) application.getValue(); + if (applicationContent != null) { + Map<String, Object> schema = (Map<String, Object>) applicationContent.get("schema"); + String type = (String) schema.get("type"); + String ref = null; + // 鏁扮粍 + if ("array".equals(type)) { + Map<String, Object> items = (Map<String, Object>) schema.get("items"); + if (items != null && items.get("$ref") != null) { + ref = (String) items.get("$ref"); + } + } + // 瀵硅薄ref + if (schema.get("$ref") != null) { + ref = (String) schema.get("$ref"); + } + if (StringUtils.isNotEmpty(ref)) { + ModelAttr modelAttr = definitinMap.get(ref); + if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) { + Map<String, Object> responseMap = new HashMap<>(8); + for (ModelAttr subModelAttr : modelAttr.getProperties()) { + responseMap.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr)); + } + return JsonUtils.writeJsonStr(responseMap); + } + } + if (schema.get("properties") != null) { + ModelAttr modelAttr = getSchemaModelAttr(schema); + if (modelAttr != null) { + Map<String, Object> responseMap = new HashMap<>(8); + for (ModelAttr subModelAttr : modelAttr.getProperties()) { + responseMap.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr)); + } + return JsonUtils.writeJsonStr(responseMap); + } + } + } + } + } + } + return StringUtils.EMPTY; + } + + private String processResponseParam1(Map<String, Object> responseObj, Map<String, ModelAttr> definitinMap) { + Map<String, Map> content = (Map) responseObj.get("content"); + // if (responseObj != null && content.get("application/json") != null) { + if (content != null) { + Iterator<Entry<String, Map>> applications = content.entrySet().iterator(); + while (applications.hasNext()) { + Entry<String, Map> application = applications.next(); + + if (application.getValue() != null) { + Map<String, Map<String, Map>> applicationContent = (Map<String, Map<String, Map>>) application.getValue(); + if (applicationContent != null) { + Map<String, Map> examples = (Map<String, Map>) applicationContent.get("examples"); + + if (examples != null) { + Map<String, Object> responseData = examples.get("response"); + + if (responseData != null) { + Object value = responseData.get("value"); + try { + return JsonUtils.writeJsonStr(value); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + } else { + return ""; + } + + } + } + } + } + return StringUtils.EMPTY; + } + + /** + * 灏佽璇锋眰浣� + * + * @param list + * @return + */ + private String processRequestParam(List<Request> list) { + Map<String, Object> headerMap = new LinkedHashMap<>(); + Map<String, Object> queryMap = new LinkedHashMap<>(); + Map<String, Object> jsonMap = new LinkedHashMap<>(); + if (list != null && list.size() > 0) { + for (Request request : list) { + String name = request.getName(); + String paramType = request.getParamType(); + Object value = getValue(request.getType(), request.getModelAttr()); + switch (paramType) { + case "header": + headerMap.put(name, value); + break; + case "query": + queryMap.put(name, value); + break; + case "path": + queryMap.put(name, value); + break; + case "body": + //TODO 鏍规嵁content-type搴忓垪鍖栨垚涓嶅悓鏍煎紡锛岀洰鍓嶅彧鐢ㄤ簡json + jsonMap.put(name, value); + break; + default: + break; + + } + } + } + String res = ""; + if (!queryMap.isEmpty()) { + res += getUrlParamsByMap(queryMap); + } + if (!headerMap.isEmpty()) { + res += " " + getHeaderByMap(headerMap); + } + if (!jsonMap.isEmpty()) { + if (jsonMap.size() == 1) { + for (Entry<String, Object> entry : jsonMap.entrySet()) { + try { + res += " '" + JsonUtils.writeJsonStr(entry.getValue()) + "'"; + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + } else { + try { + res += " '" + JsonUtils.writeJsonStr(jsonMap) + "'"; + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + } + } + return res; + } + + /** + * 渚嬪瓙涓紝瀛楁鐨勯粯璁ゅ�� + * + * @param type 绫诲瀷 + * @param modelAttr 寮曠敤鐨勭被鍨� + * @return + */ + private Object getValue(String type, ModelAttr modelAttr) { + int pos; + if ((pos = type.indexOf(":")) != -1) { + type = type.substring(0, pos); + } + switch (type) { + case "string": + return "string"; + case "string(date-time)": + return "2020/01/01 00:00:00"; + case "integer": + case "integer(int64)": + case "integer(int32)": + return 0; + case "number": + return 0.0; + case "boolean": + return true; + case "file": + return "(binary)"; + case "array": + List list = new ArrayList(); + Map<String, Object> map = new LinkedHashMap<>(); + if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) { + for (ModelAttr subModelAttr : modelAttr.getProperties()) { + map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr)); + } + } + list.add(map); + return list; + case "object": + map = new LinkedHashMap<>(); + if (modelAttr != null && !CollectionUtils.isEmpty(modelAttr.getProperties())) { + for (ModelAttr subModelAttr : modelAttr.getProperties()) { + map.put(subModelAttr.getName(), getValue(subModelAttr.getType(), subModelAttr)); + } + } + return map; + default: + return null; + } + } + + /** + * 灏唌ap杞崲鎴恥rl + */ + public static String getUrlParamsByMap(Map<String, Object> map) { + if (map == null || map.isEmpty()) { + return ""; + } + StringBuffer sb = new StringBuffer(); + for (Entry<String, Object> entry : map.entrySet()) { + sb.append(entry.getKey() + "=" + entry.getValue()); + sb.append("&"); + } + String s = sb.toString(); + if (s.endsWith("&")) { + s = StringUtils.substringBeforeLast(s, "&"); + } + return s; + } + + /** + * 灏唌ap杞崲鎴恏eader + */ + public static String getHeaderByMap(Map<String, Object> map) { + if (map == null || map.isEmpty()) { + return ""; + } + StringBuffer sb = new StringBuffer(); + for (Entry<String, Object> entry : map.entrySet()) { + sb.append("--header '"); + sb.append(entry.getKey() + ":" + entry.getValue()); + sb.append("'"); + } + return sb.toString(); + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt index 492dbbe..c26f05b 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ScenseServiceImpl.kt @@ -329,6 +329,7 @@ when (typeId.toString()) { Constant.SceneType.TYPE1.value -> { val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneConstructionSite::class.java) + subScene.csUpdateTime = Date() if (subScene.getsGuid() != null) { val record = sceneConstructionSiteMapper.selectByPrimaryKey(subScene.getsGuid()) isUpdate = record != null @@ -411,17 +412,22 @@ return locationRoadNearby.searchByRadius(Pair(lng, lat), radius) } - override fun importSceneInfo(file: MultipartFile): Boolean { - val f = ByteArrayInputStream(file.bytes) + override fun importSceneInfo(files: Array<MultipartFile>): Boolean { + if (files.isEmpty()) throw BizException("鏈纭笂浼犳枃浠讹紝鎺ュ彛璋冪敤閿欒") + + val f = ByteArrayInputStream(files[0].bytes) val scenes = sceneImport.readFromFile(f) + if (scenes.isEmpty()) throw BizException("鏂囦欢鍐呭涓虹┖") // 鏌ユ壘鍦烘櫙鍚嶇О鏄惁閲嶅 - val names = scenes.map { it.name } + val names = scenes.map { it.scense?.name } sceneRep.findSceneList(names).map { it?.name }.ifNotEmpty { val str = this.joinToString("锛�") throw BizException("瀛樺湪閲嶅鍦烘櫙锛屽涓嬶細${str}") } scenes.forEach { - createOneScene(it) + it.scense ?: return@forEach + createOneScene(it.scense!!) + sceneRep.insertOrUpdateSubScene(it.scense!!.typeid?.toInt(), it.scense!!.guid, it.subScene) } return true } diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt index b0f1806..cd80b71 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/BaseResponse.kt @@ -12,13 +12,14 @@ @JsonInclude(JsonInclude.Include.NON_NULL) @ApiModel("璇锋眰杩斿洖鍩烘湰缁撴瀯") data class BaseResponse<T>( - @ApiModelProperty("璇锋眰鏄惁鎴愬姛") - var success: Boolean, - @ApiModelProperty("璇锋眰杩斿洖娑堟伅") - var message: String = "", - val head: DataHead? = null, - @ApiModelProperty("璇锋眰杩斿洖鏁版嵁") - val data: T? = null, + @ApiModelProperty("璇锋眰鏄惁鎴愬姛") + var success: Boolean, + @ApiModelProperty("璇锋眰杩斿洖娑堟伅") + var message: String = "", + val head: DataHead? = null, + @ApiModelProperty("璇锋眰杩斿洖鏁版嵁") + val data: T? = null, + var stackTrace: String = "" ) { init { if (message.isBlank()) { diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt index 17d155e..08d072d 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt @@ -21,10 +21,10 @@ BaseResponse(true, data = res) } } catch (e: BizException) { - BaseResponse(false, message = e.message ?: "") + BaseResponse(false, message = e.message ?: "", stackTrace = e.stackTraceToString()) } catch (e: Exception) { // fixme: to log system - BaseResponse(false, message = "鏈嶅姟鍣ㄥ嚭鐜板唴閮ㄩ敊璇�") + BaseResponse(false, message = "鏈嶅姟鍣ㄥ嚭鐜板唴閮ㄩ敊璇�", stackTrace = e.stackTraceToString()) } } \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/DeviceController.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/DeviceController.kt index 96e94e5..774113b 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/DeviceController.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/DeviceController.kt @@ -19,7 +19,7 @@ @GetMapping fun fetchDevice( @ApiParam("鍦烘櫙id") @RequestParam sceneId: String, - @ApiParam("璁惧绫诲瀷id", allowableValues = "0,1,2") @RequestParam deviceTypeId: Byte, + @ApiParam("璁惧绫诲瀷id") @RequestParam deviceTypeId: Byte, ) = resPack { deviceService.findDevices(sceneId, Constant.DeviceType.fromValue(deviceTypeId)) } @ApiOperation("鏂板鍦烘櫙璁惧淇℃伅") diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/OpenApiWordController.java b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/OpenApiWordController.java new file mode 100644 index 0000000..8e56a1e --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/OpenApiWordController.java @@ -0,0 +1,105 @@ +package cn.flightfeather.supervision.lightshare.web; + +import cn.flightfeather.supervision.lightshare.service.OpenApiWordService; +import io.swagger.annotations.*; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RequestPart; +import org.springframework.web.multipart.MultipartFile; +import org.thymeleaf.context.Context; +import org.thymeleaf.spring5.SpringTemplateEngine; + +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.Map; + +@Controller +@Api(tags = "OpenAPI") +public class OpenApiWordController { + + @Value("${swagger.url}") + private String swaggerUrl; + + @Autowired + private OpenApiWordService openApiWordService; + @Autowired + private SpringTemplateEngine springTemplateEngine; + + private String fileName; + + /** + * 灏� swagger json鏂囦欢杞崲鎴� word鏂囨。骞朵笅杞� + * + * @param model + * @param jsonFile 闇�瑕佽浆鎹㈡垚 word 鏂囨。鐨剆wagger json鏂囦欢 + * @param response + * @return + * @throws Exception + */ + @ApiOperation(value = "灏� swagger json鏂囦欢杞崲鎴� word鏂囨。骞朵笅杞�", notes = "") + @ApiResponses(value = {@ApiResponse(code = 200, message = "璇锋眰鎴愬姛銆�")}) + @RequestMapping(value = "/OpenApiFileToWord", method = {RequestMethod.POST}) + public void getWord(Model model, @ApiParam("swagger json file") @RequestPart("jsonFile") MultipartFile jsonFile, HttpServletResponse response) throws Exception { + generateModelData(model, jsonFile); + writeContentToResponse(model, response); + } + + @ApiOperation(value = "灏� swagger json鏂囦欢杞崲鎴� word鏂囨。骞朵笅杞�", notes = "") + @ApiResponses(value = {@ApiResponse(code = 200, message = "璇锋眰鎴愬姛銆�")}) + @RequestMapping(value = "/OpenApiFileToWord2", method = {RequestMethod.POST}) + public void getWord2( + Model model, + @ApiParam("swagger json url") @RequestParam("url") String url, + HttpServletResponse response + ) throws Exception { + generateModelData(model, url); + writeContentToResponse(model, response); + } + + private void generateModelData(Model model, MultipartFile jsonFile) throws IOException { + Map<String, Object> result = openApiWordService.tableList(jsonFile); + fileName = jsonFile.getOriginalFilename(); + + if (fileName != null) { + fileName = fileName.replaceAll(".json", ""); + } else { + fileName = "toWord"; + } + + model.addAttribute("url", "http://"); + model.addAttribute("download", 0); + model.addAllAttributes(result); + } + + private void generateModelData(Model model, String url) { + url = StringUtils.defaultIfBlank(url, swaggerUrl); + Map<String, Object> result = openApiWordService.tableList(url); + model.addAttribute("url", url); + model.addAttribute("download", 0); + model.addAllAttributes(result); + } + + private void writeContentToResponse(Model model, HttpServletResponse response) { + Context context = new Context(); + context.setVariables(model.asMap()); + String content = springTemplateEngine.process("word", context); + response.setContentType("application/octet-stream;charset=utf-8"); + response.setCharacterEncoding("utf-8"); + try (BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream())) { + response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName + ".doc", "utf-8")); + byte[] bytes = content.getBytes(); + bos.write(bytes, 0, bytes.length); + bos.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ProblemlistController.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ProblemlistController.kt index 7b4c214..dac5f41 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ProblemlistController.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ProblemlistController.kt @@ -88,8 +88,7 @@ @PostMapping("/check") fun checkProblem( @ApiParam(value = "闂id涓婚敭") @RequestParam("pId") pId: String, - @ApiParam(value = "瀹℃牳鎿嶄綔, 0: 瀹℃牳閫氳繃锛�1: 瀹℃牳涓嶉�氳繃锛�2: 鏁存敼閫氳繃锛�3: 鏁存敼涓嶉�氳繃锛�4锛氶棶棰樺鏍告挙鍥烇紱5锛氭暣鏀瑰鏍告挙鍥�", - allowableValues = "0,1,2,3,4,5") @RequestParam("action") action: Byte, + @ApiParam(value = "瀹℃牳鎿嶄綔, 0: 瀹℃牳閫氳繃锛�1: 瀹℃牳涓嶉�氳繃锛�2: 鏁存敼閫氳繃锛�3: 鏁存敼涓嶉�氳繃锛�4锛氶棶棰樺鏍告挙鍥烇紱5锛氭暣鏀瑰鏍告挙鍥�") @RequestParam("action") action: Byte, @ApiParam(value = "瀹℃牳澶囨敞") @RequestParam("remark") remark: String, @ApiParam(value = "鐢ㄦ埛id") @RequestParam("userId") userId: String, @ApiParam(value = "鐢ㄦ埛鍚�") @RequestParam("userName") userName: String, diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ScenseController.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ScenseController.kt index 90d5434..2e2d523 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ScenseController.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/ScenseController.kt @@ -93,8 +93,8 @@ @ApiOperation(value = "閫氳繃鏂囦欢瀵煎叆鍦烘櫙淇℃伅") @PostMapping("/import") fun importSceneInfo( - @RequestPart("file") file: MultipartFile, - ) = resPack { scenseService.importSceneInfo(file) } + @RequestPart("file") files: Array<MultipartFile>, + ) = resPack { scenseService.importSceneInfo(files) } @ApiOperation(value = "鍒涘缓鍦烘櫙淇℃伅") @PutMapping("/create") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 13d7197..aad502d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -97,3 +97,4 @@ v2: enabled: false +swagger.url: http://localhost:8080/v3/api-docs \ No newline at end of file diff --git a/src/main/resources/mapper/ds1/SceneConstructionSiteMapper.xml b/src/main/resources/mapper/ds1/SceneConstructionSiteMapper.xml index dcd1585..4afeb22 100644 --- a/src/main/resources/mapper/ds1/SceneConstructionSiteMapper.xml +++ b/src/main/resources/mapper/ds1/SceneConstructionSiteMapper.xml @@ -22,6 +22,7 @@ <result column="CS_Construction_Contacts_Tel" property="csConstructionContactsTel" jdbcType="VARCHAR" /> <result column="CS_Security_Officer" property="csSecurityOfficer" jdbcType="VARCHAR" /> <result column="CS_Security_Officer_Tel" property="csSecurityOfficerTel" jdbcType="VARCHAR" /> + <result column="CS_Update_Time" property="csUpdateTime" jdbcType="TIMESTAMP" /> <result column="SI_Extension1" property="siExtension1" jdbcType="VARCHAR" /> <result column="SI_Extension2" property="siExtension2" jdbcType="VARCHAR" /> <result column="SI_Extension3" property="siExtension3" jdbcType="VARCHAR" /> diff --git a/src/main/resources/templates/word.html b/src/main/resources/templates/word.html new file mode 100644 index 0000000..0fd7619 --- /dev/null +++ b/src/main/resources/templates/word.html @@ -0,0 +1,212 @@ +<!DOCTYPE html> +<html xmlns:th="http://www.thymeleaf.org"> +<head> + <meta http-equiv="Content-Type" content="application/msword; charset=utf-8"/> + <title>toWord</title> + <style type="text/css"> + .bg { + font-size: 14.5px; + font-weight: bold; + color: #000; + background-color: #D7D7D7; + } + + table { + border-width: 1px; + border-style: solid; + border-color: black; + table-layout: fixed; + } + + tr { + height: 32px; + font-size: 12px; + } + + td { + padding-left: 10px; + border-width: 1px; + border-style: solid; + border-color: black; + height: 32px; + overflow: hidden; + word-break: break-all; + word-wrap: break-word; + font-size: 14.5px; + } + + .bg td { + font-size: 14.5px; + } + + tr td { + font-size: 14.5px; + } + + .specialHeight { + height: 40px; + } + + .first_title { + height: 60px; + line-height: 60px; + margin: 0; + font-weight: bold; + font-size: 21px; + } + + .second_title { + height: 40px; + line-height: 40px; + margin: 0; + font-size: 18.5px; + } + + .doc_title { + font-size: 42.5px; + text-align: center; + } + + .download_btn { + float: right; + } + + body { + font-family: 鎬濇簮榛戜綋 Normal; + } + </style> +</head> + +<body> +<div style="width:800px; margin: 0 auto"> + <div> + <p class="doc_title" th:text="${info.title +'锛�'+ info.version +'锛�'}"></p> + <a class="download_btn" th:if="${download == 1}" th:href="${'/downloadWord?url='+ url}">涓嬭浇鏂囨。</a> + <br> + </div> + <div th:each="tableMap, tableMapStat:${tableMap}" style="margin-bottom:20px;"> + <!--杩欎釜鏄被鐨勮鏄�--> + <h4 class="first_title" th:text="${tableMapStat.count} + '. ' + ${tableMap.key}"></h4> + <div th:each="table,tableStat:${tableMap.value}"> + + <!--杩欎釜鏄瘡涓姹傜殑璇存槑锛屾柟渚跨敓鎴愭枃妗e悗杩涜鏁寸悊--> + <h5 class="second_title" th:text="${tableStat.count} + '锛�' + ${table.tag}"></h5> + + <table border="1" cellspacing="0" cellpadding="0" width="100%"> + <tr class="bg"> + <td colspan="5" th:text="${table.tag}"></td> + </tr> + <tr> + <td width="25%">鎺ュ彛鎻忚堪</td> + <td colspan="4" th:text="${table.description}"></td> + </tr> + <tr> + <td>URL</td> + <td colspan="4" th:text="${table.url}"></td> + </tr> + <tr> + <td>璇锋眰鏂瑰紡</td> + <td colspan="4" th:text="${#strings.toUpperCase(table.requestType)}"></td> + </tr> + <tr> + <td>璇锋眰绫诲瀷</td> + <td colspan="4" th:text="${table.requestForm}"></td> + </tr> + <tr> + <td>杩斿洖绫诲瀷</td> + <td colspan="4" th:text="${table.responseForm}"></td> + </tr> + + <tr class="bg"> + <td>鍙傛暟鍚�</td> + <td width="15%">鏁版嵁绫诲瀷</td> + <td width="15%">鍙傛暟绫诲瀷</td> + <td width="15%">鏄惁蹇呭~</td> + <td width="29%">璇存槑</td> + </tr> + + <th:block th:each="request, c:${table.requestList}"> + <tr> + <td align="left" th:text="${c.count} + '.' + ${request.name}"></td> + <td th:text="${request.type}"></td> + <td th:text="${request.paramType}"></td> + <td th:if="${request.require}" th:text="Y"></td> + <td th:if="${!request.require}" th:text="N"></td> + <td th:text="${request.remark}"></td> + <!-- <td th:if="${request.modelAttr}" th:text="asdfagadfg"></td>--> + </tr> + <th:block th:if="${request.modelAttr}"> + <tbody th:include="this::request(${request.modelAttr.properties},${c.count} + '.', 1)"/> + </th:block> + + + </th:block> + + <tr class="bg"> + <td>鐘舵�佺爜</td> + <td colspan="2">鎻忚堪</td> + <td colspan="2">璇存槑</td> + </tr> + + <tr th:each="response:${table.responseList}"> + <td th:text="${response.name}"></td> + <td colspan="2" th:text="${response.description}"></td> + <td colspan="2" th:text="${response.remark}"></td> + </tr> + + <tr class="bg"> + <td>杩斿洖灞炴�у悕</td> + <td colspan="2">绫诲瀷</td> + <td colspan="2">璇存槑</td> + </tr> + + <!-- 瀵硅繑鍥炲弬鏁� 閫掑綊鐢熸垚琛�--> + <tbody th:include="this::response(${table.modelAttr.properties},'', 1)"/> + +<!-- <tr class="bg">--> +<!-- <td colspan="5">绀轰緥</td>--> +<!-- </tr>--> +<!-- <tr class="specialHeight">--> +<!-- <td class="bg">璇锋眰鍙傛暟</td>--> +<!-- <td colspan="4" th:text="${table.requestParam}"></td>--> +<!-- </tr>--> +<!-- <tr class="specialHeight">--> +<!-- <td class="bg">杩斿洖鍊�</td>--> +<!-- <td colspan="4" th:text="${table.responseParam}"></td>--> +<!-- </tr>--> + + </table> + </div> + </div> +</div> + +<th:block th:fragment="request(properties,count, lv)"> + <th:block th:each="p,c : ${properties}"> + <tr> + <td align="left" th:text="${count} + '' + ${c.count} + '.' + ${p.name}" + th:style="|padding-left:${10*lv}px|"></td> + <td th:text="${p.type}"></td> + <td></td> + <td th:if="${p.require}" th:text="Y"></td> + <td th:if="${!p.require}" th:text="N"></td> + <td th:text="${p.description}"></td> + </tr> + <th:block th:unless="${#lists.isEmpty(p.properties)}" + th:include="this::request(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})"/> + </th:block> +</th:block> + +<th:block th:fragment="response(properties,count, lv)"> + <th:block th:each="p,c : ${properties}"> + <tr> + <td align="left" th:text="${count} + '' + ${c.count} + '.' + ${p.name}" + th:style="|padding-left:${10*lv}px|"></td> + <td colspan="2" th:text="${p.type}"></td> + <td colspan="2" th:text="${p.description}"></td> + </tr> + <th:block th:unless="${#lists.isEmpty(p.properties)}" + th:include="this::response(${p.properties},${count} + '' + ${c.count} + '.',${lv+1})"/> + </th:block> +</th:block> +</body> +</html> diff --git a/src/test/kotlin/cn/flightfeather/supervision/business/autooutput/AopEvaluationTest.kt b/src/test/kotlin/cn/flightfeather/supervision/business/autooutput/AopEvaluationTest.kt index 852f32f..0aa07ff 100644 --- a/src/test/kotlin/cn/flightfeather/supervision/business/autooutput/AopEvaluationTest.kt +++ b/src/test/kotlin/cn/flightfeather/supervision/business/autooutput/AopEvaluationTest.kt @@ -9,6 +9,8 @@ import cn.flightfeather.supervision.business.autooutput.datasource.AopDataConfig import cn.flightfeather.supervision.business.autooutput.score.AopCreditCode import cn.flightfeather.supervision.common.utils.Constant +import cn.flightfeather.supervision.domain.ds1.entity.Evaluationrule +import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationruleMapper import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep import cn.flightfeather.supervision.lightshare.service.SearchService import cn.flightfeather.supervision.lightshare.vo.ExcelConfigVo @@ -19,6 +21,7 @@ import org.springframework.boot.test.context.SpringBootTest import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.context.junit4.SpringRunner +import tk.mybatis.mapper.entity.Example @RunWith(SpringRunner::class) @ExtendWith(SpringExtension::class) @@ -51,6 +54,9 @@ @Autowired lateinit var subTaskRep: SubTaskRep + + @Autowired + lateinit var evaluationruleMapper: EvaluationruleMapper /** * 闈欏畨宸ュ湴鑷瘎 @@ -147,4 +153,22 @@ val s = subTaskRep.findOne("B6kyaAjJRoGJ2Yur") aopEvaluation.executeBySubTask(s!!) } + + @Test + fun test3() { + val result = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply { + createCriteria() + .andEqualTo("tasktypeid", 99) + .andEqualTo("scensetypeid", 1) + and(createCriteria().orEqualTo("provincecode", "31").orIsNull("provincecode")) + and(createCriteria().orEqualTo("citycode", "3100").orIsNull("citycode")) + and(createCriteria().orEqualTo("districtcode", "310104").orIsNull("districtcode")) + and(createCriteria().orEqualTo("towncode", "310104014").orIsNull("towncode")) + orderBy("towncode").desc() + .orderBy("districtcode").desc() + .orderBy("citycode").desc() + .orderBy("provincecode").desc() + }) + println(result.map { it.rulename }) + } } \ No newline at end of file -- Gitblit v1.9.3