package com.gear.admin.controller.swx;;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.List;
|
import javax.servlet.http.HttpServletResponse;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.gear.admin.vo.swx.OptionsOrderVo;
|
import com.gear.admin.vo.swx.SmartOrderVo;
|
import com.gear.common.builder.WhereBuilder;
|
import com.gear.common.vo.Result;
|
import com.gear.swx.domain.SwxOptionsOrder;
|
import com.gear.swx.domain.SwxRechargeRecord;
|
import com.gear.swx.domain.SwxUser;
|
import com.gear.swx.service.ISwxUserService;
|
import io.jsonwebtoken.lang.Collections;
|
import org.apache.logging.log4j.util.Strings;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import com.gear.common.annotation.Log;
|
import com.gear.common.core.controller.BaseController;
|
import com.gear.common.enums.BusinessType;
|
import com.gear.swx.domain.SwxSmartOrder;
|
import com.gear.swx.service.ISwxSmartOrderService;
|
import com.gear.common.utils.poi.ExcelUtil;
|
|
/**
|
* 智能交易订单Controller
|
*
|
* @author czx
|
* @date 2023-11-20
|
*/
|
@RestController
|
@RequestMapping("/swx/smartOrder")
|
public class SwxSmartOrderController extends BaseController
|
{
|
@Autowired
|
private ISwxSmartOrderService swxSmartOrderService;
|
|
@Autowired
|
private ISwxUserService swxUserService;
|
/**
|
* 查询智能交易订单列表
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:list')")
|
@GetMapping("/list")
|
public Result<IPage<SmartOrderVo>> list(SmartOrderVo swxSmartOrder,
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
|
QueryWrapper<SwxSmartOrder> queryWrapper = new QueryWrapper<>();
|
if(!Strings.isEmpty(swxSmartOrder.getPhone()) || !Strings.isEmpty(swxSmartOrder.getUserName())){
|
QueryWrapper<SwxUser> userQueryWrapper = new QueryWrapper<>();
|
if(!Strings.isEmpty(swxSmartOrder.getUserName())){
|
userQueryWrapper.lambda().like(SwxUser::getUserName,swxSmartOrder.getUserName());
|
}
|
if(!Strings.isEmpty(swxSmartOrder.getPhone())){
|
userQueryWrapper.lambda().like(SwxUser::getPhone,swxSmartOrder.getPhone());
|
}
|
|
List<SwxUser> list = swxUserService.list(userQueryWrapper);
|
List<String> ids = new ArrayList<>();
|
if(!Collections.isEmpty(list)){
|
for (SwxUser item : list){
|
ids.add(item.getId());
|
}
|
}else{
|
ids.add("");
|
}
|
queryWrapper.lambda().in(SwxSmartOrder::getUserId,ids);
|
}
|
if(swxSmartOrder.getStatus() != null){
|
queryWrapper.lambda().eq(SwxSmartOrder::getStatus,swxSmartOrder.getStatus());
|
}
|
queryWrapper.lambda().orderByDesc(SwxSmartOrder::getCreateTime);
|
Page<SwxSmartOrder> page = new Page<SwxSmartOrder>(pageNo, pageSize);
|
IPage<SwxSmartOrder> pageList = swxSmartOrderService.page(page, queryWrapper);
|
IPage<SmartOrderVo> result = new Page<>();
|
List<SmartOrderVo> records = new ArrayList<>();
|
for(SwxSmartOrder item : pageList.getRecords()){
|
SmartOrderVo vo = new SmartOrderVo();
|
BeanUtils.copyProperties(item,vo);
|
SwxUser swxUser = swxUserService.getById(item.getUserId());
|
if(swxUser != null){
|
vo.setUserName(swxUser.getUserName());
|
vo.setPhone(swxUser.getPhone());
|
}
|
records.add(vo);
|
}
|
result.setRecords(records);
|
result.setCurrent(pageList.getCurrent());
|
result.setPages(pageList.getPages());
|
result.setSize(pageList.getSize());
|
result.setTotal(pageList.getTotal());
|
return Result.OK(result);
|
}
|
|
/**
|
* 导出智能交易订单列表
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:export')")
|
@Log(title = "智能交易订单", businessType = BusinessType.EXPORT)
|
@PostMapping("/export")
|
public void export(HttpServletResponse response, SwxSmartOrder swxSmartOrder){
|
QueryWrapper<SwxSmartOrder> queryWrapper = WhereBuilder.build(swxSmartOrder);
|
List<SwxSmartOrder> list = swxSmartOrderService.list(queryWrapper);
|
ExcelUtil<SwxSmartOrder> util = new ExcelUtil<SwxSmartOrder>(SwxSmartOrder.class);
|
util.exportExcel(response, list, "智能交易订单数据");
|
}
|
|
/**
|
* 获取智能交易订单详细信息
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:query')")
|
@GetMapping(value = "/{id}")
|
public Result<SwxSmartOrder> getInfo(@PathVariable("id") String id){
|
SwxSmartOrder swxSmartOrder = swxSmartOrderService.getById(id);
|
if(swxSmartOrder==null) {
|
return Result.error("未找到对应数据");
|
}
|
return Result.OK(swxSmartOrder);
|
}
|
|
/**
|
* 新增智能交易订单
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:add')")
|
@Log(title = "智能交易订单", businessType = BusinessType.INSERT)
|
@PostMapping
|
public Result<String> add(@RequestBody SwxSmartOrder swxSmartOrder){
|
//计算当期收益
|
swxSmartOrder.setCurrentProfit(swxSmartOrder.getAmount().multiply(swxSmartOrder.getRate().add(swxSmartOrder.getAddRate())).divide(new BigDecimal(100)).multiply(BigDecimal.valueOf(swxSmartOrder.getAllDay())).setScale(2,BigDecimal.ROUND_HALF_UP));
|
swxSmartOrderService.save(swxSmartOrder);
|
return Result.ok("添加成功!");
|
}
|
|
/**
|
* 修改智能交易订单
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:edit')")
|
@Log(title = "智能交易订单", businessType = BusinessType.UPDATE)
|
@PutMapping
|
public Result<String> edit(@RequestBody SwxSmartOrder swxSmartOrder){
|
swxSmartOrderService.updateById(swxSmartOrder);
|
return Result.ok("编辑成功!");
|
}
|
|
/**
|
* 删除智能交易订单
|
*/
|
@PreAuthorize("@ss.hasPermi('swx:smartOrder:remove')")
|
@Log(title = "智能交易订单", businessType = BusinessType.DELETE)
|
@DeleteMapping("/{ids}")
|
public Result<String> remove(@PathVariable List<String> ids){
|
swxSmartOrderService.removeBatchByIds(ids);
|
return Result.ok("删除成功!");
|
}
|
|
}
|