From a22ea3bcf7e36d00142074208c7dffdbd70fcd44 Mon Sep 17 00:00:00 2001 From: YXY <932687738@qq.com> Date: Sun, 20 Aug 2023 16:13:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-common/pom.xml | 6 + .../ruoyi/common/enums/LarkActiveEnum.java | 44 ++++++ .../common/enums/LarkActiveTypeEnum.java | 2 +- .../ruoyi/common/enums/LarkUserTypeEnum.java | 30 ++++ .../com/ruoyi/common/utils/ExportUtils.java | 22 +++ .../utils/excelStrategy/CustomMerge.java | 25 ++++ .../excelStrategy/CustomMergeStrategy.java | 135 ++++++++++++++++++ ruoyi-flyingbook/pom.xml | 6 + .../controller/LarkActiveController.java | 60 ++++++-- .../ruoyi/flyingbook/domain/LarkLoginLog.java | 43 ++++++ .../domain/larkactive/LarkActiveCountVo.java | 43 ++++-- .../domain/larkactive/LarkSessionRequest.java | 1 + .../flyingbook/mapper/LarkActiveMapper.java | 5 +- .../flyingbook/mapper/LarkLoginLogMapper.java | 64 +++++++++ .../service/ILarkLoginLogService.java | 63 ++++++++ .../ILarkUserActiveRelatoinService.java | 2 +- .../service/impl/LarkLoginLogServiceImpl.java | 97 +++++++++++++ .../LarkUserActiveRelatoinServiceImpl.java | 78 +++++++--- .../resources/mapper/LarkActiveMapper.xml | 10 +- .../resources/mapper/LarkLoginLogMapper.xml | 113 +++++++++++++++ .../mapper/LarkUserActiveRelatoinMapper.xml | 1 - 21 files changed, 793 insertions(+), 57 deletions(-) create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkUserTypeEnum.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/ExportUtils.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMerge.java create mode 100644 ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMergeStrategy.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkLoginLog.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkLoginLogMapper.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkLoginLogService.java create mode 100644 ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkLoginLogServiceImpl.java create mode 100644 ruoyi-flyingbook/src/main/resources/mapper/LarkLoginLogMapper.xml diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index a718db2..aa5c354 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -158,6 +158,12 @@ org.freemarker freemarker + + com.alibaba + easyexcel-core + 3.1.1 + compile + diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveEnum.java new file mode 100644 index 0000000..8b00f08 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveEnum.java @@ -0,0 +1,44 @@ +package com.ruoyi.common.enums; + +/** + * 飞书活动类型 + * + * @author ruoyi + */ +public enum LarkActiveEnum { + + /** + * + */ + MOOC("MOOC", "MOOC"), + FUN_KNOWLEDGE("FunKnowledge", "知识竞赛"), + NITPICK("Nitpick", "信息安全找茬活动"), + VIDEO("Video", "看信息安全通识视频"), + AI("AI", "AI应用创意畅想"), + INFORMATION_SECURITY("InformationSecurity", "信息安全风险提报"); + + private final String code; + private final String info; + + LarkActiveEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } + + public static LarkActiveEnum getByCode(String code){ + for (LarkActiveEnum value : LarkActiveEnum.values()) { + if (value.getCode().equals(code)){ + return value; + } + } + return null; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveTypeEnum.java index ad04475..15cf2c4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveTypeEnum.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkActiveTypeEnum.java @@ -10,7 +10,7 @@ public enum LarkActiveTypeEnum { /** * */ - DEFAULT("DEFAULT", "正常"); + LARK_APP_TYPE("LARK_APP_TYPE", "默认飞书小程序"); private final String code; private final String info; diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkUserTypeEnum.java b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkUserTypeEnum.java new file mode 100644 index 0000000..4419976 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/enums/LarkUserTypeEnum.java @@ -0,0 +1,30 @@ +package com.ruoyi.common.enums; + +/** + * 飞书活动类型 + * + * @author ruoyi + */ +public enum LarkUserTypeEnum { + + /** + * + */ + LARK_APP("LARK_APP", "飞书小程序"); + + private final String code; + private final String info; + + LarkUserTypeEnum(String code, String info) { + this.code = code; + this.info = info; + } + + public String getCode() { + return code; + } + + public String getInfo() { + return info; + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ExportUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ExportUtils.java new file mode 100644 index 0000000..daaaf8e --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ExportUtils.java @@ -0,0 +1,22 @@ +package com.ruoyi.common.utils; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import javax.servlet.http.HttpServletResponse; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +@Slf4j +public class ExportUtils { + + @SneakyThrows(UnsupportedEncodingException.class) + public static void writeFile(HttpServletResponse response, String fileName) { + + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8' '" + fileName + ".xlsx"); + } + +} \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMerge.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMerge.java new file mode 100644 index 0000000..6726a5a --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMerge.java @@ -0,0 +1,25 @@ +package com.ruoyi.common.utils.excelStrategy; + +import java.lang.annotation.*; + +/** + * 标记方法从缓存中获取 + * @author yuxiangyong + * @create 2022-10-08 13:49 + */ +@Inherited +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface CustomMerge { + + /** + * 是否需要合并单元格 + */ + boolean needMerge() default false; + + /** + * 是否是主键,即改字段相同的行合并 + */ + boolean isPk() default false; + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMergeStrategy.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMergeStrategy.java new file mode 100644 index 0000000..19ff4a7 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/excelStrategy/CustomMergeStrategy.java @@ -0,0 +1,135 @@ +package com.ruoyi.common.utils.excelStrategy; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.write.handler.RowWriteHandler; +import com.alibaba.excel.write.metadata.holder.WriteSheetHolder; +import com.alibaba.excel.write.metadata.holder.WriteTableHolder; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.util.CellRangeAddress; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; + +/** + * excel导出的策略类-相同的行进行合并 + * @see com.commons.annotation.CustomMerge + * @author yuxiangyong + * @create 2022-10-09 13:41 + */ +public class CustomMergeStrategy implements RowWriteHandler { + + /** + * 主键下标 + */ + private Integer pkIndex; + + /** + * 需要合并的列的下标集合 + */ + private List needMergeColumnIndex = new ArrayList<>(); + + /** + * DTO数据类型 + */ + private Class elementType; + + public CustomMergeStrategy(Class elementType) { + this.elementType = elementType; + } + + @Override + public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer relativeRowIndex, Boolean isHead) { + // 如果是标题,则直接返回 + if (isHead) { + return; + } + + // 获取当前sheet + Sheet sheet = writeSheetHolder.getSheet(); + + // 获取标题行 + Row titleRow = sheet.getRow(0); + + if (null == pkIndex) { + this.lazyInit(writeSheetHolder); + } + + // 判断是否需要和上一行进行合并 + // 不能和标题合并,只能数据行之间合并 + if (row.getRowNum() <= 1) { + return; + } + // 获取上一行数据 + Row lastRow = sheet.getRow(row.getRowNum() - 1); + // 将本行和上一行是同一类型的数据(通过主键字段进行判断),则需要合并 + if (lastRow.getCell(pkIndex).getStringCellValue().equalsIgnoreCase(row.getCell(pkIndex).getStringCellValue())) { + for (Integer needMerIndex : needMergeColumnIndex) { + CellRangeAddress cellRangeAddress = new CellRangeAddress(row.getRowNum() - 1, row.getRowNum(), + needMerIndex, needMerIndex); + sheet.addMergedRegionUnsafe(cellRangeAddress); + } + } + } + + /** + * 初始化主键下标和需要合并字段的下标 + */ + private void lazyInit(WriteSheetHolder writeSheetHolder) { + + // 获取当前sheet + Sheet sheet = writeSheetHolder.getSheet(); + + // 获取标题行 + Row titleRow = sheet.getRow(0); + // 获取DTO的类型 + Class eleType = this.elementType; + + // 获取DTO所有的属性 + Field[] fields = eleType.getDeclaredFields(); + + // 遍历所有的字段,因为是基于DTO的字段来构建excel,所以字段数 >= excel的列数 + for (Field theField : fields) { + // 获取@ExcelProperty注解,用于获取该字段对应在excel中的列的下标 + ExcelProperty easyExcelAnno = theField.getAnnotation(ExcelProperty.class); + // 为空,则表示该字段不需要导入到excel,直接处理下一个字段 + if (null == easyExcelAnno) { + continue; + } + // 获取自定义的注解,用于合并单元格 + CustomMerge customMerge = theField.getAnnotation(CustomMerge.class); + + // 没有@CustomMerge注解的默认不合并 + if (null == customMerge) { + continue; + } + + for (int index = 0; index < fields.length; index++) { + Cell theCell = titleRow.getCell(index); + // 当配置为不需要导出时,返回的为null,这里作一下判断,防止NPE + if (null == theCell) { + continue; + } + // 将字段和excel的表头匹配上 + if (easyExcelAnno.value()[0].equalsIgnoreCase(theCell.getStringCellValue())) { + if (customMerge.isPk()) { + pkIndex = index; + } + + if (customMerge.needMerge()) { + needMergeColumnIndex.add(index); + } + } + } + } + + // 没有指定主键,则异常 + if (null == this.pkIndex) { + throw new IllegalStateException("使用@CustomMerge注解必须指定主键"); + } + + } + +} diff --git a/ruoyi-flyingbook/pom.xml b/ruoyi-flyingbook/pom.xml index 9893767..c3e4170 100644 --- a/ruoyi-flyingbook/pom.xml +++ b/ruoyi-flyingbook/pom.xml @@ -76,6 +76,12 @@ cos_api 5.6.155 + + + com.alibaba + easyexcel + 3.1.1 + diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/LarkActiveController.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/LarkActiveController.java index b0bcb40..8fac5be 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/LarkActiveController.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/controller/LarkActiveController.java @@ -1,6 +1,13 @@ package com.ruoyi.flyingbook.controller; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.support.ExcelTypeEnum; import com.lark.oapi.service.authen.v1.model.CreateAccessTokenRespBody; +import com.lark.oapi.service.contact.v3.model.GetUserRespBody; +import com.lark.oapi.service.contact.v3.model.User; +import com.ruoyi.common.enums.LarkUserTypeEnum; +import com.ruoyi.common.utils.ExportUtils; +import com.ruoyi.common.utils.excelStrategy.CustomMergeStrategy; import com.ruoyi.flyingbook.CosHelper.CosHelper; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.enums.FlagStatus; @@ -9,12 +16,14 @@ import com.ruoyi.common.enums.LarkActiveStageEnum; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.flyingbook.LarkHelper.LarkUserHelper; import com.ruoyi.flyingbook.domain.LarkActive; +import com.ruoyi.flyingbook.domain.LarkLoginLog; import com.ruoyi.flyingbook.domain.LarkUserActiveInviteRelatoin; import com.ruoyi.flyingbook.domain.LarkUserActiveRelatoin; import com.ruoyi.flyingbook.domain.edi.ResponseVo; import com.ruoyi.flyingbook.domain.lark.LarkUserRequest; import com.ruoyi.flyingbook.domain.larkactive.*; import com.ruoyi.flyingbook.service.ILarkActiveService; +import com.ruoyi.flyingbook.service.ILarkLoginLogService; import com.ruoyi.flyingbook.service.ILarkUserActiveInviteRelatoinService; import com.ruoyi.flyingbook.service.ILarkUserActiveRelatoinService; import lombok.extern.slf4j.Slf4j; @@ -23,7 +32,9 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.util.Arrays; import java.util.Date; import java.util.Enumeration; import java.util.List; @@ -42,19 +53,34 @@ public class LarkActiveController extends BaseController { @Autowired private LarkUserHelper larkUserHelper; @Autowired + private ILarkLoginLogService larkLoginLogService; + @Autowired private CosHelper cosHelper; - private static final String APP_ID = "cli_a482a8572cbc9013"; - private static final String APP_SECRET = "lZNXbCLlOslWbwBIVc4qvgxOdnfA8Mos"; + private static final String APP_ID = "cli_a4504c9fe9f95013"; + private static final String APP_SECRET = "oWiLzl2Tkt68tvZHjQIfOb27rPQkTUhu"; /** * 分页查询活动 */ @PostMapping("/getSession") - public ResponseVo getSession(@RequestBody LarkSessionRequest request) { + public ResponseVo getSession(@RequestBody LarkSessionRequest request) { LarkSessionResponse larkSessionResponse = larkUserHelper.tokenLoginValidate(new LarkUserRequest(APP_ID, APP_SECRET, null, request.getCode())); - CreateAccessTokenRespBody userToken = larkUserHelper.getUserToken(new LarkUserRequest(APP_ID, APP_SECRET, larkSessionResponse.getData().getOpen_id())); - return new ResponseVo<>(userToken); + String openId = larkSessionResponse.getData().getOpen_id(); + GetUserRespBody userInfoDetail = larkUserHelper.getUserInfoDetail(new LarkUserRequest(APP_ID, APP_SECRET, openId)); + User user = userInfoDetail.getUser(); + LarkLoginLog larkLoginLog = new LarkLoginLog(); + larkLoginLog.setFlag(FlagStatus.OK.getCode()); + larkLoginLog.setCompanyName(request.getCompanyName()); + larkLoginLog.setImageUrl(user.getAvatar().getAvatarOrigin()); + larkLoginLog.setCreateTime(new Date()); + larkLoginLog.setUserName(user.getName()); + larkLoginLog.setOpenId(openId); + larkLoginLog.setType(LarkUserTypeEnum.LARK_APP.getCode()); + larkLoginLog.setCreateBy(user.getName()); + larkLoginLog.setCreateTime(new Date()); + larkLoginLogService.insertLarkLoginLog(larkLoginLog); + return new ResponseVo<>(user); } /** @@ -78,11 +104,12 @@ public class LarkActiveController extends BaseController { * 上传活动图片 */ @PostMapping("/uploadActiveFile") - public ResponseVo uploadActiveFile(@RequestParam("file") MultipartFile file,@RequestParam("userName")String userName,@RequestParam("larkActiveName") String larkActiveName) { + public ResponseVo uploadActiveFile(@RequestParam("file") MultipartFile file,@RequestParam("userName")String userName,@RequestParam("larkActiveName") String larkActiveName,@RequestParam("companyName") String companyName) { LarkActiveUserRelationRequest request = new LarkActiveUserRelationRequest(); request.setFile(file); request.setUserName(userName); request.setLarkActiveName(larkActiveName); + request.setCompanyName(companyName); return larkUserActiveRelatoinService.commitFile(request); } @@ -126,10 +153,23 @@ public class LarkActiveController extends BaseController { /** * 查询后台需要的数据 */ - @PostMapping("/queryCount") - public ResponseVo queryCount(@RequestBody LarkUserActiveRelatoin request) { - LarkActiveCountVo larkActiveCountVo = larkUserActiveRelatoinService.queryCount(request); - return new ResponseVo(larkActiveCountVo); + @ResponseBody + @GetMapping("/export") + public void export(HttpServletResponse response) { + try { + LarkActiveCountVo larkActiveCountVo = larkUserActiveRelatoinService.queryCount(); + ExportUtils.writeFile(response, "fileName"); + EasyExcel.write(response.getOutputStream()) + .head(LarkActiveCountVo.class) + .registerWriteHandler(new CustomMergeStrategy(LarkActiveCountVo.class)) + .excelType(ExcelTypeEnum.XLSX) + .password("123456") + .autoCloseStream(Boolean.TRUE) + .sheet("sheetName") + .doWrite(Arrays.asList(larkActiveCountVo)); + }catch (Exception e){ + log.info("导出信息错误",e); + } } } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkLoginLog.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkLoginLog.java new file mode 100644 index 0000000..d2aec3f --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/LarkLoginLog.java @@ -0,0 +1,43 @@ +package com.ruoyi.flyingbook.domain; + +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 【请填写功能名称】对象 lark_login_log + * + * @author ruoyi + * @date 2023-08-20 + */ +@Data +public class LarkLoginLog extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + private Long id; + + /** 用户唯一id */ + private String openId; + + /** 公司名称 */ + private String companyName; + + /** 用户名称 */ + private String userName; + + /** 用户头像 */ + private String imageUrl; + + /** + * 登陆人类型 + * @see com.ruoyi.common.enums.LarkUserTypeEnum + */ + private String type; + + /** + * @see com.ruoyi.common.enums.FlagStatus + */ + private Long flag; +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkActiveCountVo.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkActiveCountVo.java index 8a08691..8c2f02d 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkActiveCountVo.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkActiveCountVo.java @@ -1,9 +1,10 @@ package com.ruoyi.flyingbook.domain.larkactive; -import com.ruoyi.flyingbook.domain.LarkActive; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.write.style.ColumnWidth; +import com.ruoyi.common.utils.excelStrategy.CustomMerge; import lombok.Data; -import java.util.List; /** * 【请填写功能名称】对象 lark_active @@ -14,17 +15,31 @@ import java.util.List; @Data public class LarkActiveCountVo { - /** - * 总点击量 - */ - private Integer totalClickQty; - /** - * 总用户量 - */ - private Integer totalUserQty; - /** - * 各个模块的参与人数 - */ - private List activeUserQtyList; + @ColumnWidth(20) + @ExcelProperty("总点击量") + @CustomMerge(isPk = true) + private Integer totalClickQty = 0; + @ColumnWidth(20) + @ExcelProperty("总用户量") + private Integer totalUserQty = 0; + @ColumnWidth(20) + @ExcelProperty("MOOC 课程") + private Integer moccQty = 0; + @ColumnWidth(20) + @ExcelProperty("知识竞赛") + private Integer funKnowledgeQty = 0; + @ColumnWidth(20) + @ExcelProperty("信息安全找茬活动") + private Integer nitpickQty = 0; + @ColumnWidth(20) + @ExcelProperty("看信息安全通识视频") + private Integer videoQty = 0; + @ColumnWidth(20) + @ExcelProperty("AI应用创意畅想") + private Integer aiQty = 0; + @ColumnWidth(20) + @ExcelProperty("信息安全风险提报") + private Integer informationSecurityQty = 0; + } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkSessionRequest.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkSessionRequest.java index 95928d0..6801d3c 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkSessionRequest.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/domain/larkactive/LarkSessionRequest.java @@ -9,6 +9,7 @@ import lombok.Data; @Data public class LarkSessionRequest { + private String companyName; private String code; } diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkActiveMapper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkActiveMapper.java index a4f7f91..4cfaadb 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkActiveMapper.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkActiveMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.flyingbook.mapper; import com.ruoyi.flyingbook.domain.LarkActive; import com.ruoyi.flyingbook.domain.larkactive.LarkActiveRequest; +import org.apache.ibatis.annotations.Param; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -20,7 +21,7 @@ public interface LarkActiveMapper { * @return 【请填写功能名称】 */ public LarkActive selectLarkActiveById(Long id); - public List selectLarkActiveByName(@RequestParam("activeName") String activeName,@RequestParam("flag") Long flag); + public List selectLarkActiveByName(@Param("activeName") String activeName, @Param("flag") Long flag); /** * 查询【请填写功能名称】列表 @@ -31,7 +32,7 @@ public interface LarkActiveMapper { public List selectLarkActiveList(LarkActive larkActive); public Integer count(LarkActive larkActive); public List queryPage(LarkActiveRequest request); - public List queryActive(LarkActiveRequest larkActive); + public List queryActive(LarkActive larkActive); public List queryCompleteActive(LarkActiveRequest larkActive); /** * 新增【请填写功能名称】 diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkLoginLogMapper.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkLoginLogMapper.java new file mode 100644 index 0000000..3b26b1b --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/mapper/LarkLoginLogMapper.java @@ -0,0 +1,64 @@ +package com.ruoyi.flyingbook.mapper; + + +import com.ruoyi.flyingbook.domain.LarkLoginLog; + +import java.util.List; + +/** + * 【请填写功能名称】Mapper接口 + * + * @author ruoyi + * @date 2023-08-20 + */ +public interface LarkLoginLogMapper +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkLoginLog selectLarkLoginLogById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkLoginLogList(LarkLoginLog larkLoginLog); + public Integer count(LarkLoginLog larkLoginLog); + + /** + * 新增【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkLoginLog(LarkLoginLog larkLoginLog); + + /** + * 修改【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkLoginLog(LarkLoginLog larkLoginLog); + + /** + * 删除【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkLoginLogById(Long id); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的数据ID + * @return 结果 + */ + public int deleteLarkLoginLogByIds(Long[] ids); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkLoginLogService.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkLoginLogService.java new file mode 100644 index 0000000..aa28506 --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkLoginLogService.java @@ -0,0 +1,63 @@ +package com.ruoyi.flyingbook.service; + + +import com.ruoyi.flyingbook.domain.LarkLoginLog; + +import java.util.List; + +/** + * 【请填写功能名称】Service接口 + * + * @author ruoyi + * @date 2023-08-20 + */ +public interface ILarkLoginLogService +{ + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + public LarkLoginLog selectLarkLoginLogById(Long id); + + /** + * 查询【请填写功能名称】列表 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 【请填写功能名称】集合 + */ + public List selectLarkLoginLogList(LarkLoginLog larkLoginLog); + + /** + * 新增【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + public int insertLarkLoginLog(LarkLoginLog larkLoginLog); + + /** + * 修改【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + public int updateLarkLoginLog(LarkLoginLog larkLoginLog); + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkLoginLogByIds(Long[] ids); + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + public int deleteLarkLoginLogById(Long id); +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkUserActiveRelatoinService.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkUserActiveRelatoinService.java index 4195ad7..937710a 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkUserActiveRelatoinService.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/ILarkUserActiveRelatoinService.java @@ -22,7 +22,7 @@ public interface ILarkUserActiveRelatoinService { */ public LarkUserActiveRelatoin selectLarkUserActiveRelatoinById(Long id); - public LarkActiveCountVo queryCount(LarkUserActiveRelatoin request); + public LarkActiveCountVo queryCount(); /** * 查询【请填写功能名称】列表 diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkLoginLogServiceImpl.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkLoginLogServiceImpl.java new file mode 100644 index 0000000..890f14e --- /dev/null +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkLoginLogServiceImpl.java @@ -0,0 +1,97 @@ +package com.ruoyi.flyingbook.service.impl; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.flyingbook.domain.LarkLoginLog; +import com.ruoyi.flyingbook.mapper.LarkLoginLogMapper; +import com.ruoyi.flyingbook.service.ILarkLoginLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 【请填写功能名称】Service业务层处理 + * + * @author ruoyi + * @date 2023-08-20 + */ +@Service +public class LarkLoginLogServiceImpl implements ILarkLoginLogService +{ + @Autowired + private LarkLoginLogMapper larkLoginLogMapper; + + /** + * 查询【请填写功能名称】 + * + * @param id 【请填写功能名称】ID + * @return 【请填写功能名称】 + */ + @Override + public LarkLoginLog selectLarkLoginLogById(Long id) + { + return larkLoginLogMapper.selectLarkLoginLogById(id); + } + + /** + * 查询【请填写功能名称】列表 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 【请填写功能名称】 + */ + @Override + public List selectLarkLoginLogList(LarkLoginLog larkLoginLog) + { + return larkLoginLogMapper.selectLarkLoginLogList(larkLoginLog); + } + + /** + * 新增【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + @Override + public int insertLarkLoginLog(LarkLoginLog larkLoginLog) + { + larkLoginLog.setCreateTime(DateUtils.getNowDate()); + return larkLoginLogMapper.insertLarkLoginLog(larkLoginLog); + } + + /** + * 修改【请填写功能名称】 + * + * @param larkLoginLog 【请填写功能名称】 + * @return 结果 + */ + @Override + public int updateLarkLoginLog(LarkLoginLog larkLoginLog) + { + larkLoginLog.setUpdateTime(DateUtils.getNowDate()); + return larkLoginLogMapper.updateLarkLoginLog(larkLoginLog); + } + + /** + * 批量删除【请填写功能名称】 + * + * @param ids 需要删除的【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkLoginLogByIds(Long[] ids) + { + return larkLoginLogMapper.deleteLarkLoginLogByIds(ids); + } + + /** + * 删除【请填写功能名称】信息 + * + * @param id 【请填写功能名称】ID + * @return 结果 + */ + @Override + public int deleteLarkLoginLogById(Long id) + { + return larkLoginLogMapper.deleteLarkLoginLogById(id); + } +} diff --git a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkUserActiveRelatoinServiceImpl.java b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkUserActiveRelatoinServiceImpl.java index e5be6fc..c540b4c 100644 --- a/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkUserActiveRelatoinServiceImpl.java +++ b/ruoyi-flyingbook/src/main/java/com/ruoyi/flyingbook/service/impl/LarkUserActiveRelatoinServiceImpl.java @@ -2,11 +2,14 @@ package com.ruoyi.flyingbook.service.impl; import com.qcloud.cos.model.PutObjectResult; import com.ruoyi.common.enums.FlagStatus; +import com.ruoyi.common.enums.LarkActiveEnum; import com.ruoyi.common.enums.LarkActiveStageEnum; +import com.ruoyi.common.enums.LarkUserTypeEnum; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.flyingbook.CosHelper.CosHelper; import com.ruoyi.flyingbook.domain.LarkActive; +import com.ruoyi.flyingbook.domain.LarkLoginLog; import com.ruoyi.flyingbook.domain.LarkUserActiveImage; import com.ruoyi.flyingbook.domain.LarkUserActiveRelatoin; import com.ruoyi.flyingbook.domain.edi.ResponseVo; @@ -15,6 +18,7 @@ import com.ruoyi.flyingbook.domain.larkactive.LarkActiveRequest; import com.ruoyi.flyingbook.domain.larkactive.LarkActiveUserRelationRequest; import com.ruoyi.flyingbook.domain.larkactive.LarkActiveVo; import com.ruoyi.flyingbook.mapper.LarkActiveMapper; +import com.ruoyi.flyingbook.mapper.LarkLoginLogMapper; import com.ruoyi.flyingbook.mapper.LarkUserActiveImageMapper; import com.ruoyi.flyingbook.mapper.LarkUserActiveRelatoinMapper; import com.ruoyi.flyingbook.service.ILarkUserActiveRelatoinService; @@ -48,6 +52,8 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi private CosHelper cosHelper; @Autowired private LarkUserActiveImageMapper larkUserActiveImageMapper; + @Autowired + private LarkLoginLogMapper larkLoginLogMapper; private static final String BUCKET_NAME = "ruoyi-1308275795"; @@ -64,34 +70,59 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi } @Override - public LarkActiveCountVo queryCount(LarkUserActiveRelatoin request) { + public LarkActiveCountVo queryCount() { LarkActiveCountVo larkActiveCountVo = new LarkActiveCountVo(); + //总点击量 + LarkLoginLog larkLoginLog = new LarkLoginLog(); + larkLoginLog.setType(LarkUserTypeEnum.LARK_APP.getCode()); + larkLoginLog.setFlag(FlagStatus.OK.getCode()); + Integer totalClickQty = larkLoginLogMapper.count(larkLoginLog); + larkActiveCountVo.setTotalClickQty(totalClickQty); + //总用户量 LarkUserActiveRelatoin larkUserActiveRelatoin = new LarkUserActiveRelatoin(); larkUserActiveRelatoin.setActiveStage(LarkActiveStageEnum.ADJUST.getCode()); larkUserActiveRelatoin.setFlag(FlagStatus.OK.getCode()); - larkUserActiveRelatoin.setUserName(request.getUserName()); int userCount = larkUserActiveRelatoinMapper.queryUserCount(larkUserActiveRelatoin); larkActiveCountVo.setTotalUserQty(userCount); - List larkActiveCountVos = larkUserActiveRelatoinMapper.queryUserCountGroupByActive(larkUserActiveRelatoin); - if (CollectionUtils.isNotEmpty(larkActiveCountVos)) { - List activeIdList = larkActiveCountVos.stream().map(LarkActiveVo::getId).distinct().collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(activeIdList)) { - LarkActiveRequest query = new LarkActiveRequest(); - query.setFlag(FlagStatus.OK.getCode()); - query.setLarkActiveIdList(activeIdList); - Map activeMap = larkActiveMapper.queryActive(query).stream().collect(Collectors.toMap(LarkActive::getId, Function.identity(), (k1, k2) -> k1)); - for (LarkActiveVo activeCountVo : larkActiveCountVos) { - LarkActive larkActive = activeMap.get(activeCountVo.getId()); - if (larkActive != null) { - BeanUtils.copyProperties(larkActive, activeCountVo); - } - } + //每个活动的数量 + LarkActive query = new LarkActive(); + query.setFlag(FlagStatus.OK.getCode()); + List larkActives = larkActiveMapper.queryActive(query); + if (CollectionUtils.isNotEmpty(larkActives)) { + Map activeCountMap = larkUserActiveRelatoinMapper.queryUserCountGroupByActive(larkUserActiveRelatoin).stream().collect(Collectors.toMap(LarkActiveVo::getId, LarkActiveVo::getQty, (k1, k2) -> k1)); + for (LarkActive active : larkActives) { + Integer qty = activeCountMap.getOrDefault(active.getId(), 0); + fillCount(larkActiveCountVo,qty,active.getActiveDesc()); } } - larkActiveCountVo.setActiveUserQtyList(larkActiveCountVos); return larkActiveCountVo; } + private void fillCount(LarkActiveCountVo larkActiveCountVo,Integer qty,String activeCode){ + qty = qty == null ? 0 : qty; + LarkActiveEnum activeEnum = LarkActiveEnum.getByCode(activeCode); + switch (activeEnum){ + case MOOC: + larkActiveCountVo.setMoccQty(qty); + break; + case FUN_KNOWLEDGE: + larkActiveCountVo.setFunKnowledgeQty(qty); + break; + case NITPICK: + larkActiveCountVo.setNitpickQty(qty); + break; + case VIDEO: + larkActiveCountVo.setVideoQty(qty); + break; + case AI: + larkActiveCountVo.setAiQty(qty); + break; + case INFORMATION_SECURITY: + larkActiveCountVo.setInformationSecurityQty(qty); + break; + } + } + /** * 查询【请填写功能名称】列表 * @@ -133,7 +164,7 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi return new ResponseVo(); } LarkActive active = larkActives.get(0); - LarkUserActiveRelatoin relatoin = queryUserActiveRelation(request.getUserName(), active.getId()); + LarkUserActiveRelatoin relatoin = queryUserActiveRelation(request.getCompanyName(),request.getUserName(), active.getId()); if (relatoin == null) { return new ResponseVo(); } @@ -143,6 +174,7 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi buildUserActiveImage(relatoin, key); if (totalCount >= larkActive.getActiveImageCount()) { relatoin.setActiveStage(LarkActiveStageEnum.ADJUST.getCode()); + larkUserActiveRelatoinMapper.updateLarkUserActiveRelatoin(relatoin); } return new ResponseVo(); } @@ -165,7 +197,7 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi return larkUserActiveImageMapper.selectLarkUserActiveImageList(larkUserActiveImage).size(); } - private LarkUserActiveRelatoin queryUserActiveRelation(String userName, Long activeId) { + private LarkUserActiveRelatoin queryUserActiveRelation(String companyName,String userName, Long activeId) { LarkUserActiveRelatoin relatoin = new LarkUserActiveRelatoin(); relatoin.setUserName(userName); relatoin.setActiveId(activeId); @@ -173,8 +205,14 @@ public class LarkUserActiveRelatoinServiceImpl implements ILarkUserActiveRelatoi List larkUserActiveRelatoins = larkUserActiveRelatoinMapper.selectLarkUserActiveRelatoinList(relatoin); if (CollectionUtils.isNotEmpty(larkUserActiveRelatoins)) { return larkUserActiveRelatoins.get(0); + }else { + relatoin.setCreateBy("System"); + relatoin.setCreateTime(new Date()); + relatoin.setActiveStage(LarkActiveStageEnum.SUBMIT.getCode()); + relatoin.setCompanyName(companyName); + larkUserActiveRelatoinMapper.insertLarkUserActiveRelatoin(relatoin); + return relatoin; } - return null; } /** diff --git a/ruoyi-flyingbook/src/main/resources/mapper/LarkActiveMapper.xml b/ruoyi-flyingbook/src/main/resources/mapper/LarkActiveMapper.xml index 1f4fd9a..ca76a95 100644 --- a/ruoyi-flyingbook/src/main/resources/mapper/LarkActiveMapper.xml +++ b/ruoyi-flyingbook/src/main/resources/mapper/LarkActiveMapper.xml @@ -103,7 +103,7 @@ limit #{offset},{pageSize} - @@ -147,7 +141,7 @@ + + + + + + + + + + + + + + + + + + + + select id, open_id, company_name, user_name, image_url, type, create_by, create_time, update_by, update_time, flag, remark from lark_login_log + + + + + + + + + + insert into lark_login_log + + open_id, + company_name, + user_name, + image_url, + type, + create_by, + create_time, + update_by, + update_time, + flag, + remark, + + + #{openId}, + #{companyName}, + #{userName}, + #{imageUrl}, + #{type}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{flag}, + #{remark}, + + + + + update lark_login_log + + open_id = #{openId}, + company_name = #{companyName}, + user_name = #{userName}, + image_url = #{imageUrl}, + type = #{type}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + flag = #{flag}, + remark = #{remark}, + + where id = #{id} + + + + delete from lark_login_log where id = #{id} + + + + delete from lark_login_log where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-flyingbook/src/main/resources/mapper/LarkUserActiveRelatoinMapper.xml b/ruoyi-flyingbook/src/main/resources/mapper/LarkUserActiveRelatoinMapper.xml index 062a363..7fe1584 100644 --- a/ruoyi-flyingbook/src/main/resources/mapper/LarkUserActiveRelatoinMapper.xml +++ b/ruoyi-flyingbook/src/main/resources/mapper/LarkUserActiveRelatoinMapper.xml @@ -94,7 +94,6 @@ and active_stage = #{activeStage} and flag = #{flag} - group by user_name