admin
2025-08-08 035edfa382d349ba66240fbfef68c14c7cfc95d1
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
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.taoke.autopay.controller.admin.js2;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.taoke.autopay.dao.ClientInfoMapper;
import com.taoke.autopay.entity.ClientAdditionalInfo;
import com.taoke.autopay.entity.ClientInfo;
import com.taoke.autopay.service.ClientAdditionalInfoService;
import com.taoke.autopay.service.ClientInfoService;
import com.taoke.autopay.utils.Constant;
import com.taoke.autopay.utils.TimeUtil;
import com.taoke.autopay.utils.encrypt.AESUtil;
import com.taoke.autopay.vo.admin.AdminOrderClientInfoVO;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.util.*;
 
/**
 * 下单设备管理
 */
@Controller
@RequestMapping("/admin/api/clientinfo/js2")
public class AdminClientInfoJS2Controller {
 
    @Resource
    private ClientInfoService clientInfoService;
 
    @Resource
    private ClientAdditionalInfoService clientAdditionalInfoService;
 
    private final Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
        @Override
        public void write(JsonWriter out, Date value) throws IOException {
            String desc = "";
            if (value != null) {
                // 判断是否是同一天
                desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
                out.value(desc);
            } else {
                out.value("");
            }
        }
 
        @Override
        public Date read(JsonReader in) throws IOException {
            return new Date();
        }
    }).create();
 
    @ResponseBody
    @RequestMapping("list")
    public String list(String account, int page,int limit){
 
        ClientInfoMapper.DaoQuery query=new   ClientInfoMapper.DaoQuery();
        if(!StringUtil.isNullOrEmpty(account)) {
            query.account = account;
        }
        query.start = (long) (page - 1) *limit;
        query.count = limit;
        query.clientType = ClientInfo.CLIENT_TYPE_ORDER;
        query.sortList= Arrays.asList(new String[]{"create_time desc"});
        JSONObject data=new JSONObject();
        List<ClientInfo> list = clientInfoService.list(query);
        Map<Long, ClientAdditionalInfo> map;
        if(!list.isEmpty()){
            List<Long> idList=new ArrayList<>();
            for(ClientInfo info:list){
                idList.add(info.getId());
            }
            map = clientAdditionalInfoService.getClientAdditionalInfoMap(idList);
        } else {
            map = new HashMap<>();
        }
        List<AdminOrderClientInfoVO> results = new ArrayList<>();
        list.forEach(info->{
            ClientAdditionalInfo additionalInfo = map.get(info.getId());
            results.add(AdminOrderClientInfoVO.builder()
                    .client(info)
                    .additionalInfo(additionalInfo)
                    .build());
        });
 
        data.put("list", gson.toJson(results));
        data.put("count",  clientInfoService.count(query));
        return JsonUtil.loadTrueResult(data);
    }
 
 
    @ResponseBody
    @RequestMapping("setpwd")
    public String setPwd(Long id, String pwd) {
        if(id==null||pwd==null||pwd.length()<6){
            return JsonUtil.loadFalseResult("数据不完整");
        }
        clientInfoService.setPwd(id,StringUtil.Md5( pwd));
        return JsonUtil.loadTrueResult("");
    }
 
    @ResponseBody
    @RequestMapping("add")
    public String addClient(String pwd, int count) {
        if(count>100){
            return JsonUtil.loadFalseResult("单次创建最多100个");
        }
        for(int i=0;i<count;i++){
              ClientInfo info=ClientInfo.builder()
                      .pwd(StringUtil.Md5(pwd))
                      .clientType(ClientInfo.CLIENT_TYPE_ORDER)
                      .build();
              clientInfoService.add(info);
              if(info!=null){
                  clientAdditionalInfoService.addClientAdditionalInfo(ClientAdditionalInfo.builder()
                                  .id(info.getId())
                                  .createTime(new Date())
                          .build());
              }
        }
        return JsonUtil.loadTrueResult("");
    }
 
    @ResponseBody
    @RequestMapping("update")
    public String updateClientInfo(ClientAdditionalInfo info) {
        if(info==null||info.getId()==null) {
            return JsonUtil.loadFalseResult("数据不完整");
        }
        if(!StringUtil.isNullOrEmpty(info.getAlipayPassword())){
            info.setAlipayPassword(AESUtil.encrypt(info.getAlipayPassword(), Constant.AES_KEY));
        }else{
            ClientAdditionalInfo old =  clientAdditionalInfoService.getClientAdditionalInfoByClientId(info.getId());
            if(StringUtil.isNullOrEmpty(old.getAlipayPassword())){
                return JsonUtil.loadFalseResult("尚未设置支付宝密码");
            }
        }
        clientAdditionalInfoService.updateClientAdditionalInfo(info);
        return JsonUtil.loadTrueResult("");
    }
 
    @ResponseBody
    @RequestMapping("getAdditionalInfo")
    public String getAdditionalInfo(Long id) {
        if(id==null) {
            return JsonUtil.loadFalseResult("数据不完整");
        }
        ClientAdditionalInfo additionalInfo =  clientAdditionalInfoService.getClientAdditionalInfoByClientId(id);
        additionalInfo.setAlipayPassword("");
        return JsonUtil.loadTrueResult(gson.toJson(additionalInfo));
    }
 
}