| | |
| | | public class CreditExchangeRateAdminController { |
| | | |
| | | 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 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(); |
| | | } |
| | | }).registerTypeAdapter(BigDecimal.class, new TypeAdapter<BigDecimal>() { |
| | | @Override |
| | | public void write(JsonWriter out, BigDecimal value) throws IOException { |
| | | if (value != null) { |
| | | out.value(value.toString()); |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | @Override |
| | | public Date read(JsonReader in) throws IOException { |
| | | return new Date(); |
| | | } |
| | | }).registerTypeAdapter(BigDecimal.class, new TypeAdapter<BigDecimal>() { |
| | | @Override |
| | | public void write(JsonWriter out, BigDecimal value) throws IOException { |
| | | if (value != null) { |
| | | out.value(value.toString()); |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal read(JsonReader in) throws IOException { |
| | | return new BigDecimal("0.00"); |
| | | } |
| | | }).create(); |
| | | @Override |
| | | public BigDecimal read(JsonReader in) throws IOException { |
| | | return new BigDecimal("0.00"); |
| | | } |
| | | }).registerTypeAdapter(ExchangeRate.ExchangeRateType.class, new TypeAdapter<ExchangeRate.ExchangeRateType>() { |
| | | @Override |
| | | public void write(JsonWriter out, ExchangeRate.ExchangeRateType value) throws IOException { |
| | | if (value != null) { |
| | | out.value(value.getDesc()); |
| | | } else { |
| | | out.value(""); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ExchangeRate.ExchangeRateType read(JsonReader in) throws IOException { |
| | | return ExchangeRate.ExchangeRateType.GENERAL_EXCHANGE; |
| | | } |
| | | }) |
| | | |
| | | .create(); |
| | | |
| | | @Resource |
| | | private ExchangeRateService exchangeRateService; |
| | |
| | | @RequestMapping("list") |
| | | public String listExchangeRates(int page, int limit) { |
| | | List<ExchangeRate> exchangeRates = exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder() |
| | | .start((long) (page - 1) * limit) |
| | | .count(limit) |
| | | .start((long) (page - 1) * limit) |
| | | .count(limit) |
| | | .build()); |
| | | long count = exchangeRateService.countExchangeRates(ExchangeRateMapper.DaoQuery.builder().build()); |
| | | JSONObject root=new JSONObject(); |
| | | root.put("list",gson.toJson(exchangeRates)); |
| | | root.put("count",count); |
| | | JSONObject root = new JSONObject(); |
| | | root.put("list", gson.toJson(exchangeRates)); |
| | | root.put("count", count); |
| | | return JsonUtil.loadTrueResult(root); |
| | | } |
| | | |
| | |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("update") |
| | | public String updateExchangeRate(ExchangeRate exchangeRate) { |
| | | int success = exchangeRateService.updateExchangeRate(exchangeRate); |
| | | if (success>0) { |
| | | public String updateExchangeRate(Long id, BigDecimal rate) { |
| | | int success = exchangeRateService.updateExchangeRate(ExchangeRate.builder() |
| | | .id(id) |
| | | .rate(rate) |
| | | .build()); |
| | | if (success > 0) { |
| | | return JsonUtil.loadTrueResult("更新成功"); |
| | | } else { |
| | | return JsonUtil.loadFalseResult("更新失败"); |