feiyu02
2025-03-28 7d74f3fd087d4a8192ed556a6c2e3a2ea3c81cff
1. 新增扬尘监测数据上传功能
已修改10个文件
已添加5个文件
292 ■■■■■ 文件已修改
src/main/kotlin/cn/flightfeather/supervision/business/autooutput/AopOutput.kt 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/common/utils/Constant.kt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/domain/ds1/mapper/DustDataResultMapper.kt 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/MonitorDataRep.kt 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/DomaincatalogService.kt 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/MonitorDataService.kt 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemtypeService.kt 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DomaincatalogServiceImpl.kt 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MonitorDataServiceImpl.kt 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemtypeServiceImpl.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/lightshare/web/MonitorDataController.kt 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ds1/DustDataResultMapper.xml 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ds1/ScenseMapper.xml 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DomaincatalogServiceImplTest.kt 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/kotlin/cn/flightfeather/supervision/business/autooutput/AopOutput.kt
@@ -8,6 +8,7 @@
import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationMapper
import cn.flightfeather.supervision.domain.ds1.mapper.ItemevaluationMapper
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
/**
@@ -23,6 +24,7 @@
    /**
     * å°†è¯„分记录输出至数据库
     */
    @Transactional
    fun toDbEvaluation(evaluationScene: AopDataSource.EvaluationScene, p: Pair<Evaluation, List<Itemevaluation>>) {
        //去除已有记录
        evaluationMapper.deleteByExample(Example(Evaluation::class.java).apply {
@@ -40,6 +42,7 @@
    /**
     * å°†è¯„分记录更新至数据库
     */
    @Transactional
    fun updateDbEvaluation(evaluationScene: AopDataSource.EvaluationScene, p: Pair<Evaluation, List<Itemevaluation>>) {
        evaluationMapper.updateByPrimaryKey(p.first)
        p.second.forEach { il -> itemevaluationMapper.updateByPrimaryKey(il) }
src/main/kotlin/cn/flightfeather/supervision/common/utils/Constant.kt
@@ -39,6 +39,7 @@
        TYPE9("9","道路扬尘监测点"), TYPE10("10","道路"),
        TYPE11("11","河流断面"), TYPE12("12","工业园区"),
        TYPE13("13","无固定场景"),TYPE14("14","堆场"),
        TYPE15("15","精品小区"),
        TYPE99("99","其他");
        companion object {
src/main/kotlin/cn/flightfeather/supervision/domain/ds1/mapper/DustDataResultMapper.kt
@@ -2,7 +2,11 @@
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.domain.util.MyMapper
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.apache.ibatis.annotations.Mapper
@Mapper
interface DustDataResultMapper : MyMapper<DustDataResult?>
interface DustDataResultMapper : MyMapper<DustDataResult?> {
    fun selectByArea(areaVo: AreaVo): List<DustDataResult?>
}
src/main/kotlin/cn/flightfeather/supervision/domain/ds1/repository/MonitorDataRep.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,24 @@
package cn.flightfeather.supervision.domain.ds1.repository
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.domain.ds1.mapper.DustDataResultMapper
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.springframework.stereotype.Repository
/**
 * ç›‘测数据数据库查询
 * @date 2025/3/19
 * @author feiyu02
 */
@Repository
class MonitorDataRep(
    private val dataResultMapper: DustDataResultMapper,
) {
    /**
     * æ ¹æ®è¡Œæ”¿åŒºåŸŸã€æ—¶é—´ã€ä»¥åŠåœºæ™¯ç±»åž‹æŸ¥è¯¢ç»“æžœ
     */
    fun fetchDustDataResult(areaVo: AreaVo): List<DustDataResult?> {
        return dataResultMapper.selectByArea(areaVo)
    }
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/DomaincatalogService.kt
@@ -1,6 +1,8 @@
package cn.flightfeather.supervision.lightshare.service
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.entity.Domaincatalog
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.DomaincatalogVo
@@ -16,4 +18,14 @@
    fun update(domaincatalog: Domaincatalog): Int
    fun delete(id: String): Int
    /**
     * å¿«æ·é…ç½®
     * é’ˆå¯¹ä¸€ç§æ–°çš„场景类型,进行快速配置
     */
    fun quickConfiguration(
        target: Constant.SceneType, targetArea: AreaVo, source: Constant.SceneType,
        sourceArea: AreaVo,
    ): Boolean
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/MonitorDataService.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,16 @@
package cn.flightfeather.supervision.lightshare.service
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.lightshare.vo.AreaVo
/**
 * ç›‘测数据(包含扬尘监测、油烟监测等等所有监测数据)服务
 * @date 2025/3/19
 * @author feiyu02
 */
interface MonitorDataService {
    fun uploadDustDataResult(dataList: List<DustDataResult>): Boolean
    fun fetchDustDataResult(areaVo: AreaVo): List<DustDataResult?>
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemtypeService.kt
@@ -1,5 +1,6 @@
package cn.flightfeather.supervision.lightshare.service
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.entity.Problemtype
import cn.flightfeather.supervision.lightshare.vo.ProblemDetailVo
import cn.flightfeather.supervision.lightshare.vo.ProblemtypeVo
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DomaincatalogServiceImpl.kt
@@ -1,14 +1,26 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.domain.ds1.entity.Domaincatalog
import cn.flightfeather.supervision.domain.ds1.mapper.DomaincatalogMapper
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.common.utils.UUIDGenerator
import cn.flightfeather.supervision.domain.ds1.entity.*
import cn.flightfeather.supervision.domain.ds1.mapper.*
import cn.flightfeather.supervision.lightshare.service.DomaincatalogService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.DomaincatalogVo
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
import java.util.*
@Service
class DomaincatalogServiceImpl(val domaincatalogMapper: DomaincatalogMapper) : DomaincatalogService {
class DomaincatalogServiceImpl(
    private val domaincatalogMapper: DomaincatalogMapper,
    private val problemtypeMapper: ProblemtypeMapper,
    private val changeAdviceMapper: ChangeAdviceMapper,
    private val evaluationruleMapper: EvaluationruleMapper,
    private val evaluationsubruleMapper: EvaluationsubruleMapper,
) : DomaincatalogService {
    //根据name查询
    override fun findOneByName(name: String): Domaincatalog? {
        val domaincatalog = Domaincatalog()
@@ -35,4 +47,66 @@
    override fun update(domaincatalog: Domaincatalog): Int = domaincatalogMapper.updateByPrimaryKey(domaincatalog)
    override fun delete(id: String): Int = domaincatalogMapper.deleteByPrimaryKey(id)
    @Transactional
    override fun quickConfiguration(
        target: Constant.SceneType,
        targetArea: AreaVo,
        source: Constant.SceneType,
        sourceArea: AreaVo,
    ): Boolean {
        //1. é—®é¢˜ç±»åž‹å’Œæ•´æ”¹å»ºè®®
        val adviceList = changeAdviceMapper.selectByExample(Example(ChangeAdvice::class.java).apply {
            createCriteria().andEqualTo("adExtension1", sourceArea.districtname)
                .andEqualTo("adExtension2", source.text)
        })
        problemtypeMapper.selectByExample(Example(Problemtype::class.java).apply {
            createCriteria().andEqualTo("scensetypeid", source.value.toByte())
                .andEqualTo("districtname", sourceArea.districtname)
        }).forEach {
            val newProblemGuid = UUIDGenerator.generate16ShortUUID()
            adviceList.find { ad -> ad.adProblemtypeguid == it.guid }?.let { ad ->
                ad.adGuid = UUIDGenerator.generate16ShortUUID()
                ad.adProblemtypeguid = newProblemGuid
                ad.adCreatedate = Date()
                ad.adUpdatedate = Date()
                ad.adExtension1 = targetArea.districtname
                ad.adExtension2 = target.text
                changeAdviceMapper.insert(ad)
            }
            it.guid = newProblemGuid
            it.scensetypeid = target.value.toByte()
            it.scensetype = target.text
            it.createdate = Date()
            it.updatedate = Date()
            it.provincecode = targetArea.provincecode
            it.provincename = targetArea.provincename
            it.citycode = targetArea.citycode
            it.cityname = targetArea.cityname
            it.districtcode = targetArea.districtcode
            it.districtname = targetArea.districtname
            problemtypeMapper.insert(it)
        }
        return true
        //2. é—®é¢˜ä½ç½®ï¼ˆé»˜è®¤å·¥åœ°ï¼Œå¯ä¸ä¿®æ”¹ï¼‰
        //3. è‡ªè¯„规则表
//        evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
//            createCriteria().andEqualTo("tasktypeid", 99)
//                .andEqualTo("scensetypeid", source.value)
//            and(createCriteria().orEqualTo("provincecode", sourceArea.provincecode).orIsNull("provincecode"))
//            and(createCriteria().orEqualTo("citycode", sourceArea.citycode).orIsNull("citycode"))
//            and(createCriteria().orEqualTo("districtcode", sourceArea.districtcode).orIsNull("districtcode"))
//            and(createCriteria().orEqualTo("towncode", sourceArea.towncode).orIsNull("towncode"))
//        }).takeIf { it.isNotEmpty() }?.get(0).let {sourceRule ->
//            if (sourceRule != null) {
//                evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
//                    createCriteria().andEqualTo("", sourceRule)
//                })
//            }
//        }
    }
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/MonitorDataServiceImpl.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,31 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.business.autooutput.AopOutput
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.domain.ds1.repository.MonitorDataRep
import cn.flightfeather.supervision.lightshare.service.MonitorDataService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
/**
 *
 * @date 2025/3/19
 * @author feiyu02
 */
@Service
class MonitorDataServiceImpl(
    private val aopOutput: AopOutput,
    private val monitorDataRep: MonitorDataRep,
) : MonitorDataService {
    @Transactional
    override fun uploadDustDataResult(dataList: List<DustDataResult>): Boolean {
        dataList.forEach { aopOutput.toDbDataResult(it) }
        return true
    }
    override fun fetchDustDataResult(areaVo: AreaVo): List<DustDataResult?> {
        return monitorDataRep.fetchDustDataResult(areaVo)
    }
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemtypeServiceImpl.kt
@@ -1,5 +1,7 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.common.utils.UUIDGenerator
import cn.flightfeather.supervision.domain.ds1.entity.Problemtype
import cn.flightfeather.supervision.domain.ds1.mapper.ProblemtypeMapper
import cn.flightfeather.supervision.lightshare.service.ProblemtypeService
@@ -7,8 +9,10 @@
import cn.flightfeather.supervision.lightshare.vo.ProblemtypeVo
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
import tk.mybatis.mapper.util.StringUtil
import java.util.*
@Service
class ProblemtypeServiceImpl(val problemtypeMapper: ProblemtypeMapper) : ProblemtypeService {
src/main/kotlin/cn/flightfeather/supervision/lightshare/web/BaseResPack.kt
@@ -22,5 +22,9 @@
        }
    } catch (e: BizException) {
        BaseResponse(false, message = e.message ?: "")
    } catch (e: Exception) {
        // fixme: to log system
        BaseResponse(false, message = "服务器出现内部错误")
    }
}
src/main/kotlin/cn/flightfeather/supervision/lightshare/web/MonitorDataController.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,33 @@
package cn.flightfeather.supervision.lightshare.web
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.lightshare.service.MonitorDataService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiParam
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
/**
 * ç›‘测数据(包含扬尘监测、油烟监测等等所有监测数据)相关API接口
 * @date 2025/3/19
 * @author feiyu02
 */
@Api(tags = ["MonitorDataController"], description = "监测数据(包含扬尘监测、油烟监测等等所有监测数据)相关API接口")
@RestController
@RequestMapping("/monitor/data")
class MonitorDataController(private val monitorDataService: MonitorDataService) {
    @ApiOperation(value = "上传扬尘监测数据的月度统计结果")
    @PutMapping("/result/construction/upload")
    fun uploadDustDataResult(
        @ApiParam("统计结果") @RequestBody dataList: List<DustDataResult>,
    ) = resPack { monitorDataService.uploadDustDataResult(dataList) }
    @ApiOperation(value = "查询扬尘监测数据的月度统计结果")
    @PostMapping("/result/construction/get")
    fun fetchDustDataResult(
        @ApiParam("区域条件信息") @RequestBody areaVo: AreaVo
    ) = resPack { monitorDataService.fetchDustDataResult(areaVo) }
}
src/main/resources/mapper/ds1/DustDataResultMapper.xml
@@ -25,4 +25,33 @@
    DR_Id, DR_Scene_Id, DR_Scene_Name, DR_Device_Code, DR_Time, DR_Exceed_Times, DR_Avg, 
    DR_Max, DR_Min, DR_Over_Avg_Per, DR_Data_Num, DR_Effective_Rate
  </sql>
  <!-- æ•°æ®ç»Ÿè®¡ç»“果时间条件 -->
  <sql id="Where_Plan_Time">
    <if test="starttime != null">
      AND ${tableAlias}.DR_Time >= #{starttime}
    </if>
    <if test="endtime != null">
      AND ${tableAlias}.DR_Time &lt;= #{endtime}
    </if>
  </sql>
  <select id="selectByArea" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from ea_t_dust_data_result as a
    left join sm_t_scense as b
    on a.DR_Scene_Id = b.S_GUID
    <where>
      <include refid="cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper.Where_Area">
        <property name="tableAlias" value="b"/>
      </include>
      <include refid="cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper.Where_Type">
        <property name="tableAlias" value="b"/>
      </include>
      <include refid="Where_Plan_Time">
        <property name="tableAlias" value="a"/>
      </include>
    </where>
  </select>
</mapper>
src/main/resources/mapper/ds1/ScenseMapper.xml
@@ -70,6 +70,13 @@
    </if>
  </sql>
  <!-- åœºæ™¯ç±»åž‹æ¡ä»¶ -->
  <sql id="Where_Type">
    <if test="scensetypeid != null">
      AND ${tableAlias}.S_TypeID = #{scensetypeid}
    </if>
  </sql>
  <select id="selectNoAccountScene" resultMap="BaseResultMap">
    select a.* FROM sm_t_scense as a LEFT JOIN sm_t_userinfo as b on a.S_GUID = b.D_GUID WHERE b.UI_GUID is null
  </select>
src/test/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DomaincatalogServiceImplTest.kt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,41 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.SupervisionApplication
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.lightshare.service.DomaincatalogService
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest(classes = [SupervisionApplication::class])
class DomaincatalogServiceImplTest {
    @Autowired
    lateinit var domaincatalogService: DomaincatalogService
    @Test
    fun quickConfiguration() {
        domaincatalogService.quickConfiguration(
            Constant.SceneType.TYPE15, AreaVo().apply {
                provincecode = "31"
                provincename = "上海市"
                citycode = "3100"
                cityname = "上海市"
                districtcode = "310105"
                districtname = "长宁区"
            },
            Constant.SceneType.TYPE1, AreaVo().apply {
                provincecode = "31"
                provincename = "上海市"
                citycode = "3100"
                cityname = "上海市"
                districtcode = "310105"
                districtname = "长宁区"
            }
        )
    }
}