xieb
2023-10-19 1dd5d8f8a616f5cf3caa7828d46989c7d3dcafc4
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package cn.gistack.sm.jcsb.service.impl;
 
import cn.gistack.pwd.dto.CBCResultDTO;
import cn.gistack.pwd.dto.ResultDTO;
import cn.gistack.pwd.fegin.IPwdClient;
import cn.gistack.sm.jcsb.supo.DangerReportSUPO;
import cn.gistack.sm.jcsb.entity.DangerReport;
import cn.gistack.sm.jcsb.mapper.DangerReportMapper;
import cn.gistack.sm.jcsb.service.IDangerReportService;
import cn.gistack.sm.jcsb.vo.DangerReportVO;
import cn.gistack.sm.jcsb.vo.StatisticsVO;
import cn.gistack.sm.sjztmd.entity.AttResBase;
import cn.gistack.sm.sjztmd.service.IAttResBaseService;
import cn.gistack.system.user.entity.User;
import cn.gistack.system.user.feign.IUserClient;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.Serializable;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
 
/**
 * @PROJECT_NAME: skjcmanager
 * @DESCRIPTION:
 * @USER: aix
 * @DATE: 2023/5/18 17:47
 */
@Service
public class DangerReportServiceImpl extends BaseServiceImpl<DangerReportMapper, DangerReport> implements IDangerReportService {
 
    @Autowired
    private IPwdClient pwdClient;
    @Autowired
    private IAttResBaseService attResBaseService;
 
    @Autowired
    private IUserClient userClient;
 
    @Override
    public List<DangerReportVO> getAll(DangerReport dangerReport) {
        return baseMapper.getAll(dangerReport);
    }
 
    @Override
    public IPage<DangerReportVO> selectPage(IPage<DangerReportVO> page, DangerReportVO dangerReportVO) {
        List<DangerReportVO> dangerReportVOS = baseMapper.selectRecordPage(page, dangerReportVO);
        dangerReportVOS.forEach(item->{
            R<ResultDTO> res = pwdClient.getDecrypt(item.getSm4iv(), item.getKeyindexs(), item.getEncdata());
            if (res.getCode() == 200){
                item.setBase64Data(res.getData().getData());
            }
 
            item.setEncdata("");
            item.setKeyindexs("");
            item.setSm4iv("");
        });
        return page.setRecords(dangerReportVOS);
    }
 
    @Override
    public StatisticsVO getStatistics(String resGuid) {
        return baseMapper.getStatistics(resGuid);
    }
 
    @Override
    public boolean saveUp(DangerReport dangerReport) {
        // 填充加密内容
        DangerReportSUPO dangerReportSUPO = BeanUtil.copy(dangerReport, DangerReportSUPO.class);
 
        // 获取水库名称
        AttResBase attResBase = attResBaseService.getDetailByCode(dangerReport.getReservoirId());
        //转码后的水库名
        String encodeReservoirName = "";
        //转码后的上报人
        String encodeCreateUserName = "";
        //转码后的处理人
        String encodeToUserName = "";
        String encodeDesinfo = "";
        R<User> userR = userClient.userInfoById(Long.parseLong(dangerReportSUPO.getToUser()));
        R<User> createUser = userClient.userInfoById(dangerReportSUPO.getCreateUser());
 
        try {
            encodeReservoirName= URLEncoder.encode(attResBase.getName(), "UTF-8");
            encodeCreateUserName = URLEncoder.encode(createUser.getData().getName(), "UTF-8");
            encodeToUserName=URLEncoder.encode(userR.getData().getName(), "UTF-8");
            encodeDesinfo = URLEncoder.encode(dangerReport.getDesinfo(), "UTF-8");
        }catch (Exception e){
            System.out.println(e);
        }
 
 
        dangerReportSUPO.setReservoirName(encodeReservoirName);
        dangerReport.setReservoirName(attResBase.getName()); // 保存水库名称
        dangerReport.setReservoirId(attResBase.getGuid());
 
        // 获取用户
        dangerReportSUPO.setCreateUserName(encodeCreateUserName);
        dangerReportSUPO.setToUserName(encodeToUserName);
        dangerReportSUPO.setDesinfo(encodeDesinfo);
 
        String message = JSONObject.toJSONString(dangerReportSUPO);
        R<CBCResultDTO> cbcResultDTOR =  pwdClient.getCBCMacEncipher(message);
        if (cbcResultDTOR.getCode() != 200) {
            return false;
        }
        String maced = cbcResultDTOR.getData().getMaced();
        String keyIndex = cbcResultDTOR.getData().getKeyIndex();
        String sm4iv = cbcResultDTOR.getData().getSm4IV();
        dangerReport.setMaced(maced);
        dangerReport.setKeyindexs(keyIndex);
        dangerReport.setSm4iv(sm4iv);
        R<ResultDTO> resultDTOR = pwdClient.getEncrypt(sm4iv, keyIndex, message);
        if (resultDTOR.getCode() != 200) {
            return false;
        }
        dangerReport.setEncdata(resultDTOR.getData().getData());
 
        return this.save(dangerReport);
 
    }
 
    @Override
    public DangerReportVO getVODetail(String id) {
        DangerReport item = super.getById(id);
        DangerReportVO newEntity = new DangerReportVO();
        newEntity.setId(item.getId());
 
        R<ResultDTO> res = pwdClient.getDecrypt(item.getSm4iv(), item.getKeyindexs(), item.getEncdata());
        if (res.getCode() == 200){
            newEntity.setBase64Data(res.getData().getData());
            newEntity.setCreateTime(item.getCreateTime());
        }
 
        return newEntity;
    }
 
}