diff --git a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java index 8439f08..c88ba79 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/controller/AuthController.java @@ -12,7 +12,6 @@ import me.zhyd.oauth.model.AuthResponse; import me.zhyd.oauth.model.AuthUser; import me.zhyd.oauth.request.AuthRequest; import me.zhyd.oauth.utils.AuthStateUtils; -import org.dromara.common.core.constant.TenantConstants; import org.dromara.common.core.constant.UserConstants; import org.dromara.common.core.domain.R; import org.dromara.common.core.domain.model.LoginBody; @@ -133,10 +132,7 @@ public class AuthController { return R.fail(MessageUtils.message("auth.grant.type.blocked")); } // 校验租户 - if (StringUtils.isEmpty(loginBody.getTenantId())) { - //没有则默认注册在主租户下; - loginBody.setTenantId(TenantConstants.DEFAULT_TENANT_ID); - } else { + if (StringUtils.isNotEmpty(loginBody.getTenantId())) { loginService.checkTenant(loginBody.getTenantId()); } // 登录 @@ -144,6 +140,7 @@ public class AuthController { return R.ok(loginVo); } + /** * 第三方登录请求 * diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java index 8567bbe..377d6c5 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java @@ -22,8 +22,10 @@ import org.dromara.common.core.utils.ValidatorUtils; import org.dromara.common.json.utils.JsonUtils; import org.dromara.common.satoken.utils.LoginHelper; import org.dromara.common.tenant.helper.TenantHelper; +import org.dromara.system.domain.Counselor; import org.dromara.system.domain.SysUser; import org.dromara.system.domain.vo.SysClientVo; +import org.dromara.system.mapper.CounselorMapper; import org.dromara.system.mapper.SysUserMapper; import org.dromara.web.domain.vo.LoginVo; import org.dromara.web.service.IAuthStrategy; @@ -45,6 +47,8 @@ public class XcxAuthStrategy implements IAuthStrategy { private final SysUserMapper userMapper; + private final CounselorMapper counselorMapper; + @Override public LoginVo login(String body, SysClientVo client) { String clientKey = client.getClientKey(); @@ -83,8 +87,15 @@ public class XcxAuthStrategy implements IAuthStrategy { } finally { WxMaConfigHolder.remove();//清理ThreadLocal } + // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 - SysUser user = loadUserByOpenidAndPhoneNumber(openid, phoneNumber, tenantId); + SysUser user; + //判断咨询师还是普通用户 + if ("mp-weixin".equals(clientKey)) { + user = loadUserByOpenidAndPhoneNumber(openid, phoneNumber, tenantId); + } else { + user = loadUserByOpenidAndPhoneNumber4Counselor(openid, phoneNumber); + } // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 LoginUser loginUser = new LoginUser(); @@ -141,4 +152,31 @@ public class XcxAuthStrategy implements IAuthStrategy { }); } + private SysUser loadUserByOpenidAndPhoneNumber4Counselor(String openid, String phoneNumber) { + // 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户 + return TenantHelper.ignore(() -> { + SysUser user = userMapper.selectOne(new LambdaQueryWrapper().eq(SysUser::getUserName, phoneNumber)); + if (ObjectUtil.isNull(user)) { + throw new UserException("本手机号暂未开通咨询师账号,请联系平台"); + } else { + Counselor counselor = counselorMapper.selectById(user.getUserId()); + if (ObjectUtil.isNull(counselor)) { + throw new UserException("本手机号暂未开通咨询师账号,请联系平台"); + } + String openId = user.getOpenId(); + if (StringUtils.isEmpty(openId)) { + SysUser sysUser = new SysUser(); + sysUser.setUserId(user.getUserId()); + sysUser.setOpenId(openid); + userMapper.updateById(sysUser); + return user; + } + if (openId.equals(openid)) { + return user; + } else { + throw new UserException("此用户已被其他微信号绑定", phoneNumber); + } + } + }); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/wx/WxMyController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/wx/WxMyController.java index 8d69b09..617b845 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/wx/WxMyController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/wx/WxMyController.java @@ -16,11 +16,11 @@ import org.dromara.common.web.core.BaseController; import org.dromara.system.domain.bo.BaseQueryBo; import org.dromara.system.domain.bo.ReservationOrderBo; import org.dromara.system.domain.bo.SysScaleBo; +import org.dromara.system.domain.vo.*; import org.dromara.system.service.IArchiveService; import org.dromara.system.service.IMyService; import org.dromara.system.service.ISysEvaluationRecordService; import org.dromara.system.utils.AsposeUtil; -import org.dromara.system.domain.vo.*; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -62,7 +62,7 @@ public class WxMyController extends BaseController { */ @GetMapping("/evaluation/task/pageList") public TableDataInfo taskList(PageQuery pageQuery) { - return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID,() -> myService.queryPersonalTaskPageList(pageQuery)); + return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> myService.queryPersonalTaskPageList(pageQuery)); } /** @@ -70,7 +70,7 @@ public class WxMyController extends BaseController { */ @GetMapping("/scale/pageList") public TableDataInfo list(SysScaleBo bo, PageQuery pageQuery) { - return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID,() -> myService.queryScalePageList(bo, pageQuery)); + return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> myService.queryScalePageList(bo, pageQuery)); } /** @@ -112,7 +112,7 @@ public class WxMyController extends BaseController { @GetMapping("/archive/pageList") public TableDataInfo statisticPageList(PageQuery pageQuery) { Long userId = LoginHelper.getUserId(); - return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID,() -> archiveService.queryStatisticPageList(userId, pageQuery)); + return TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> archiveService.queryStatisticPageList(userId, pageQuery)); } /** @@ -122,13 +122,7 @@ public class WxMyController extends BaseController { public void export(BaseQueryBo bo, HttpServletResponse response) throws Exception { Long userId = LoginHelper.getUserId(); bo.setUserId(userId); - String filePath = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID,() -> { - try { - return sysEvaluationRecordService.getWordTemplate(bo); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); + String filePath = myService.getWordTemplate(bo); File pdf = FileUtil.createTempFile(".pdf", true); String pdfPath = pdf.getPath(); File pdfFile = new File(pdfPath); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/ReservationTime.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/ReservationTime.java index 0aaa97d..1d6f321 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/ReservationTime.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/ReservationTime.java @@ -44,13 +44,13 @@ public class ReservationTime extends BaseEntity { /** * 开始时间 */ - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "GMT+8") private Date startTime; /** * 结束时间 */ - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm", timezone = "GMT+8") private Date endTime; /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/ReservationDayMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/ReservationDayMapper.java index a225685..70c5eab 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/ReservationDayMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/ReservationDayMapper.java @@ -30,12 +30,5 @@ public interface ReservationDayMapper extends BaseMapperPlus selectNotUseDateList(@Param("time") String time,@Param("day") String day, @Param("userId") Long userId); - /** - * 查询day的数据 - * @param day 年-月-日 - * @param userId - * @return - */ - //List selectNotUseDateList(@Param("day") String day, @Param("userId") Long userId); List selectOrderList(@Param("time") String time, @Param("userId") Long userId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/IMyService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/IMyService.java index 0f81d0c..9f70a7e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/IMyService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/IMyService.java @@ -2,6 +2,7 @@ package org.dromara.system.service; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; +import org.dromara.system.domain.bo.BaseQueryBo; import org.dromara.system.domain.bo.ReservationOrderBo; import org.dromara.system.domain.bo.SysScaleBo; import org.dromara.system.domain.vo.ReservationOrderVo; @@ -22,4 +23,6 @@ public interface IMyService { TableDataInfo queryScalePageList(SysScaleBo bo, PageQuery pageQuery); TableDataInfo queryReservationPageList(ReservationOrderBo bo, PageQuery pageQuery); + + String getWordTemplate(BaseQueryBo bo) throws Exception; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/MyServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/MyServiceImpl.java index 09632e4..6fff32d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/MyServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/MyServiceImpl.java @@ -1,33 +1,55 @@ package org.dromara.system.service.impl; +import cn.hutool.core.io.FileUtil; +import cn.hutool.http.HtmlUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.data.*; +import com.deepoove.poi.data.style.BorderStyle; +import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.xwpf.usermodel.XWPFTable; import org.dromara.common.core.constant.TenantConstants; +import org.dromara.common.core.service.DeptService; import org.dromara.common.core.service.OssService; +import org.dromara.common.core.utils.DateUtils; +import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.system.constant.StatusEnum; import org.dromara.system.domain.ReservationOrder; import org.dromara.system.domain.SysEvaluationRecord; import org.dromara.system.domain.SysScale; +import org.dromara.system.domain.bo.BaseQueryBo; import org.dromara.system.domain.bo.ReservationOrderBo; import org.dromara.system.domain.bo.SysScaleBo; -import org.dromara.system.domain.vo.ReservationOrderVo; -import org.dromara.system.domain.vo.StatisticNumVo; -import org.dromara.system.domain.vo.SysEvaluationRecordVo; -import org.dromara.system.domain.vo.SysScaleVo; +import org.dromara.system.domain.vo.*; +import org.dromara.system.domain.word.EvaluationRecordWordData; +import org.dromara.system.domain.word.WordEvaluationFactor; +import org.dromara.system.domain.word.WordFactor; +import org.dromara.system.domain.word.WordRadar; import org.dromara.system.mapper.ReservationOrderMapper; import org.dromara.system.mapper.SysEvaluationRecordMapper; import org.dromara.system.mapper.SysScaleMapper; +import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.service.IMyService; +import org.dromara.system.service.ISysConfigService; import org.springframework.stereotype.Service; +import java.io.File; +import java.io.FileInputStream; +import java.math.BigDecimal; +import java.rmi.ServerException; import java.util.ArrayList; +import java.util.Date; +import java.util.LinkedList; import java.util.List; /** @@ -45,8 +67,11 @@ public class MyServiceImpl implements IMyService { private final SysEvaluationRecordMapper evaluationRecordMapper; private final SysScaleMapper scaleMapper; private final ReservationOrderMapper reservationOrderMapper; + private final SysUserMapper userMapper; + private final DeptService deptService; private final OssService ossService; + private final ISysConfigService configService; @Override @@ -116,6 +141,18 @@ public class MyServiceImpl implements IMyService { return queryEvaluationRecordPageList(lqw, pageQuery); } + private TableDataInfo queryEvaluationRecordPageList(LambdaQueryWrapper lqw, PageQuery pageQuery) { + Page result = evaluationRecordMapper.selectVoPage(pageQuery.build(), lqw); + List records = result.getRecords(); + for (SysEvaluationRecordVo record : records) { + SysScale scale = scaleMapper.selectById(record.getScaleId()); + String s = ossService.selectUrlByIds(String.valueOf(scale.getAppCover())); + record.setAppCoverUrl(s); + record.setScaleName(scale.getScaleName()); + } + return TableDataInfo.build(result); + } + @Override public TableDataInfo queryScalePageList(SysScaleBo bo, PageQuery pageQuery) { Long userId = LoginHelper.getUserId(); @@ -136,15 +173,154 @@ public class MyServiceImpl implements IMyService { return TableDataInfo.build(page); } - private TableDataInfo queryEvaluationRecordPageList(LambdaQueryWrapper lqw, PageQuery pageQuery) { - Page result = evaluationRecordMapper.selectVoPage(pageQuery.build(), lqw); - List records = result.getRecords(); - for (SysEvaluationRecordVo record : records) { - SysScale scale = scaleMapper.selectById(record.getScaleId()); - String s = ossService.selectUrlByIds(String.valueOf(scale.getAppCover())); - record.setAppCoverUrl(s); - record.setScaleName(scale.getScaleName()); + @Override + public String getWordTemplate(BaseQueryBo bo) throws Exception { + Long userId = bo.getUserId(); + if (userId == null) { + throw new ServerException("用户ID不能为空"); } - return TableDataInfo.build(result); + Long recordId = bo.getRecordId(); + if (recordId == null) { + throw new ServerException("记录ID不能为空"); + } + Long scaleId = bo.getScaleId(); + if (scaleId == null) { + throw new ServerException("量表ID不能为空"); + } + SysScale sysScale = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> scaleMapper.selectById(scaleId)); + boolean mbtiFlag = false; + if (sysScale.getScaleName().contains("MBTI")) { + mbtiFlag = true; + } + EvaluationRecordWordData wordData = new EvaluationRecordWordData(); + + String name = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> configService.selectConfigByKey("sys.school.name")); + if (StringUtils.isEmpty(name)) { + wordData.setSchoolName(name); + } else { + wordData.setSchoolName("无"); + } + + SysEvaluationRecord sysEvaluationRecord = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> evaluationRecordMapper.selectById(recordId)); + Date createTime = sysEvaluationRecord.getCreateTime(); + Date updateTime = sysEvaluationRecord.getUpdateTime(); + wordData.setCreateTime(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, createTime)); + wordData.setUseTime(DateUtils.getDatePoor4MinSec(createTime, updateTime)); + + SysUserVo user = userMapper.selectVoById(userId); + wordData.setNickName(user.getNickName()); + if (user.getDeptId() != null) { + String s = deptService.selectDeptNameByIds(Long.toString(user.getDeptId())); + wordData.setDeptName(s); + } else { + wordData.setDeptName("无"); + } + wordData.setSex("0".equals(user.getSex()) ? "男" : "女"); + + SysScaleVo scale = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> scaleMapper.selectVoById(scaleId)); + wordData.setScaleName(scale.getScaleName()); + wordData.setScaleDetails(scale.getScaleDetails()); + + List answerVos = TenantHelper.dynamic(TenantConstants.DEFAULT_TENANT_ID, () -> evaluationRecordMapper.selectEvaluationFactor4Word(recordId)); + BorderStyle borderStyle = new BorderStyle(); + borderStyle.setColor("A6A6A6"); + borderStyle.setSize(4); + borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE); + RowRenderData factorHeader = Rows.of("名称", "包含题目", "原始分", "得分", "命中区间", "区间描述").bgColor("F2F2F2").center() + .textColor("7F7f7F").textFontFamily("宋体").textFontSize(9).create(); + TableRenderData factorTable = Tables.ofA4MediumWidth().addRow(factorHeader).border(borderStyle) + .width(14.63d, null).center().create(); + //一并处理数据 + int size = answerVos.size(); + LinkedList factors = new LinkedList<>(); + List strings = new ArrayList<>(); + List doubles = new ArrayList<>(); + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < size; i++) { + WordEvaluationFactor answerVo = answerVos.get(i); + String factorName = answerVo.getFactorName(); + double score = answerVo.getScore().doubleValue(); + StringBuilder range = new StringBuilder(); + BigDecimal minValue = answerVo.getMinValue(); + BigDecimal maxValue = answerVo.getMaxValue(); + String answerScore = answerVo.getScore().toString(); + boolean minFlag = false; + boolean maxFlag = false; + if (minValue != null) { + minFlag = true; + } + if (maxValue != null) { + maxFlag = true; + } + if (minFlag) { + if (maxFlag) { + range.append(minValue.doubleValue()); + range.append("-"); + range.append(maxValue.doubleValue()); + } else { + answerScore = answerScore + "↑"; + range.append(minValue.doubleValue()); + } + } else if (maxFlag) { + range.append(maxValue.doubleValue()); + answerScore = answerScore + "↓"; + } else { + range.append("无"); + } + //处理因子得分表格 + RowRenderData one = Rows.of(factorName, answerVo.getQuestionNum().toString(), + answerVo.getTotalScore().toString(), answerScore, range.toString(), answerVo.getRangeName()) + .textFontFamily("宋体").textFontSize(9).center().create(); + factorTable.addRow(one); + //处理测评结果 + WordFactor wordFactor = new WordFactor(); + wordFactor.setFactorName(factorName); + wordFactor.setScore(score); + wordFactor.setEvalDesc(answerVo.getEvalDesc()); + //判断激活,放到首位并添加建议 + if (answerVo.getStatus() == 1) { + factors.addFirst(wordFactor); + stringBuilder.append("\t").append(factorName).append("——").append(HtmlUtil.cleanHtmlTag(answerVo.getEvalPropose())).append("\n").append("\n").append("\r"); + } else { + factors.add(wordFactor); + } + if (!"总分".equals(answerVo.getFactorName())) { + //雷达图使用 + strings.add(answerVo.getFactorName()); + doubles.add(score); + } + } + + wordData.setFactor(factorTable); + wordData.setFactors(factors); + //处理雷达图 + if (strings.size() > 1) { + ChartMultiSeriesRenderData chart = Charts + .ofMultiSeries(scale.getScaleName(), strings.toArray(String[]::new)) + .addSeries("因子项", doubles.toArray(Double[]::new)) + .create(); + WordRadar radar = new WordRadar(); + radar.setRadarChart(chart); + wordData.setRadar(radar); + } + wordData.setPropose(stringBuilder.toString()); + File path; + if (mbtiFlag) { + path = new File("/usr/local/tenant/word/MBTITemplate.docx"); + } else { + path = new File("/usr/local/tenant/word/personalTemplate.docx"); + } + File docx = FileUtil.createTempFile(".docx", true); + String wordPath = docx.getPath(); + try (FileInputStream fileInputStream = new FileInputStream(path)) { + Configure config = Configure.builder() + .bind("warnCharts", new LoopRowTableRenderPolicy()).useSpringEL().build(); + XWPFTemplate template = XWPFTemplate.compile(fileInputStream, config).render(wordData); + template.writeToFile(wordPath); + } + Configure config = Configure.builder() + .bind("factors", new LoopRowTableRenderPolicy()).useSpringEL().build(); + XWPFTemplate.compile(path, config).render(wordData); + return wordPath; } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/ReservationServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/ReservationServiceImpl.java index 6d813ff..6cb1246 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/ReservationServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/ReservationServiceImpl.java @@ -130,7 +130,7 @@ public class ReservationServiceImpl implements IReservationService { public List selectTimeListByDay(String day, Long counselorId) { List dayList = dayMapper.selectVoList(new LambdaQueryWrapper() .eq(ReservationDay::getCounselorId, counselorId) - .apply("DATE_FORMAT(day_time, '%Y-%m-%d') =" + day)); + .eq(ReservationDay::getDayTime, day)); for (ReservationDayVo one : dayList) { Date dayTime = one.getDayTime(); one.setWeek(DateUtils.getWeek(dayTime));