package com.yeshi.makemoney.app.controller.admin.goldcorn;
|
|
import com.google.gson.*;
|
import com.yeshi.makemoney.app.utils.SystemInfoUtil;
|
import com.yeshi.makemoney.app.vo.admin.goldcorn.GoldCornMoneyExchangeRateAdminVO;
|
import net.sf.json.JSONArray;
|
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.SystemUtil;
|
import org.yeshi.utils.TimeUtil;
|
import com.google.gson.reflect.TypeToken;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpSession;
|
import java.lang.reflect.Type;
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.List;
|
|
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornMoneyExchangeRateRecord;
|
import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMoneyExchangeRateRecordService;
|
import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornMoneyExchangeRateRecordQuery;
|
|
@Controller
|
@RequestMapping("admin/api/goldcorn/exchangerate")
|
public class GoldCornMoneyExchangeRateRecordAdminController {
|
|
@Resource
|
private GoldCornMoneyExchangeRateRecordService goldCornMoneyExchangeRateRecordService;
|
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String list(GoldCornMoneyExchangeRateRecordQuery query, int page, int limit) {
|
List<GoldCornMoneyExchangeRateRecord> list = goldCornMoneyExchangeRateRecordService.list(query, page, limit);
|
long count = goldCornMoneyExchangeRateRecordService.count(query);
|
JSONObject data = new JSONObject();
|
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
|
@Override
|
public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) {
|
return date == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(date.getTime(), "yyyy.MM.dd HH:mm"));
|
}
|
}).create();
|
|
data.put("list", gson.toJson(list));
|
data.put("count", count);
|
return JsonUtil.loadTrueResult(data);
|
|
}
|
|
@ResponseBody
|
@RequestMapping("delete")
|
public String delete(String ids) {
|
Type type = new TypeToken<List<String>>() {
|
}.getType();
|
List<String> idList = new Gson().fromJson(ids, type);
|
|
for (String id : idList) {
|
//生效之后无法修改,无法删除
|
GoldCornMoneyExchangeRateRecord record = goldCornMoneyExchangeRateRecordService.get(id);
|
if (record.getValidateTime().getTime() <= System.currentTimeMillis()) {
|
return JsonUtil.loadFalseResult("已经生效的设置无法删除");
|
}
|
}
|
goldCornMoneyExchangeRateRecordService.delete(idList);
|
return JsonUtil.loadTrueResult("");
|
}
|
|
@ResponseBody
|
@RequestMapping("add")
|
public String add(GoldCornMoneyExchangeRateAdminVO vo, HttpSession session) {
|
try {
|
GoldCornMoneyExchangeRateRecord bean = vo.toEntity(SystemInfoUtil.getAdminSelectedSystem(session));
|
goldCornMoneyExchangeRateRecordService.add(bean);
|
return JsonUtil.loadTrueResult("");
|
} catch (Exception e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping("get")
|
public String get(String id, HttpSession session) {
|
GoldCornMoneyExchangeRateRecord entity = goldCornMoneyExchangeRateRecordService.get(id);
|
if (entity != null) {
|
return JsonUtil.loadTrueResult(GoldCornMoneyExchangeRateAdminVO.create(entity));
|
} else {
|
return JsonUtil.loadFalseResult("ID不存在");
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("update")
|
public String update(GoldCornMoneyExchangeRateAdminVO bean, HttpSession session) {
|
if (bean.getId() == null) {
|
return JsonUtil.loadFalseResult("ID不能为空");
|
}
|
|
//生效之后无法修改,无法删除
|
GoldCornMoneyExchangeRateRecord record = goldCornMoneyExchangeRateRecordService.get(bean.getId());
|
if (record.getValidateTime().getTime() <= System.currentTimeMillis()) {
|
return JsonUtil.loadFalseResult("已经生效的设置无法修改");
|
}
|
|
|
try {
|
goldCornMoneyExchangeRateRecordService.update(bean.toEntity(null));
|
} catch (Exception e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
|
}
|
return JsonUtil.loadTrueResult("");
|
|
}
|
|
|
}
|