327 lines
16 KiB
Java
327 lines
16 KiB
Java
package com.peanut.modules.master.controller;
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
import com.peanut.common.utils.R;
|
|
import com.peanut.modules.book.entity.SysDictDataEntity;
|
|
import com.peanut.modules.common.entity.MyUserEntity;
|
|
import com.peanut.modules.common.entity.UserContribution;
|
|
import com.peanut.modules.master.service.MyUserService;
|
|
import com.peanut.modules.master.service.UserContributionService;
|
|
import com.peanut.modules.sys.service.SysDictDataService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
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 javax.servlet.http.HttpServletResponse;
|
|
import java.io.OutputStream;
|
|
import java.math.BigDecimal;
|
|
import java.net.URLEncoder;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 湖分管理
|
|
*/
|
|
@Slf4j
|
|
@RestController("masterUserContribution")
|
|
@RequestMapping("master/userContribution")
|
|
public class UserContributionController {
|
|
|
|
@Autowired
|
|
private UserContributionService contributionService;
|
|
@Autowired
|
|
private MyUserService userService;
|
|
@Autowired
|
|
private SysDictDataService sysDictDataService;
|
|
|
|
//湖分标签列表
|
|
@RequestMapping("/getUserContributionLabelList")
|
|
public R getUserContributionLabelList() {
|
|
List labelList = sysDictDataService.list(new LambdaQueryWrapper<SysDictDataEntity>()
|
|
.eq(SysDictDataEntity::getDictLabel,"userContributionLabel")
|
|
.orderByAsc(SysDictDataEntity::getSort));
|
|
return R.ok().put("labelList",labelList);
|
|
}
|
|
|
|
//新增湖分标签
|
|
@RequestMapping("/addUserContributionLabelList")
|
|
public R addUserContributionLabelList(@RequestBody SysDictDataEntity sysDictDataEntity) {
|
|
sysDictDataEntity.setDictLabel("userContributionLabel");
|
|
List<SysDictDataEntity> labelList = sysDictDataService.list(new LambdaQueryWrapper<SysDictDataEntity>()
|
|
.eq(SysDictDataEntity::getDictLabel,"userContributionLabel")
|
|
.orderByDesc(SysDictDataEntity::getDictType));
|
|
if (labelList.size() > 0){
|
|
sysDictDataEntity.setDictType(Integer.valueOf(labelList.get(0).getDictType())+1+"");
|
|
}else {
|
|
sysDictDataEntity.setDictType("1");
|
|
}
|
|
sysDictDataService.save(sysDictDataEntity);
|
|
return R.ok().put("sysDictDataEntity",sysDictDataEntity);
|
|
}
|
|
|
|
//修改湖分标签
|
|
@RequestMapping("/editUserContributionLabelList")
|
|
public R editUserContributionLabelList(@RequestBody SysDictDataEntity sysDictDataEntity) {
|
|
sysDictDataService.updateById(sysDictDataEntity);
|
|
return R.ok().put("sysDictDataEntity",sysDictDataEntity);
|
|
}
|
|
|
|
//删除湖分标签
|
|
@RequestMapping("/delUserContributionLabelList")
|
|
public R delUserContributionLabelList(@RequestBody Map<String, Object> params) {
|
|
SysDictDataEntity sysDictDataEntity = sysDictDataService.getById(params.get("id").toString());
|
|
int count = contributionService.count(new LambdaQueryWrapper<UserContribution>()
|
|
.eq(UserContribution::getType,sysDictDataEntity.getDictType()));
|
|
if (count > 0){
|
|
return R.error("已存在湖分记录");
|
|
}
|
|
sysDictDataService.removeById(params.get("id").toString());
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/listByPage")
|
|
public R listByPage(@RequestBody Map<String, Object> params) {
|
|
MPJLambdaWrapper<UserContribution> wrapper = new MPJLambdaWrapper();
|
|
wrapper.selectAll(UserContribution.class);
|
|
wrapper.leftJoin(MyUserEntity.class, MyUserEntity::getId, UserContribution::getUserId);
|
|
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("userId")&& StringUtils.isNotEmpty(params.get("userId").toString())) {
|
|
wrapper.eq(MyUserEntity::getId,params.get("userId"));
|
|
}
|
|
if (params.containsKey("tel")&& StringUtils.isNotEmpty(params.get("tel").toString())) {
|
|
wrapper.like(MyUserEntity::getTel,params.get("tel"));
|
|
}
|
|
if (params.containsKey("email")&& StringUtils.isNotEmpty(params.get("email").toString())) {
|
|
wrapper.like(MyUserEntity::getEmail,params.get("email"));
|
|
}
|
|
if (params.containsKey("type")&& StringUtils.isNotEmpty(params.get("type").toString())) {
|
|
wrapper.eq(UserContribution::getType,params.get("type"));
|
|
}
|
|
wrapper.orderByDesc(UserContribution::getCreateTime);
|
|
Page<UserContribution> page = contributionService.page(new Page<>(
|
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
|
List<UserContribution> userContributions = page.getRecords();
|
|
if (userContributions.size() > 0){
|
|
for (UserContribution contribution : userContributions) {
|
|
contribution.setUser(userService.getById(contribution.getUserId()));
|
|
}
|
|
}
|
|
return R.ok().put("result", page);
|
|
}
|
|
|
|
//统计查询
|
|
@RequestMapping("/contributionStatQuery")
|
|
public R contributionStatQuery(@RequestBody Map<String, Object> params) {
|
|
return R.ok().put("result", getStatQueryData(params));
|
|
}
|
|
|
|
|
|
public Page getStatQueryData(Map<String, Object> params) {
|
|
MPJLambdaWrapper<UserContribution> wrapper = new MPJLambdaWrapper();
|
|
wrapper.leftJoin(MyUserEntity.class, MyUserEntity::getId, UserContribution::getUserId);
|
|
wrapper.select(UserContribution::getUserId);
|
|
wrapper.selectAs(MyUserEntity::getTel,"userTel");
|
|
wrapper.selectAs(MyUserEntity::getName,"userName");
|
|
wrapper.selectSum(UserContribution::getScore);
|
|
if (params.containsKey("tel")&&StringUtils.isNotEmpty(params.get("tel").toString())) {
|
|
wrapper.like(MyUserEntity::getTel,params.get("tel"));
|
|
}
|
|
wrapper.groupBy(UserContribution::getUserId);
|
|
wrapper.orderByDesc("score");
|
|
Page<UserContribution> page = contributionService.page(new Page<>(
|
|
Long.parseLong(params.get("current").toString()), Long.parseLong(params.get("limit").toString())), wrapper);
|
|
List<UserContribution> userContributions = page.getRecords();
|
|
for (UserContribution contribution : userContributions) {
|
|
String level = "";
|
|
if (contribution.getScore().compareTo(new BigDecimal(500))>=0){
|
|
level = "7星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(300))>=0){
|
|
level = "6星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(150))>=0){
|
|
level = "5星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(135))>=0){
|
|
level = "4.5星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(120))>=0){
|
|
level = "4星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(105))>=0){
|
|
level = "3.5星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(90))>=0){
|
|
level = "3星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(75))>=0){
|
|
level = "2.5星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(60))>=0){
|
|
level = "2星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(45))>=0){
|
|
level = "1.5星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(30))>=0){
|
|
level = "1星";
|
|
}else if (contribution.getScore().compareTo(new BigDecimal(15))>=0){
|
|
level = "0.5星";
|
|
}
|
|
contribution.setLevel(level);
|
|
MPJLambdaWrapper<UserContribution> mw = new MPJLambdaWrapper();
|
|
mw.leftJoin(SysDictDataEntity.class,SysDictDataEntity::getDictType,UserContribution::getType);
|
|
mw.selectAll(UserContribution.class);
|
|
mw.selectAs(SysDictDataEntity::getDictValue,"typeInfo");
|
|
mw.eq(UserContribution::getUserId,contribution.getUserId());
|
|
mw.eq(SysDictDataEntity::getDictLabel,"userContributionLabel");
|
|
mw.orderByDesc(UserContribution::getCreateTime);
|
|
List<UserContribution> cs = contributionService.list(mw);
|
|
if(params.containsKey("startTime")&&StringUtils.isNotEmpty(params.get("startTime").toString())){
|
|
BigDecimal statQueryScore = BigDecimal.ZERO;
|
|
for (UserContribution c:cs) {
|
|
if (c.getCreateTime().getTime()>=DateUtil.parse(params.get("startTime").toString(),"yyyy-MM-dd").getTime()){
|
|
c.setStatQueryFlag(1);
|
|
statQueryScore = statQueryScore.add(c.getScore());
|
|
}
|
|
}
|
|
contribution.setStatQueryScore(statQueryScore);
|
|
}
|
|
contribution.setContributions(cs);
|
|
contribution.setUser(userService.getById(contribution.getUserId()));
|
|
}
|
|
return page;
|
|
}
|
|
|
|
@RequestMapping("/exportContributionStatQuery")
|
|
public void exportContributionStatQuery(HttpServletResponse response,@RequestBody Map<String, Object> params) throws Exception {
|
|
String fileName = "湖分统计查询.xlsx";
|
|
fileName = URLEncoder.encode(fileName, "UTF-8");
|
|
response.setContentType("application/vnd.ms-excel");
|
|
response.setCharacterEncoding("utf8");
|
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
OutputStream outputStream = response.getOutputStream();
|
|
List<UserContribution> list = getStatQueryData(params).getRecords();
|
|
Workbook workbook = new HSSFWorkbook();
|
|
Sheet sheet = workbook.createSheet("Sheet1");
|
|
Row headerRow = sheet.createRow(0);// 创建表头行
|
|
Cell headerCell0 = headerRow.createCell(0);
|
|
headerCell0.setCellValue("序号");
|
|
Cell headerCell2 = headerRow.createCell(1);
|
|
headerCell2.setCellValue("姓名");
|
|
Cell headerCell3 = headerRow.createCell(2);
|
|
headerCell3.setCellValue("电话");
|
|
sheet.setColumnWidth(2,15*256);
|
|
Cell headerCell1 = headerRow.createCell(3);
|
|
headerCell1.setCellValue("星级");
|
|
Cell headerCell4 = headerRow.createCell(4);
|
|
headerCell4.setCellValue("湖分");
|
|
Cell headerCell5 = headerRow.createCell(5);
|
|
headerCell5.setCellValue("明细");
|
|
sheet.setColumnWidth(5,60*256);
|
|
// 填充数据
|
|
int no = 1;
|
|
int startI = 1;
|
|
int i = 1;
|
|
for (UserContribution userContribution : list) {
|
|
CellStyle cellStyle = workbook.createCellStyle();
|
|
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
Font font = workbook.createFont();
|
|
//涨星等级颜色变化
|
|
//半星 黄色
|
|
//一星 绿色
|
|
//一星半 红色
|
|
//二星 蓝色
|
|
if (userContribution.getStatQueryScore()!=null&&userContribution.getStatQueryScore().compareTo(BigDecimal.ZERO)>0){
|
|
if (userContribution.getScore().compareTo(new BigDecimal(150))<1){
|
|
if (userContribution.getStatQueryScore().compareTo(new BigDecimal(60))>=0){
|
|
font.setColor(IndexedColors.BLUE.getIndex());
|
|
}else if (userContribution.getStatQueryScore().compareTo(new BigDecimal(45))>=0){
|
|
font.setColor(IndexedColors.RED.getIndex());
|
|
}else if (userContribution.getStatQueryScore().compareTo(new BigDecimal(30))>=0){
|
|
font.setColor(IndexedColors.GREEN.getIndex());
|
|
}else if (userContribution.getStatQueryScore().compareTo(new BigDecimal(15))>=0){
|
|
font.setColor(IndexedColors.ORANGE.getIndex());
|
|
}
|
|
}else {
|
|
if ("6星".equals(userContribution.getLevel())){
|
|
if (userContribution.getStatQueryScore().compareTo(new BigDecimal(150))>=0){
|
|
int count = (userContribution.getStatQueryScore().subtract(new BigDecimal(150))).intValue()%15;
|
|
if (count>=2){
|
|
font.setColor(IndexedColors.BLUE.getIndex());
|
|
}else if (count>=1){
|
|
font.setColor(IndexedColors.RED.getIndex());
|
|
}else {
|
|
font.setColor(IndexedColors.GREEN.getIndex());
|
|
}
|
|
}
|
|
}
|
|
if ("7星".equals(userContribution.getLevel())){
|
|
if (userContribution.getStatQueryScore().compareTo(new BigDecimal(200))>=0){
|
|
if (userContribution.getStatQueryScore().compareTo(new BigDecimal(350))>=0){
|
|
font.setColor(IndexedColors.BLUE.getIndex());
|
|
}else {
|
|
font.setColor(IndexedColors.GREEN.getIndex());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cellStyle.setFont(font);
|
|
for (UserContribution c : userContribution.getContributions()) {
|
|
Row dataRow = sheet.createRow(i);
|
|
Cell dataCell0 = dataRow.createCell(0);
|
|
dataCell0.setCellValue(no);
|
|
dataCell0.setCellStyle(cellStyle);
|
|
Cell dataCell2 = dataRow.createCell(1);
|
|
dataCell2.setCellValue(userContribution.getUserName());
|
|
dataCell2.setCellStyle(cellStyle);
|
|
Cell dataCell3 = dataRow.createCell(2);
|
|
dataCell3.setCellValue(userContribution.getUserTel());
|
|
dataCell3.setCellStyle(cellStyle);
|
|
Cell dataCell1 = dataRow.createCell(3);
|
|
dataCell1.setCellValue(userContribution.getLevel());
|
|
dataCell1.setCellStyle(cellStyle);
|
|
Cell dataCell4 = dataRow.createCell(4);
|
|
dataCell4.setCellValue(userContribution.getScore().toString());
|
|
dataCell4.setCellStyle(cellStyle);
|
|
Cell dataCell5 = dataRow.createCell(5);
|
|
dataCell5.setCellValue(c.getTypeInfo() + "-" + c.getDetail() + "(" + c.getScore() + "分)");
|
|
if (c.getStatQueryFlag()==1){
|
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
dataCell5.setCellStyle(cellStyle);
|
|
}
|
|
i++;
|
|
}
|
|
// 合并单元格
|
|
if(startI!=i-1){
|
|
sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 0, 0));
|
|
sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 1, 1));
|
|
sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 2, 2));
|
|
sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 3, 3));
|
|
sheet.addMergedRegion(new CellRangeAddress(startI, i-1, 4, 4));
|
|
}
|
|
startI = i;
|
|
no++;
|
|
}
|
|
workbook.write(outputStream);
|
|
outputStream.close();
|
|
}
|
|
|
|
@RequestMapping("/saveUserContribution")
|
|
public R saveUserContribution(@RequestBody UserContribution contribution) {
|
|
contributionService.save(contribution);
|
|
return R.ok();
|
|
}
|
|
|
|
@RequestMapping("/delUserContribution")
|
|
public R delMessage(@RequestBody UserContribution contribution) {
|
|
contributionService.removeById(contribution.getId());
|
|
return R.ok();
|
|
}
|
|
|
|
}
|