feiyu02
2024-11-19 752e00503f672ddfe2066afb6c235721a3a912b5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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}")
        }
    }
}