| | |
| | | package com.xinquan.system.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.page.PageDTO; |
| | | import com.xinquan.common.core.web.domain.AjaxResult; |
| | | import com.xinquan.common.security.service.TokenService; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.RemoteUserService; |
| | | import com.xinquan.system.api.domain.CommissionRule; |
| | | import com.xinquan.system.api.model.LoginUser; |
| | | import com.xinquan.system.domain.CommonQuestion; |
| | | import com.xinquan.system.service.CommissionRuleService; |
| | | import com.xinquan.system.service.CommonQuestionService; |
| | | import com.xinquan.system.utils.MyQrCodeUtil; |
| | | import com.xinquan.system.utils.ObsUploadUtil; |
| | | import com.xinquan.system.utils.QRCodeUtil; |
| | | import com.xinquan.system.utils.UUIDUtil; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.omg.CORBA.PRIVATE_MEMBER; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream; |
| | | import org.aspectj.weaver.loadtime.Aj; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ByteArrayResource; |
| | | import org.springframework.mock.web.MockMultipartFile; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/system/common-question") |
| | | |
| | | public class CommonQuestionController { |
| | | @Resource |
| | | private CommonQuestionService commonQuestionService; |
| | | @Resource |
| | | private CommissionRuleService commissionRuleService; |
| | | @Resource |
| | | private RemoteUserService remoteUserService; |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @PostMapping("/getQrCode") |
| | | @ApiOperation(value = "获取客服微信二维码",tags = "获取客服微信二维码") |
| | | public R getQrCode() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | if (userId==0)return R.tokenError("登录失效"); |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | CommonQuestion one = commonQuestionService.lambdaQuery().eq(CommonQuestion::getType, 2).one(); |
| | | return R.ok(one.getCustomerServiceQrCode()); |
| | | } |
| | | @GetMapping("/commonQuestion") |
| | | @ApiOperation(value = "常见问题列表", tags = {"联系客服"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<CommonQuestion>> myInviteRankList( |
| | | @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | Page<CommonQuestion> page = commonQuestionService.lambdaQuery() |
| | | .eq(CommonQuestion::getType,1) |
| | | .orderByDesc(CommonQuestion::getSortNum) |
| | | .orderByDesc(CommonQuestion::getCreateTime) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | return R.ok(PageDTO.of(page, CommonQuestion.class)); |
| | | } |
| | | @GetMapping("/commonQuestionList") |
| | | @ApiOperation(value = "常见问题列表-分页", tags = {"管理后台-常见问题"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "分页参数,当前页码", name = "pageCurr", required = true, dataType = "Integer"), |
| | | @ApiImplicitParam(value = "分页参数,每页数量", name = "pageSize", required = true, dataType = "Integer") |
| | | }) |
| | | public R<PageDTO<CommonQuestion>> commonQuestionList( |
| | | @RequestParam(value = "pageCurr", defaultValue = "1") Integer pageCurr, |
| | | @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | Page<CommonQuestion> page = commonQuestionService.lambdaQuery() |
| | | .eq(CommonQuestion::getType,1) |
| | | .orderByDesc(CommonQuestion::getCreateTime) |
| | | .page(new Page<>(pageCurr, pageSize)); |
| | | if (page.getRecords().isEmpty()){ |
| | | return R.ok(PageDTO.empty(page)); |
| | | } |
| | | for (CommonQuestion record : page.getRecords()) { |
| | | record.setUid(record.getId() + ""); |
| | | } |
| | | return R.ok(PageDTO.of(page, CommonQuestion.class)); |
| | | } |
| | | @GetMapping("/detailKfCode") |
| | | @ApiOperation(value = "查看详情客服微信", tags = "管理后台-常见问题") |
| | | public R<CommonQuestion> detailKfCode() { |
| | | CommonQuestion one = commonQuestionService.lambdaQuery() |
| | | .eq(CommonQuestion::getType, 2).one(); |
| | | if (one == null){ |
| | | return R.ok(new CommonQuestion()); |
| | | } |
| | | one.setUid(one.getId()+""); |
| | | return R.ok(one); |
| | | } |
| | | @GetMapping("/updateKfCode") |
| | | @ApiOperation(value = "修改/新增客服微信", tags = "管理后台-常见问题") |
| | | public R<CommonQuestion> updateKfCode(String customerServiceQrCode) { |
| | | CommonQuestion one = commonQuestionService.lambdaQuery() |
| | | .eq(CommonQuestion::getType, 2).one(); |
| | | if (one == null){ |
| | | // 新增 |
| | | CommonQuestion commonQuestion = new CommonQuestion(); |
| | | commonQuestion.setCustomerServiceQrCode(customerServiceQrCode); |
| | | commonQuestion.setType(2); |
| | | commonQuestionService.save(commonQuestion); |
| | | }else{ |
| | | // 编辑 |
| | | one.setCustomerServiceQrCode(customerServiceQrCode); |
| | | commonQuestionService.updateById(one); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | @PostMapping("/addCommonQuestion") |
| | | @ApiOperation(value = "新增常见问题", tags = "管理后台-常见问题") |
| | | public R addCommonQuestion(@RequestBody CommonQuestion homeBackgroundMusic) { |
| | | return R.ok(commonQuestionService.save(homeBackgroundMusic)); |
| | | } |
| | | |
| | | @GetMapping("/detailCommonQuestion") |
| | | @ApiOperation(value = "查看详情常见问题", tags = "管理后台-常见问题") |
| | | public R<CommonQuestion> detailCommonQuestion(String uid) { |
| | | return R.ok(commonQuestionService.getById(uid)); |
| | | } |
| | | @PostMapping("/updateCommonQuestion") |
| | | @ApiOperation(value = "修改常见问题", tags = "管理后台-常见问题") |
| | | public R updateCommonQuestion(@RequestBody CommonQuestion homeBackgroundMusic) { |
| | | return R.ok(commonQuestionService.updateById(homeBackgroundMusic)); |
| | | } |
| | | @PostMapping("/deleteCommonQuestion") |
| | | @ApiOperation(value = "批量删除", tags = "管理后台-常见问题") |
| | | public R deleteCommonQuestion(String ids) { |
| | | return R.ok(commonQuestionService.removeBatchByIds(Arrays.asList(ids.split(",")).stream().map(Long::valueOf).collect(Collectors.toList()))); |
| | | } |
| | | @PostMapping("/getQuestionById") |
| | | @ApiOperation(value = "常见问题列表-查看详情", tags = {"联系客服"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(value = "id", name = "id", required = true, dataType = "Integer"), |
| | | }) |
| | | public R<CommonQuestion> myInviteRankList(Long id) { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | CommonQuestion byId = commonQuestionService.getById(id); |
| | | return R.ok(byId); |
| | | } |
| | | @PostMapping("/getCommissionRule") |
| | | @ApiOperation(value = "推广活动页",tags = "推广活动页") |
| | | public R<CommissionRule> getCommissionRule() throws Exception { |
| | | LoginUser loginUser = tokenService.getLoginUser(); |
| | | if (loginUser==null){ |
| | | return R.tokenError("登录失效"); |
| | | } |
| | | Long userId = loginUser.getUserid(); |
| | | |
| | | CommissionRule one = commissionRuleService.lambdaQuery().one(); |
| | | HashMap<String, String> blueCode = new HashMap<>(); |
| | | blueCode.put("user_id", userId + ""); |
| | | String blueS = "http://113.45.158.158/share/#/pages/register/register?userId="+userId; |
| | | |
| | | MyQrCodeUtil.createCodeToFile(blueS); |
| | | BufferedImage blueImage = QRCodeUtil.createImage(blueS); |
| | | MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | String s = ObsUploadUtil.obsUpload(blueFile); |
| | | one.setQrCode(s); |
| | | return R.ok(one); |
| | | } |
| | | |
| | | public static void main(String[] args) throws Exception { |
| | | HashMap<String, String> blueCode = new HashMap<>(); |
| | | blueCode.put("url", "https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/apkAndroid.apk"); |
| | | String blueS = "https://xqgwzh.obs.cn-south-1.myhuaweicloud.com/apkAndroid.apk"; |
| | | MyQrCodeUtil.createCodeToFile(blueS); |
| | | BufferedImage blueImage = QRCodeUtil.createImage(blueS); |
| | | MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | String s = ObsUploadUtil.obsUpload(blueFile); |
| | | System.err.println(s); |
| | | } |
| | | @PostMapping("/getCommissionRuleShare") |
| | | @ApiOperation(value = "推广活动页",tags = "H5分享") |
| | | public R<CommissionRule> getCommissionRuleShare(String userId) throws Exception { |
| | | CommissionRule one = commissionRuleService.lambdaQuery().one(); |
| | | HashMap<String, String> blueCode = new HashMap<>(); |
| | | blueCode.put("user_id", userId + ""); |
| | | String blueS = "http://113.45.158.158/share/#/pages/register/register?userId="+userId; |
| | | MyQrCodeUtil.createCodeToFile(blueS); |
| | | BufferedImage blueImage = QRCodeUtil.createImage(blueS); |
| | | MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG"); |
| | | String s = ObsUploadUtil.obsUpload(blueFile); |
| | | one.setQrCode(s); |
| | | return R.ok(one); |
| | | } |
| | | public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException { |
| | | // 将 BufferedImage 转换为字节数组 |
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| | | ImageIO.write(bufferedImage, "png", baos); |
| | | byte[] bytes = baos.toByteArray(); |
| | | |
| | | // 创建 ByteArrayResource |
| | | ByteArrayResource resource = new ByteArrayResource(bytes); |
| | | |
| | | // 创建 MockMultipartFile |
| | | MockMultipartFile multipartFile = new MockMultipartFile( |
| | | "file", |
| | | fileName, |
| | | "image/png", |
| | | resource.getInputStream() |
| | | ); |
| | | |
| | | return multipartFile; |
| | | } |
| | | } |
| | | |