| | |
| | | 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.core.util.RandomUtil; |
| | | import cn.hutool.crypto.SecureUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.enums.UserStatus; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.WebUtils; |
| | | import com.ruoyi.system.export.BigGiftPackageImport; |
| | | import com.ruoyi.system.export.SysUserImport; |
| | | import com.ruoyi.system.model.TBigGiftPackage; |
| | | import com.ruoyi.system.model.TCompany; |
| | | import com.ruoyi.system.model.TPhysicalGoods; |
| | | import com.ruoyi.system.query.BigGiftPackageQuery; |
| | | import com.ruoyi.system.query.CompanyUserQuery; |
| | | import com.ruoyi.system.query.TCompanyQuery; |
| | | import com.ruoyi.system.service.ISysUserService; |
| | | import com.ruoyi.system.service.TCompanyService; |
| | | import com.ruoyi.system.service.TPhysicalGoodsService; |
| | | import com.ruoyi.system.query.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.ProfitPageListVo; |
| | | import com.ruoyi.system.vo.PromotionPageListVo; |
| | | import com.ruoyi.system.vo.SysUserVO; |
| | | import com.ruoyi.web.controller.system.SysUserController; |
| | | 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.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.text.MessageFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | private final TCompanyService companyService; |
| | | private final ISysUserService userService; |
| | | private final RedisTemplate redisTemplate; |
| | | private final TAppUserService appUserService ; |
| | | private final TBigGiftPackageOrderService bigGiftPackageOrderService; |
| | | |
| | | |
| | | public TCompanyController(TCompanyService companyService, ISysUserService userService, RedisTemplate redisTemplate) { |
| | | public TCompanyController(TCompanyService companyService, ISysUserService userService, RedisTemplate redisTemplate, TAppUserService appUserService, TBigGiftPackageOrderService bigGiftPackageOrderService) { |
| | | this.companyService = companyService; |
| | | this.userService = userService; |
| | | this.redisTemplate = redisTemplate; |
| | | this.appUserService = appUserService; |
| | | this.bigGiftPackageOrderService = bigGiftPackageOrderService; |
| | | } |
| | | |
| | | @ApiOperation(value = "公司分页列表") |
| | |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); |
| | | } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | }else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkCodeUnique(user)) { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,推广码已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | |
| | | @ApiOperation(value = "公司需求--管理人员获取二维码") |
| | | @GetMapping(value = "/getQrcode") |
| | | public R<String> getQrcode(@RequestParam Long userId) { |
| | | Object o = redisTemplate.opsForValue().get("ADMIN_WX_IMG" + userId); |
| | | SysUser sysUser = userService.selectUserById(userId); |
| | | Object o = redisTemplate.opsForValue().get("ADMIN_WX_IMG" + sysUser.getUserId()); |
| | | if(o!=null){ |
| | | return R.ok(o.toString()); |
| | | } |
| | |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("page", "pages/home/home"); |
| | | param.put("width", 430); //二维码尺寸 |
| | | param.put("scene", "userId=" + userId); //二维码尺寸 |
| | | param.put("scene", "code=" + sysUser.getCode()+"&type=1"); //二维码尺寸 |
| | | param.put("env_version", "trial"); //二维码尺寸 |
| | | param.put("check_path", false); //二维码尺寸 |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.body(JSON.toJSONString(param)); |
| | | |
| | | byte[] result = post.execute().bodyBytes(); |
| | | HttpResponse execute = post.execute(); |
| | | byte[] result =execute .bodyBytes(); |
| | | // base64 |
| | | String img = Base64.getEncoder().encodeToString(result); |
| | | // 后台用户的小程序码 |
| | |
| | | { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | else if (StringUtils.isNotEmpty(user.getCode()) && !userService.checkCodeUnique(user)) |
| | | { |
| | | return R.fail("新增用户'" + user.getUserName() + "'失败,推广号已存在"); |
| | | } |
| | | user.setCreateBy(getUsername()); |
| | | user.setPassword(SecurityUtils.encryptPassword("123456")); |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | |
| | | user.setRoleType(3); |
| | | user.setRoleId(1l); |
| | | // 随机10数数字 |
| | | user.setCode(RandomUtil.randomNumbers(10)); |
| | | userService.insertUser(user); |
| | | if(user.getCompanyId()!=null){ |
| | | String accessToken = getAccessToken(); |
| | |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("page", "pages/home/home"); |
| | | param.put("width", 430); //二维码尺寸 |
| | | param.put("scene", "userId=" + user.getUserId()); //二维码尺寸 |
| | | param.put("scene", "code=" + user.getCode()+"&type=1"); //二维码尺寸 |
| | | param.put("env_version", "trial"); //二维码尺寸 |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.body(JSON.toJSONString(param)); |
| | |
| | | { |
| | | return R.fail("修改用户'" + user.getUserName() + "'失败,手机号码已存在"); |
| | | } |
| | | |
| | | user.setUpdateBy(getUsername()); |
| | | if(StringUtils.isNotEmpty(user.getPassword())){ |
| | | user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); |
| | | } |
| | | // 移除之前的二维码 |
| | | redisTemplate.delete("ADMIN_WX_IMG" + user.getUserId()); |
| | | return R.ok(userService.updateUser(user)); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | @Log(title = "股东-导入", businessType = BusinessType.IMPORT) |
| | | @ApiOperation(value = "股东-导入") |
| | | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) |
| | | @PostMapping("/import") |
| | | public R<String> importInfo(@RequestPart("file") MultipartFile file, @RequestParam Integer companyId) { |
| | | List<SysUserImport> imports = new ArrayList<>(); |
| | | ImportParams params = new ImportParams(); |
| | | params.setHeadRows(1); //表头行数 |
| | | InputStream inputStream = null; |
| | | try { |
| | | inputStream = file.getInputStream(); |
| | | imports = ExcelImportUtil.importExcel(inputStream, |
| | | SysUserImport.class, params); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new ServiceException("股东导入失败!"); |
| | | } finally { |
| | | try { |
| | | inputStream.close(); |
| | | } catch (IOException e) { |
| | | throw new ServiceException(e.getMessage()); |
| | | } |
| | | } |
| | | if (CollectionUtils.isEmpty(imports)) { |
| | | throw new ServiceException("股东数据为空!"); |
| | | } |
| | | cn.hutool.json.JSONObject result = new cn.hutool.json.JSONObject(); |
| | | int i = 1; |
| | | for (SysUserImport sysUserImport : imports) { |
| | | if (!org.springframework.util.StringUtils.hasLength(sysUserImport.getUserName())){ |
| | | result.append("第"+i+"行:[", "人员名称"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!org.springframework.util.StringUtils.hasLength(sysUserImport.getCode())){ |
| | | result.append("第"+i+"行:[", "推广号"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!org.springframework.util.StringUtils.hasLength(sysUserImport.getPhone())){ |
| | | result.append("第"+i+"行:[", "联系电话"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!org.springframework.util.StringUtils.hasLength(sysUserImport.getAccount())){ |
| | | result.append("第"+i+"行:[", "登录账号"+"]不能为空"); |
| | | continue; |
| | | } |
| | | if (!org.springframework.util.StringUtils.hasLength(sysUserImport.getPassword())){ |
| | | result.append("第"+i+"行:[", "初始密码"+"]不能为空"); |
| | | continue; |
| | | } |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserName(sysUserImport.getAccount()); |
| | | if(!userService.checkUserNameUnique(sysUser)){ |
| | | result.append("第"+i+"行:[", "登录账号"+"]已存在"); |
| | | continue; |
| | | } |
| | | sysUser.setNickName(sysUserImport.getUserName()); |
| | | sysUser.setPhonenumber(sysUserImport.getPhone()); |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(sysUserImport.getPassword())); |
| | | sysUser.setCompanyId(companyId); |
| | | sysUser.setRemark(sysUserImport.getRemark()); |
| | | sysUser.setCode(sysUserImport.getCode()); |
| | | if(!userService.checkCodeUnique(sysUser)){ |
| | | result.append("第"+i+"行:[", "推广号"+"]已存在"); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | sysUser.setCreateBy(getUsername()); |
| | | sysUser.setRoleType(3); |
| | | sysUser.setRoleId(1L); |
| | | // sysUsers.add(sysUser); |
| | | userService.insertUser(sysUser); |
| | | i++; |
| | | } |
| | | |
| | | if(!result.isEmpty()){ |
| | | return R.fail(result.toString()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "推广记录") |
| | | @PostMapping("/promotionPageList") |
| | | public R<Page<PromotionPageListVo>> promotionPageList(@RequestBody @Valid PromotionPageListQuery query) { |
| | | Page<PromotionPageListVo> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | List<PromotionPageListVo> list = appUserService.promotionPageList(page,query); |
| | | page.setRecords(list); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value = "推广记录导出") |
| | | @PostMapping(value = "/export") |
| | | @Log(title = "推广记录-导出", businessType = BusinessType.EXPORT) |
| | | public void export(@RequestBody @Valid PromotionPageListQuery query){ |
| | | |
| | | List<PromotionPageListVo> list = appUserService.promotionPageListExport(query); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), PromotionPageListVo.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 = "收益明细") |
| | | @PostMapping("/profitPageList") |
| | | public R<Page<ProfitPageListVo>> profitPageList(@RequestBody @Valid ProfitPageListQuery query) { |
| | | Page<ProfitPageListVo> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | List<ProfitPageListVo> list = bigGiftPackageOrderService.profitPageList(page,query); |
| | | |
| | | page.setRecords(list); |
| | | return R.ok(page); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "收益明细导出") |
| | | @PostMapping(value = "/exportProfit") |
| | | @Log(title = "收益明细-导出", businessType = BusinessType.EXPORT) |
| | | public void exportProfit(@RequestBody @Valid ProfitPageListQuery query){ |
| | | |
| | | List<ProfitPageListVo> list = bigGiftPackageOrderService.profitPageListExport(query); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ProfitPageListVo.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(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |