我有购买的简单REST,我需要做的最后一件事是方法:报告2019 UAH —此命令应从http://fixer.io获取交叉货币汇率的列表(免费注册)计划),计算指定年份的总收入,将其转换并以指定货币显示,其中: 2019年–应计算总收入的年份 UAH-表示总收入的货币。 我什至不知道如何处理它。甚至不知道保存货币和鞭子数据的最佳方法是什么。
@Entity
@Table (name="purchase")
public class Purchase {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@CreationTimestamp
@Temporal(TemporalType.DATE)
@Column(name="createat")
private Date created;
@Column(name="price")
private BigDecimal price;
@Column(name="currency")
private String currency;}
@Repository
public interface PurchaseRepository extends CrudRepository<Purchase, Long
> {
List<Purchase> findById(Long id);
List<Purchase> findAllByOrderByCreatedAsc();
String deleteByCurrency(String currency);
long deleteByCreated(Date date);
}
@Service
public class PurchaseService {
@Autowired
private PurchaseRepository purchaseRepository;
public void addPurchase(Purchase purchase) {
purchaseRepository.save(purchase);
}
public List<Purchase> getAllPurchase(){
List<Purchase> purchase = new ArrayList<>();
purchaseRepository.findAll().forEach(purchase::add);
return purchase;
}
public List<Purchase> findAllSorted(){
List<Purchase> persons = purchaseRepository.findById((long) 2);
return persons;
}
@Transactional
public List<Purchase> findAllByOrderByCreatedAsc() {
List<Purchase> persons =
purchaseRepository.findAllByOrderByCreatedAsc();
return persons;
}
@Transactional
public String deleteByCurrency(String currency) {
return purchaseRepository.deleteByCurrency(currency);
};
@Transactional
public long deleteAllByDate(Date date){
return purchaseRepository.deleteByCreated(date);
}
}
@RestController
public class PurchaseController {
@Autowired
private PurchaseService purchaseService;
@PostMapping("/purchase")
public void addPurchase (@RequestBody Purchase purchase) {
purchaseService.addPurchase(purchase);}
@RequestMapping("/purchase")
public List<Purchase> getAllTopics(){
return purchaseService.getAllPurchase();
}
@RequestMapping("/purchasee")
public List<Purchase> getAllbyName(){
return purchaseService.findAllSorted();
}
@RequestMapping("/purchases")
public List<Purchase> getAllByDate(){
return purchaseService.findAllByOrderByCreatedAsc();
}
@RequestMapping(method=RequestMethod.DELETE,
value="/purchase/{created}")
String deleteByDate(@PathVariable String currency) {
return purchaseService.deleteByCurrency(currency);
Method Report 2019 UAH —此命令应从http://fixer.io(注册免费计划)中获取交叉货币汇率列表,计算指定年份的总收入,将其转换为指定货币,其中:
2019年-应计算总收入的年份 UAH-表示总收入的货币