package com.taoke.autopay.controller.admin;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.JsonObject;
|
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.AdminUser;
|
import com.taoke.autopay.entity.ClientInfo;
|
import com.taoke.autopay.service.AdminUserService;
|
import com.taoke.autopay.service.ClientInfoService;
|
import com.taoke.autopay.utils.TimeUtil;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.validation.BindingResult;
|
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 javax.servlet.http.HttpSession;
|
import javax.validation.constraints.NotEmpty;
|
import java.io.IOException;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
|
@Controller
|
@RequestMapping("/admin/api/clientinfo")
|
public class AdminClientInfoController {
|
|
@Resource
|
private ClientInfoService clientInfoService;
|
|
private 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 = (page-1)*limit;
|
query.count = limit;
|
query.sortList= Arrays.asList(new String[]{"create_time desc"});
|
JSONObject data=new JSONObject();
|
List<ClientInfo> list = clientInfoService.list(query);
|
data.put("list", gson.toJson(list));
|
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=new ClientInfo();
|
info.setPwd(StringUtil.Md5(pwd));
|
clientInfoService.add(info);
|
}
|
return JsonUtil.loadTrueResult("");
|
}
|
|
}
|