| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.ExcelImportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import cn.afterturn.easypoi.excel.entity.ImportParams; |
| | | import cn.hutool.json.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.BatchUpdateIntegralDto; |
| | | import com.ruoyi.system.dto.UpdateAppUserDto; |
| | | import com.ruoyi.system.export.AppUserGoldImport; |
| | | import com.ruoyi.system.export.AppUserImport; |
| | | import com.ruoyi.system.model.TAppUser; |
| | | import com.ruoyi.system.model.TCompany; |
| | | import com.ruoyi.system.model.TGoldChangeRecord; |
| | | import com.ruoyi.system.export.BigGiftPackageImport; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.AppUserListQuery; |
| | | import com.ruoyi.system.query.BigGiftPackageQuery; |
| | | import com.ruoyi.system.service.TAppUserService; |
| | | import com.ruoyi.system.service.TCompanyService; |
| | | import com.ruoyi.system.service.TGoldChangeRecordService; |
| | | import com.ruoyi.system.service.TIntegralChangeRecordService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.URLEncoder; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Autowired |
| | | private TGoldChangeRecordService goldChangeRecordService; |
| | | |
| | | @Autowired |
| | | private TIntegralChangeRecordService integralChangeRecordService; |
| | | |
| | | |
| | | @ApiOperation(value = "用户管理分页列表") |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @Log(title = "小程序用户-用户导入", businessType = BusinessType.IMPORT) |
| | | @ApiOperation(value = "小程序用户-用户导入") |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "小程序用户导出") |
| | | @PostMapping(value = "/exportAppUser") |
| | | @Log(title = "小程序用户-导出", businessType = BusinessType.EXPORT) |
| | | public void exportAppUser(@RequestBody AppUserListQuery query) { |
| | | |
| | | List<TAppUser> list = appUserService.exportAppUser(query); |
| | | |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TAppUser.class, list); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | assert response != null; |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("小程序用户导出信息.xls", "utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "一键清空金币") |
| | | @GetMapping(value = "/clearGold") |
| | | @Log(title = "小程序用户-一键清空金币", businessType = BusinessType.UPDATE) |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | public R clearGold() { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | List<TAppUser> list = appUserService.list(); |
| | | |
| | | ArrayList<TGoldChangeRecord> tGoldChangeRecords = new ArrayList<>(); |
| | | for (TAppUser user : list) { |
| | | |
| | | TGoldChangeRecord tGoldChangeRecord = new TGoldChangeRecord(); |
| | | tGoldChangeRecord.setAppUserId(user.getId()); |
| | | tGoldChangeRecord.setPrice(user.getGoldBalance()); |
| | | tGoldChangeRecord.setBalance(BigDecimal.ZERO); |
| | | tGoldChangeRecord.setType(2); |
| | | tGoldChangeRecord.setCreateUserId(userId); |
| | | tGoldChangeRecords.add(tGoldChangeRecord); |
| | | } |
| | | |
| | | goldChangeRecordService.saveBatch(tGoldChangeRecords); |
| | | appUserService.update(new LambdaUpdateWrapper<TAppUser>().set(TAppUser::getGoldBalance, 0)); |
| | | return R.ok(); |
| | | |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "批量修改积分") |
| | | @PostMapping(value = "/batchUpdateGold") |
| | | @Log(title = "小程序用户-批量修改积分", businessType = BusinessType.UPDATE) |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | public R batchUpdateGold(@RequestBody BatchUpdateIntegralDto dto) { |
| | | Long userId = tokenService.getLoginUser().getUserId(); |
| | | List<Integer> userIds = dto.getUserIds(); |
| | | List<TAppUser> tAppUsers = appUserService.listByIds(userIds); |
| | | List<TIntegralChangeRecord> tIntegralChangeRecords = new ArrayList<>(); |
| | | for (TAppUser tAppUser : tAppUsers) { |
| | | TIntegralChangeRecord tIntegralChangeRecord = new TIntegralChangeRecord(); |
| | | tIntegralChangeRecord.setAppUserId(tAppUser.getId()); |
| | | tIntegralChangeRecord.setOldBalance(new BigDecimal(tAppUser.getAccumulativeIntegral())); |
| | | tIntegralChangeRecord.setPrice(new BigDecimal(dto.getIntegral())); |
| | | tIntegralChangeRecord.setCreateUserId(userId); |
| | | tIntegralChangeRecords.add(tIntegralChangeRecord); |
| | | |
| | | tAppUser.setAccumulativeIntegral(dto.getIntegral()); |
| | | } |
| | | integralChangeRecordService.saveBatch(tIntegralChangeRecords); |
| | | appUserService.updateBatchById(tAppUsers); |
| | | return R.ok(); |
| | | |
| | | |
| | | } |
| | | } |
| | | |