package cn.flightfeather.supervision.lightshare.service.Impl
|
|
import cn.flightfeather.supervision.common.creditcode.EnvCreditCode
|
import cn.flightfeather.supervision.domain.entity.Evaluation
|
import cn.flightfeather.supervision.domain.mapper.BaseInfoMapper
|
import cn.flightfeather.supervision.domain.mapper.OverallEvaluationMapper
|
import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
|
import cn.flightfeather.supervision.domain.repository.UserConfigRep
|
import cn.flightfeather.supervision.lightshare.service.CreditService
|
import cn.flightfeather.supervision.lightshare.vo.BaseResponse
|
import cn.flightfeather.supervision.lightshare.vo.CreditInfoVo
|
import cn.flightfeather.supervision.lightshare.vo.DataHead
|
import cn.flightfeather.supervision.lightshare.vo.UserSearchCondition
|
import com.github.pagehelper.PageHelper
|
import org.springframework.stereotype.Service
|
import java.util.*
|
import javax.servlet.http.HttpServletResponse
|
|
@Service
|
class CreditServiceImpl(
|
private val overallEvaluationMapper: OverallEvaluationMapper,
|
private val userinfoMapper: UserinfoMapper,
|
private val userConfigRep: UserConfigRep,
|
private val baseInfoMapper: BaseInfoMapper,
|
) : CreditService {
|
|
override fun searchEcCodeList(
|
userId: String,
|
condition: UserSearchCondition,
|
page: Int,
|
perPage: Int,
|
): BaseResponse<List<CreditInfoVo>> {
|
if (condition.period == null) return BaseResponse(false, "必须选择周期")
|
if (condition.sceneTypes.size > 2) return BaseResponse(false, "场景类型只支持一种")
|
val config = userConfigRep.getUserConfigBySubType(userId)
|
val condition2 = UserSearchCondition.fromUserConfig(config, condition)
|
val p = PageHelper.startPage<Evaluation>(page, perPage)
|
val result = overallEvaluationMapper.searchEcCodeList(condition2)
|
return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = result)
|
}
|
|
override fun downloadEcCodeImg(userId: String, response: HttpServletResponse): BaseResponse<Boolean> {
|
// val info = baseInfoMapper.selectByPrimaryKey(userId)?.let { Triple(it.biGuid, it.biName ?: "", it.ciName) }
|
// ?: userinfoMapper.selectByPrimaryKey(userId)?.let { Triple(it.guid, it.realname ?: "", "") }
|
// ?: return BaseResponse(false, "用户不存在")
|
val info = baseInfoMapper.selectByPrimaryKey(userId) ?: return BaseResponse(false, "用户不存在")
|
val supply = "${info.biCityName}${info.biDistrictName}生态环境局"
|
return try {
|
response.contentType = "image/png;charset=utf-8"
|
val name = Base64.getEncoder().encodeToString("${info.biName}.png".toByteArray())
|
response.setHeader("fileName", name)
|
EnvCreditCode.createImage(info.biGuid, info.biName, info.ciName, supply, response.outputStream)
|
// response.outputStream.write(output.toByteArray())
|
BaseResponse(true)
|
} catch (e: Exception) {
|
BaseResponse(false, "环信码图片生成异常:${e.message}")
|
}
|
}
|
}
|