| | |
| | | package com.yami.trading.admin.controller.miner; |
| | | |
| | | import com.yami.trading.admin.controller.service.MinerService; |
| | | import com.yami.trading.bean.model.Miner; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import com.yami.trading.bean.miner.Miner; |
| | | import com.yami.trading.common.exception.BusinessException; |
| | | import com.yami.trading.common.web.ResultObject; |
| | | import com.yami.trading.service.miner.service.MinerService; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @program: trading-order-master |
| | | * @description: 矿机 |
| | | * @create: 2025-01-22 17:10 |
| | | **/ |
| | | * 矿机产品 |
| | | * |
| | | */ |
| | | @RestController |
| | | @RequestMapping("miner") |
| | | @Api(tags = "矿机") |
| | | @Slf4j |
| | | @CrossOrigin |
| | | public class MinerController { |
| | | |
| | | @Autowired |
| | | private MinerService minerService; |
| | | private Logger logger = LogManager.getLogger(MinerController.class); |
| | | |
| | | @Autowired |
| | | protected MinerService minerService; |
| | | |
| | | private final String action = "api/miner!"; |
| | | |
| | | // 添加矿机 |
| | | @PostMapping("/add") |
| | | public boolean addMiner(@RequestBody Miner miner) { |
| | | return minerService.addMiner(miner); |
| | | } |
| | | /** |
| | | * 矿机产品列表 |
| | | */ |
| | | @RequestMapping(action + "list.action") |
| | | public Object list() throws IOException { |
| | | |
| | | // 删除矿机 |
| | | @DeleteMapping("/delete/{id}") |
| | | public boolean deleteMiner(@PathVariable int id) { |
| | | return minerService.deleteMiner(id); |
| | | } |
| | | ResultObject resultObject = new ResultObject(); |
| | | try { |
| | | List<Miner> data = minerService.findAllState_1(); |
| | | List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); |
| | | if (data != null) { |
| | | for (int i = 0; i < data.size(); i++) { |
| | | result.add(minerService.getBindOne(data.get(i))); |
| | | } |
| | | } |
| | | resultObject.setData(result); |
| | | resultObject.setCode("0"); |
| | | } catch (BusinessException e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg(e.getMessage()); |
| | | logger.error("BusinessException:", e); |
| | | } catch (Exception e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | return resultObject; |
| | | } |
| | | |
| | | // 更新矿机 |
| | | @PutMapping("/update") |
| | | public boolean updateMiner(@RequestBody Miner miner) { |
| | | return minerService.updateMiner(miner); |
| | | } |
| | | /** |
| | | * 矿机产品详情 |
| | | */ |
| | | @RequestMapping(action + "get.action") |
| | | public Object get(HttpServletRequest request) { |
| | | |
| | | // 获取矿机详情 |
| | | @GetMapping("/get/{id}") |
| | | public Miner getMiner(@PathVariable int id) { |
| | | return minerService.getMiner(id); |
| | | } |
| | | ResultObject resultObject = new ResultObject(); |
| | | try { |
| | | String id = request.getParameter("id"); |
| | | Miner data = minerService.findById(id); |
| | | resultObject.setData(minerService.getBindOne(data)); |
| | | resultObject.setCode("0"); |
| | | } catch (BusinessException e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg(e.getMessage()); |
| | | logger.error("BusinessException:", e); |
| | | } catch (Exception e) { |
| | | resultObject.setCode("1"); |
| | | resultObject.setMsg("程序错误"); |
| | | logger.error("error:", e); |
| | | } |
| | | |
| | | // 获取所有矿机 |
| | | @GetMapping("/getAll") |
| | | public List<Miner> getAllMiners() { |
| | | return minerService.getAllMiners(); |
| | | } |
| | | |
| | | |
| | | return resultObject; |
| | | } |
| | | } |