linzhijie
2021-03-11 93af1c6ffb9ae0e894689ad3a37b548e57d54cff
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
package com.ots.project.exam.restcontroller;
 
import com.ots.project.exam.domain.EntDemographyInfo;
import com.ots.project.exam.domain.EntDemographyParam;
import com.ots.project.exam.domain.EntTestMember;
import com.ots.project.exam.dto.DictItemDto;
import com.ots.project.exam.dto.ParamDefine;
import com.ots.project.exam.dto.ParamsInfo;
import com.ots.project.exam.dto.RestResponse;
import com.ots.project.exam.service.IEntDemographyParamService;
import com.ots.project.exam.service.IEntTestMemberService;
import com.ots.project.exam.service.ITReportTemplateService;
import com.ots.project.exam.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
 
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
 
@RestController
public class MemberControllerImpl implements MemberController {
 
    @Autowired
    private MemberService memberService;
 
    @Autowired
    private IEntTestMemberService entTestMemberService;
 
    @Autowired
    IEntDemographyParamService entDemographyParamService;
 
    @Autowired
    private ITReportTemplateService itReportTemplateService;
 
    @Override
    public RestResponse getdemographyParam(String token, String lang) {
        try {
            List<ParamDefine> collect = memberService.getParamDefines(token, lang);
            // 給姓名默认值
            getMemberNameValue(collect);
            return RestResponse.ok(collect);
        } catch (Exception ex) {
            return RestResponse.fail(ex);
        }
    }
 
    private void getMemberNameValue(List<ParamDefine> collect) {
        EntTestMember entTestMember = entTestMemberService.selectEntTestMemberById(collect.get(0).getMemberId());
        String  paramIds = collect.stream().map(it -> {
            return it.getParamId().toString();
        }).collect(Collectors.joining(","));
 
        List<EntDemographyParam> entDemographyParams = entDemographyParamService.selectEntDemographyParamListByParamIn(paramIds);
        Map<Long, String> entDemographyParamsMap = entDemographyParams.stream().collect(
                Collectors.toMap(EntDemographyParam::getParamId, EntDemographyParam::getParamCode));
 
        for (ParamDefine paramDefine : collect) {
            System.out.println(entDemographyParamsMap.get(paramDefine.getParamId()));
            if (Objects.equals(entDemographyParamsMap.get(paramDefine.getParamId()), "name")) {
                paramDefine.setParamValue(entTestMember.getMemberName());
            }
        }
    }
 
    @Override
    public RestResponse queryDemographyParamInfo(String token) {
        try {
            List<EntDemographyInfo> resluts = memberService.queryDemographyParamInfo(token);
            return RestResponse.ok(resluts);
        } catch (Exception ex) {
            return RestResponse.fail(ex);
        }
    }
 
    @Override
    public RestResponse saveDemographyParamInfo(@Valid List<ParamsInfo> infos, String token, String langType) {
        try {
            memberService.saveDemographyParamInfo(token, infos, langType);
            return RestResponse.ok();
        } catch (Exception ex) {
            return RestResponse.fail(ex);
        }
    }
 
    @Override
    public RestResponse memberAuth(String token) {
        try {
            return RestResponse.ok();
        } catch (Exception ex) {
            return RestResponse.fail(ex);
        }
    }
 
    @Override
    public RestResponse queryLangList(String token, String reportTemplateId) {
        try {
            List<DictItemDto> resluts = memberService.queryLang(token);
            // 睿邻只有中文
//            List<TReportTemplate> tReportTemplateList = itReportTemplateService.selectTReportTemplates(reportTemplateId);
//            // 睿邻的只有中文
//            for (TReportTemplate tReportTemplate : tReportTemplateList) {
//                if ("RuiLin".equals(tReportTemplate.getReportType())) {
//                    for (DictItemDto dictData : resluts) {
//                        if ("Chinese".equals(dictData.getDictValue())) {
//                            List<DictItemDto> reslutChinese = new ArrayList<>();
//                            reslutChinese.add(dictData);
//                            return RestResponse.ok(reslutChinese);
//                        }
//                    }
//                }
//            }
 
            return RestResponse.ok(resluts);
        } catch (Exception ex) {
            return RestResponse.fail(ex);
        }
    }
}