src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
@@ -21,7 +21,9 @@
import java.text.SimpleDateFormat
import javax.annotation.Resource
import java.math.BigDecimal
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
@@ -114,8 +116,8 @@
    override fun getStatisticalResult(areaVo: AreaVo): List<StatisticsVo> {
        val districtcode = areaVo.districtcode
        val sceneType = areaVo.scensetypeid
        val startTime = areaVo.starttime
        val endTime = areaVo.endtime
        val startTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val endTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val maps = problemlistMapper.getStatisticalResult(districtcode,startTime, endTime, sceneType)
        val statisticsVos = mutableListOf<StatisticsVo>()
        maps.forEach {
@@ -144,7 +146,12 @@
//                .andGreaterThanOrEqualTo("endtime", areaVo.endtime)
//                .andEqualTo("districtcode", areaVo.districtcode)
        val chargeInfoVo = ChargeInfoVo()
        val sql = "select T_GUID, T_Name from tm_t_task where TS_GUID IS NULL and T_StartTime <= '" + areaVo.starttime + "' and T_EndTime >= '" + areaVo.endtime + "' and T_DistrictCode = '" + areaVo.districtcode +"'"
        val sTime = areaVo.starttime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val eTime = areaVo.endtime?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
        val sql =
            "select T_GUID, T_Name from tm_t_task where TS_GUID IS NULL and T_StartTime <= '" + sTime + "' and T_EndTime" +
                    " >= '" + eTime + "' and T_DistrictCode = '" + areaVo.districtcode + "'"
        val maps1 = taskMapper.selectSE(sql)
        var topTaskId = String()
        var topTaskName = String()
@@ -321,6 +328,12 @@
                mediafileMapper.deleteByExample(Example(Mediafile::class.java).apply {
                    createCriteria().andEqualTo("businessguid", id)
                })
                //更新巡查信息中的问题数量
                val inspection = inspectionMapper.selectByPrimaryKey(p.iguid)
                if (inspection.problemcount != null && inspection.problemcount!! > 0) {
                    inspection.problemcount = inspection.problemcount!! - 1
                    inspectionMapper.updateByPrimaryKey(inspection)
                }
                BaseResponse(true, "问题删除成功", data = i)
            }
        }
@@ -478,12 +491,92 @@
            val filePath = "${Constant.DEFAULT_FILE_PATH}/images/$path/"
            try {
                //调用文件保存方法
                FileUtil().uploadFile(image.bytes, filePath, fileName)
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                // TODO: handle exception
            }
        }
        //更新巡查信息的问题数
        if (inspection.problemcount != null) {
            inspection.problemcount = inspection.problemcount!! + 1
            inspectionMapper.updateByPrimaryKey(inspection)
        }
        return BaseResponse(true)
    }
    override fun changeProblem(problemId: String, files: Array<MultipartFile>): BaseResponse<String> {
        // 更新问题
        val p = problemlistMapper.selectByPrimaryKey(problemId) ?: return BaseResponse(false, "问题不存在")
        p.apply {
            ischanged = true
            changedtime = Date()
            extension3 = Constant.CHANGE_UNCHECKED
            val today = LocalDate.now()
            val pTime = LocalDateTime.ofInstant(time?.toInstant(), ZoneId.systemDefault()).toLocalDate()
            changecatalog = if (p.extension1 != null) {
                if (today.isAfter(pTime)) {
                    Constant.PROMISE_CHANGE
                } else {
                    Constant.LOCAL_CHANGE
                }
            } else {
                Constant.UN_PROMISE_CHANGE
            }
        }
        problemlistMapper.updateByPrimaryKey(p)
        // 保存图片
        val now = LocalDateTime.now()
        val mediaFiles = mediafileMapper.selectByExample(Example(Mediafile::class.java).apply {
            createCriteria().andEqualTo("businessguid", p.guid)
                .andEqualTo("businesstypeid", 1)
                .andEqualTo("ischanged", false)
        })
        if (mediaFiles.isEmpty()) return BaseResponse(false, "场景问题数量为0,无法整改")
        val m = mediaFiles[0]
        m.path = m.path + "整改/"
        m.savetime = Date()
        m.ischanged = true
        for (image in files) {
            m.apply {
                guid = UUIDGenerator.generate16ShortUUID()
                description = p.problemname + " " + p.location + " 整改 " + UUIDGenerator.generateUUID(4) + ".jpg"
            }
            mediafileMapper.insert(m)
            val path = m.extension1
            val fileName = m.guid + ".jpg"
//            val filePath = "E:\\work\\第三方监管app\\自动评分\\餐饮\\"
            val filePath = "${Constant.DEFAULT_FILE_PATH}/images/$path"
            try {
                //调用文件保存方法
                FileUtil.uploadFile(image.bytes, filePath, fileName)
            } catch (e: Exception) {
                println(e)
            }
        }
        return BaseResponse(true)
    }
    override fun getBySubTask(stGuid: String): List<ProblemlistVo> {
        //根据子任务ID获取问题列表
        val problemListVo = findBySubtaskId(stGuid)
        //判断是否有问题列表
        if (!problemListVo.isEmpty()) {
            //根据每个问题,获取媒体文件
            problemListVo.forEach {
                val mediafileVo = mediafileService.findByBusinessGUID(it.guid!!)
                //判断是否有媒体资料
                if (!mediafileVo.isEmpty()) {
                    //赋值
                    it.mediafileList = mediafileVo
                }
            }
        }
        return problemListVo
    }
}