115 lines
4.4 KiB
Java
115 lines
4.4 KiB
Java
package com.peanut.modules.master.controller;
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.common.entity.JfTransactionDetails;
|
|
import com.peanut.modules.common.entity.MyUserEntity;
|
|
import com.peanut.modules.master.service.JfTransactionDetailsService;
|
|
import com.peanut.modules.master.service.MyUserService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Description: 积分记录
|
|
*/
|
|
@Slf4j
|
|
@RestController("masterJfTransactionDetails")
|
|
@RequestMapping("master/jfTransactionDetails")
|
|
public class JfTransactionDetailsController {
|
|
|
|
@Autowired
|
|
private JfTransactionDetailsService jfService;
|
|
|
|
@Autowired
|
|
private MyUserService userService;
|
|
|
|
/**
|
|
* 列表
|
|
*/
|
|
@RequestMapping("/listByPage")
|
|
public R listByPage(@RequestBody Map<String, Object> params) {
|
|
MPJLambdaWrapper<JfTransactionDetails> wrapper = new MPJLambdaWrapper();
|
|
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,JfTransactionDetails::getUserId);
|
|
wrapper.selectAll(JfTransactionDetails.class);
|
|
if (params.containsKey("userId")&& StringUtils.isNotEmpty(params.get("userId").toString())) {
|
|
wrapper.eq(JfTransactionDetails::getUserId,params.get("userId"));
|
|
}
|
|
if (params.containsKey("userName")&& StringUtils.isNotEmpty(params.get("userName").toString())) {
|
|
wrapper.like(MyUserEntity::getName,params.get("userName"));
|
|
wrapper.like(MyUserEntity::getNickname,params.get("userName"));
|
|
}
|
|
|
|
if (params.containsKey("actType")&&StringUtils.isNotEmpty(params.get("actType").toString())) {
|
|
wrapper.eq(JfTransactionDetails::getActType,params.get("actType"));
|
|
}
|
|
if (params.containsKey("remark")&&StringUtils.isNotEmpty(params.get("remark").toString())) {
|
|
wrapper.like(JfTransactionDetails::getRemark,params.get("remark"));
|
|
}
|
|
wrapper.orderByDesc(JfTransactionDetails::getCreateTime);
|
|
Page<JfTransactionDetails> page = jfService.page(new Page<>(
|
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
|
List<JfTransactionDetails> records = page.getRecords();
|
|
if (records.size() > 0) {
|
|
for (int i=0;i<records.size();i++) {
|
|
records.get(i).setUser(userService.getById(records.get(i).getUserId()));
|
|
}
|
|
}
|
|
page.setRecords(records);
|
|
return R.ok().put("result", page);
|
|
}
|
|
|
|
@RequestMapping("/getJfTransactionDetailsById")
|
|
public R getJfTransactionDetailsById(String id) {
|
|
return R.ok().put("result", jfService.getById(id));
|
|
}
|
|
|
|
//冲扣积分
|
|
@RequestMapping("/saveJfTransactionDetails")
|
|
public R saveJfTransactionDetails(@RequestBody Map<String, Object> params) {
|
|
JfTransactionDetails jf = new JfTransactionDetails();
|
|
MyUserEntity user = userService.getById(params.get("userId").toString());
|
|
BigDecimal changeAmount = new BigDecimal(params.get("changeAmount").toString());
|
|
String actType = params.get("actType").toString();
|
|
if (actType.equals("0")) {
|
|
jf.setActType(0);
|
|
user.setJf(user.getJf().add(changeAmount));
|
|
}else {
|
|
jf.setActType(1);
|
|
user.setJf(user.getJf().subtract(changeAmount));
|
|
}
|
|
userService.updateById(user);
|
|
jf.setUserId(user.getId());
|
|
jf.setChangeAmount(changeAmount);
|
|
jf.setRemark(params.get("remark").toString());
|
|
jf.setUserBalance(user.getJf());
|
|
jfService.save(jf);
|
|
return R.ok();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping("/saveOrUpdateJfTransactionDetails")
|
|
public R saveOrUpdateJfTransactionDetails(@RequestBody JfTransactionDetails jf) {
|
|
jfService.saveOrUpdate(jf);
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/delJfTransactionDetails")
|
|
public R delJfTransactionDetails(String id) {
|
|
jfService.removeById(id);
|
|
return R.ok();
|
|
}
|
|
|
|
}
|