From 75b611e724c8c43fae728557f90ed80a7c703dfd Mon Sep 17 00:00:00 2001 From: "382696293@qq.com" <382696293@qq.com> Date: Mon, 29 Jan 2024 11:38:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=89=93=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/entity/WxClockImg.java | 83 +++++++++++ .../domain/entity/WxClockInstrumentLog.java | 98 +++++++++++++ .../common/core/domain/entity/WxClockLog.java | 113 +++++++++++++++ .../common/core/domain/req/WxClockLogReq.java | 46 ++++++ .../common/core/mapper/WxClockImgMapper.java | 62 ++++++++ .../mapper/WxClockInstrumentLogMapper.java | 62 ++++++++ .../common/core/mapper/WxClockLogMapper.java | 61 ++++++++ .../resources/mapper/WxClockImgMapper.xml | 74 ++++++++++ .../mapper/WxClockInstrumentLogMapper.xml | 85 +++++++++++ .../resources/mapper/WxClockLogMapper.xml | 91 ++++++++++++ .../controller/WxClockLogController.java | 48 +++++++ .../service/IWxClockLogService.java | 10 ++ .../service/impl/WxClockLogServiceImpl.java | 135 ++++++++++++++++++ 13 files changed, 968 insertions(+) create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockImg.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockInstrumentLog.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockLog.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockImgMapper.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockInstrumentLogMapper.java create mode 100644 flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockLogMapper.java create mode 100644 flossom-common/flossom-common-core/src/main/resources/mapper/WxClockImgMapper.xml create mode 100644 flossom-common/flossom-common-core/src/main/resources/mapper/WxClockInstrumentLogMapper.xml create mode 100644 flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml create mode 100644 flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java create mode 100644 flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/IWxClockLogService.java create mode 100644 flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxClockLogServiceImpl.java diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockImg.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockImg.java new file mode 100644 index 0000000..4c486b1 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockImg.java @@ -0,0 +1,83 @@ +package com.flossom.common.core.domain.entity; + +import com.flossom.common.core.annotation.Excel; +import com.flossom.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 用户打卡图片关联对象 wx_clock_img + * + * @author flossom + * @date 2024-01-27 + */ +public class WxClockImg extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * $column.columnComment + */ + private Long id; + + /** + * 打卡ID + */ + @Excel(name = "打卡ID") + private Long userClockId; + + /** + * 打卡图片 + */ + @Excel(name = "打卡图片") + private String clockImg; + + /** + * 状态(0正常 1停用) + */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private Long status; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setUserClockId(Long userClockId) { + this.userClockId = userClockId; + } + + public Long getUserClockId() { + return userClockId; + } + + public void setClockImg(String clockImg) { + this.clockImg = clockImg; + } + + public String getClockImg() { + return clockImg; + } + + public void setStatus(Long status) { + this.status = status; + } + + public Long getStatus() { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("userClockId", getUserClockId()) + .append("clockImg", getClockImg()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockInstrumentLog.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockInstrumentLog.java new file mode 100644 index 0000000..de2f4e9 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockInstrumentLog.java @@ -0,0 +1,98 @@ +package com.flossom.common.core.domain.entity; + +import com.flossom.common.core.annotation.Excel; +import com.flossom.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 微信用户使用仪器记录对象 wx_clock_instrument_log + * + * @author flossom + * @date 2024-01-29 + */ +public class WxClockInstrumentLog extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * $column.columnComment + */ + private Long id; + + /** + * 用户ID + */ + @Excel(name = "用户ID") + private Long userId; + + /** + * 仪器ID + */ + @Excel(name = "仪器ID") + private Long instrumentId; + + /** + * 仪器名称 + */ + @Excel(name = "仪器名称") + private String instrumentName; + + /** + * 状态(0正常 1停用) + */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private Long status; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getUserId() { + return userId; + } + + public void setInstrumentId(Long instrumentId) { + this.instrumentId = instrumentId; + } + + public Long getInstrumentId() { + return instrumentId; + } + + public void setInstrumentName(String instrumentName) { + this.instrumentName = instrumentName; + } + + public String getInstrumentName() { + return instrumentName; + } + + public void setStatus(Long status) { + this.status = status; + } + + public Long getStatus() { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("userId", getUserId()) + .append("instrumentId", getInstrumentId()) + .append("instrumentName", getInstrumentName()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockLog.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockLog.java new file mode 100644 index 0000000..80a5e38 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/entity/WxClockLog.java @@ -0,0 +1,113 @@ +package com.flossom.common.core.domain.entity; + +import com.flossom.common.core.annotation.Excel; +import com.flossom.common.core.web.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 用户打卡对象 wx_clock_log + * + * @author flossom + * @date 2024-01-29 + */ +public class WxClockLog extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** + * $column.columnComment + */ + private Long id; + + /** + * 微信用户 + */ + @Excel(name = "微信用户") + private Long userId; + + /** + * 当天使用过的仪器 + */ + @Excel(name = "当天使用过的仪器") + private String instrumentId; + + /** + * 当天使用过的仪器 + */ + @Excel(name = "当天使用过的仪器") + private String instrumentName; + + /** + * 打卡心得 + */ + @Excel(name = "打卡心得") + private String clockContent; + + /** + * 状态(0正常 1停用) + */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private Long status; + + public void setId(Long id) { + this.id = id; + } + + public Long getId() { + return id; + } + + public void setUserId(Long userId) { + this.userId = userId; + } + + public Long getUserId() { + return userId; + } + + public void setInstrumentId(String instrumentId) { + this.instrumentId = instrumentId; + } + + public String getInstrumentId() { + return instrumentId; + } + + public void setInstrumentName(String instrumentName) { + this.instrumentName = instrumentName; + } + + public String getInstrumentName() { + return instrumentName; + } + + public void setClockContent(String clockContent) { + this.clockContent = clockContent; + } + + public String getClockContent() { + return clockContent; + } + + public void setStatus(Long status) { + this.status = status; + } + + public Long getStatus() { + return status; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("userId", getUserId()) + .append("instrumentId", getInstrumentId()) + .append("instrumentName", getInstrumentName()) + .append("clockContent", getClockContent()) + .append("status", getStatus()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .toString(); + } +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java new file mode 100644 index 0000000..d1a7da7 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java @@ -0,0 +1,46 @@ +package com.flossom.common.core.domain.req; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +/** + * 用户打卡对象 wx_clock_log + * + * @author flossom + * @date 2024-01-27 + */ +public class WxClockLogReq { + + /** + * 打卡心得 + */ + @NotBlank(message = "请输入打卡心得") + @Size(min = 1, max = 120, message = "内容限制120个字符以内") + private String clockContent; + + /** + * 打卡照片 + */ + @NotNull(message = "请上传打卡图片") + @Size(min = 1, max = 3, message = "打卡图片数限制在3张以内") + List clockImageList; + + public String getClockContent() { + return clockContent; + } + + public void setClockContent(String clockContent) { + this.clockContent = clockContent; + } + + public List getClockImageList() { + return clockImageList; + } + + public void setClockImageList(List clockImageList) { + this.clockImageList = clockImageList; + } + +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockImgMapper.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockImgMapper.java new file mode 100644 index 0000000..48012a5 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockImgMapper.java @@ -0,0 +1,62 @@ +package com.flossom.common.core.mapper; + +import com.flossom.common.core.domain.entity.WxClockImg; + +import java.util.List; + + +/** + * 用户打卡图片关联Mapper接口 + * + * @author flossom + * @date 2024-01-27 + */ +public interface WxClockImgMapper { + /** + * 查询用户打卡图片关联 + * + * @param id 用户打卡图片关联主键 + * @return 用户打卡图片关联 + */ + public WxClockImg selectWxClockImgById(Long id); + + /** + * 查询用户打卡图片关联列表 + * + * @param wxClockImg 用户打卡图片关联 + * @return 用户打卡图片关联集合 + */ + public List selectWxClockImgList(WxClockImg wxClockImg); + + /** + * 新增用户打卡图片关联 + * + * @param wxClockImg 用户打卡图片关联 + * @return 结果 + */ + public int insertWxClockImg(WxClockImg wxClockImg); + + /** + * 修改用户打卡图片关联 + * + * @param wxClockImg 用户打卡图片关联 + * @return 结果 + */ + public int updateWxClockImg(WxClockImg wxClockImg); + + /** + * 删除用户打卡图片关联 + * + * @param id 用户打卡图片关联主键 + * @return 结果 + */ + public int deleteWxClockImgById(Long id); + + /** + * 批量删除用户打卡图片关联 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteWxClockImgByIds(Long[] ids); +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockInstrumentLogMapper.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockInstrumentLogMapper.java new file mode 100644 index 0000000..8afdaca --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockInstrumentLogMapper.java @@ -0,0 +1,62 @@ +package com.flossom.common.core.mapper; + +import com.flossom.common.core.domain.entity.WxClockInstrumentLog; + +import java.util.List; + + +/** + * 微信用户使用仪器记录Mapper接口 + * + * @author flossom + * @date 2024-01-29 + */ +public interface WxClockInstrumentLogMapper { + /** + * 查询微信用户使用仪器记录 + * + * @param id 微信用户使用仪器记录主键 + * @return 微信用户使用仪器记录 + */ + public WxClockInstrumentLog selectWxClockInstrumentLogById(Long id); + + /** + * 查询微信用户使用仪器记录列表 + * + * @param wxClockInstrumentLog 微信用户使用仪器记录 + * @return 微信用户使用仪器记录集合 + */ + public List selectWxClockInstrumentLogList(WxClockInstrumentLog wxClockInstrumentLog); + + /** + * 新增微信用户使用仪器记录 + * + * @param wxClockInstrumentLog 微信用户使用仪器记录 + * @return 结果 + */ + public int insertWxClockInstrumentLog(WxClockInstrumentLog wxClockInstrumentLog); + + /** + * 修改微信用户使用仪器记录 + * + * @param wxClockInstrumentLog 微信用户使用仪器记录 + * @return 结果 + */ + public int updateWxClockInstrumentLog(WxClockInstrumentLog wxClockInstrumentLog); + + /** + * 删除微信用户使用仪器记录 + * + * @param id 微信用户使用仪器记录主键 + * @return 结果 + */ + public int deleteWxClockInstrumentLogById(Long id); + + /** + * 批量删除微信用户使用仪器记录 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteWxClockInstrumentLogByIds(Long[] ids); +} diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockLogMapper.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockLogMapper.java new file mode 100644 index 0000000..7740ee9 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/mapper/WxClockLogMapper.java @@ -0,0 +1,61 @@ +package com.flossom.common.core.mapper; + +import com.flossom.common.core.domain.entity.WxClockLog; + +import java.util.List; + +/** + * 用户打卡Mapper接口 + * + * @author flossom + * @date 2024-01-29 + */ +public interface WxClockLogMapper { + /** + * 查询用户打卡 + * + * @param id 用户打卡主键 + * @return 用户打卡 + */ + public WxClockLog selectWxClockLogById(Long id); + + /** + * 查询用户打卡列表 + * + * @param wxClockLog 用户打卡 + * @return 用户打卡集合 + */ + public List selectWxClockLogList(WxClockLog wxClockLog); + + /** + * 新增用户打卡 + * + * @param wxClockLog 用户打卡 + * @return 结果 + */ + public int insertWxClockLog(WxClockLog wxClockLog); + + /** + * 修改用户打卡 + * + * @param wxClockLog 用户打卡 + * @return 结果 + */ + public int updateWxClockLog(WxClockLog wxClockLog); + + /** + * 删除用户打卡 + * + * @param id 用户打卡主键 + * @return 结果 + */ + public int deleteWxClockLogById(Long id); + + /** + * 批量删除用户打卡 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteWxClockLogByIds(Long[] ids); +} diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockImgMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockImgMapper.xml new file mode 100644 index 0000000..59c5580 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockImgMapper.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + select id, user_clock_id, clock_img, status, create_by, create_time from wx_clock_img + + + + + + + + insert into wx_clock_img + + user_clock_id, + clock_img, + status, + create_by, + create_time, + + + #{userClockId}, + #{clockImg}, + #{status}, + #{createBy}, + #{createTime}, + + + + + update wx_clock_img + + user_clock_id = #{userClockId}, + clock_img = #{clockImg}, + status = #{status}, + create_by = #{createBy}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from wx_clock_img where id = #{id} + + + + delete from wx_clock_img where id in + + #{id} + + + \ No newline at end of file diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockInstrumentLogMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockInstrumentLogMapper.xml new file mode 100644 index 0000000..7f89c92 --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockInstrumentLogMapper.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + select id, user_id, instrument_id, instrument_name, status, create_by, create_time from wx_clock_instrument_log + + + + + + + + insert into wx_clock_instrument_log + + user_id, + instrument_id, + instrument_name, + status, + create_by, + create_time, + + + #{userId}, + #{instrumentId}, + #{instrumentName}, + #{status}, + #{createBy}, + #{createTime}, + + + + + update wx_clock_instrument_log + + user_id = #{userId}, + instrument_id = #{instrumentId}, + instrument_name = #{instrumentName}, + status = #{status}, + create_by = #{createBy}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from wx_clock_instrument_log where id = #{id} + + + + delete from wx_clock_instrument_log where id in + + #{id} + + + \ No newline at end of file diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml new file mode 100644 index 0000000..82bcb9e --- /dev/null +++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + select id, user_id, instrument_id, instrument_name, clock_content, status, create_by, create_time from wx_clock_log + + + + + + + + insert into wx_clock_log + + user_id, + instrument_id, + instrument_name, + clock_content, + status, + create_by, + create_time, + + + #{userId}, + #{instrumentId}, + #{instrumentName}, + #{clockContent}, + #{status}, + #{createBy}, + #{createTime}, + + + + + update wx_clock_log + + user_id = #{userId}, + instrument_id = #{instrumentId}, + instrument_name = #{instrumentName}, + clock_content = #{clockContent}, + status = #{status}, + create_by = #{createBy}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from wx_clock_log where id = #{id} + + + + delete from wx_clock_log where id in + + #{id} + + + \ No newline at end of file diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java new file mode 100644 index 0000000..75dbf22 --- /dev/null +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java @@ -0,0 +1,48 @@ +package com.flossom.miniProgram.controller; + +import com.flossom.common.core.domain.R; +import com.flossom.common.core.domain.req.WxClockLogReq; +import com.flossom.common.core.web.controller.BaseController; +import com.flossom.miniProgram.service.IWxClockLogService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.NotNull; + +/** + * 用户打卡Controller + * + * @author flossom + * @date 2024-01-27 + */ +@RestController +@RequestMapping("/clock") +public class WxClockLogController extends BaseController { + + @Autowired + private IWxClockLogService wxClockLogService; + + /** + * 添加用户使用仪器记录表 + */ + @GetMapping("/addClockInstrument") + public R addClockInstrument(@NotNull(message = "请选择仪器ID") @RequestParam("instrumentId") Long instrumentId) { + wxClockLogService.addClockInstrument(instrumentId); + return R.ok(); + } + + /** + * 新增用户打卡 + * 需要记录当天使用过的全部仪器(打卡前后的全部仪器) + */ + @PostMapping("/insertClockLog") + public R insertClockLog(@Validated @RequestBody WxClockLogReq wxClockLogReq) { + wxClockLogService.insertWxClockLog(wxClockLogReq); + return R.ok(); + } + + + + +} diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/IWxClockLogService.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/IWxClockLogService.java new file mode 100644 index 0000000..c5a34e6 --- /dev/null +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/IWxClockLogService.java @@ -0,0 +1,10 @@ +package com.flossom.miniProgram.service; + +import com.flossom.common.core.domain.req.WxClockLogReq; + +public interface IWxClockLogService { + + public void insertWxClockLog(WxClockLogReq wxClockLogReq); + + void addClockInstrument(Long instrumentId); +} diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxClockLogServiceImpl.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxClockLogServiceImpl.java new file mode 100644 index 0000000..9e4fc32 --- /dev/null +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/service/impl/WxClockLogServiceImpl.java @@ -0,0 +1,135 @@ +package com.flossom.miniProgram.service.impl; + +import com.flossom.common.core.domain.entity.*; +import com.flossom.common.core.domain.req.WxClockLogReq; +import com.flossom.common.core.enums.Status; +import com.flossom.common.core.mapper.WxClockImgMapper; +import com.flossom.common.core.mapper.WxClockInstrumentLogMapper; +import com.flossom.common.core.mapper.WxClockLogMapper; +import com.flossom.common.core.mapper.WxInstrumentMapper; +import com.flossom.common.core.utils.DateUtils; +import com.flossom.common.security.utils.SecurityUtils; +import com.flossom.miniProgram.service.IWxClockLogService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Service +public class WxClockLogServiceImpl implements IWxClockLogService { + + @Autowired + private WxClockLogMapper wxClockLogMapper; + + @Autowired + private WxClockImgMapper wxClockImgMapper; + + @Autowired + private WxClockInstrumentLogMapper wxClockInstrumentLogMapper; + + @Autowired + private WxInstrumentMapper wxInstrumentMapper; + + + @Override + @Transactional + public void insertWxClockLog(WxClockLogReq wxClockLogReq) { + WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember(); + // 打卡记录 + WxClockLog wxClockLog = new WxClockLog(); + BeanUtils.copyProperties(wxClockLogReq, wxClockLog); + wxClockLog.setUserId(wxUserMember.getId()); + wxClockLog.setCreateBy(wxUserMember.getNickname()); + wxClockLog.setCreateTime(DateUtils.getNowDate()); + // 当天使用过的仪器 + WxClockInstrumentLog queryInstrumentLog = new WxClockInstrumentLog(); + queryInstrumentLog.setUserId(wxUserMember.getId()); + LocalDateTime now = LocalDateTime.now(); + wxClockLog.getParams().put("beginTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MIN)); + wxClockLog.getParams().put("endTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MAX)); + queryInstrumentLog.setStatus(Status.OK.getCode().longValue()); + List wxClockInstrumentLogList = wxClockInstrumentLogMapper.selectWxClockInstrumentLogList(queryInstrumentLog); + if (wxClockInstrumentLogList != null && wxClockInstrumentLogList.size() > 0) { + String instrumentIdList = wxClockInstrumentLogList.stream() + .map(WxClockInstrumentLog::getInstrumentId) + .distinct() + .map(Objects::toString) + .collect(Collectors.joining(",")); + wxClockLog.setInstrumentId(instrumentIdList); + String instrumentNameList = wxClockInstrumentLogList.stream() + .map(WxClockInstrumentLog::getInstrumentName) + .distinct() + .map(Objects::toString) + .collect(Collectors.joining(",")); + wxClockLog.setInstrumentName(instrumentNameList); + } + wxClockLogMapper.insertWxClockLog(wxClockLog); + + // 打卡图片 + if (wxClockLogReq.getClockImageList() != null && wxClockLogReq.getClockImageList().size() > 0) { + for (String image : wxClockLogReq.getClockImageList()) { + WxClockImg wxClockImg = new WxClockImg(); + wxClockImg.setUserClockId(wxClockLog.getId()); + wxClockImg.setClockImg(image); + wxClockImg.setCreateBy(wxUserMember.getNickname()); + wxClockImg.setCreateTime(DateUtils.getNowDate()); + wxClockImgMapper.insertWxClockImg(wxClockImg); + } + } + + + /** + * TODO:奖励积分 + */ + + } + + @Override + @Transactional + public void addClockInstrument(Long instrumentId) { + // 添加仪器使用记录 + WxClockInstrumentLog wxClockInstrumentLog = new WxClockInstrumentLog(); + wxClockInstrumentLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId()); + wxClockInstrumentLog.setInstrumentId(instrumentId); + WxInstrument wxInstrument = wxInstrumentMapper.selectWxInstrumentById(instrumentId); + if (wxInstrument != null) { + wxClockInstrumentLog.setInstrumentName(wxInstrument.getName()); + } + wxClockInstrumentLog.setStatus(Status.OK.getCode().longValue()); + wxClockInstrumentLog.setCreateBy(SecurityUtils.getLoginUser().getWxUserMember().getNickname()); + wxClockInstrumentLog.setCreateTime(DateUtils.getNowDate()); + wxClockInstrumentLogMapper.insertWxClockInstrumentLog(wxClockInstrumentLog); + + // 查询今天是否有打卡,存在打卡,则将仪器添加到最近一条打卡记录上 + WxClockLog queryClockLog = new WxClockLog(); + queryClockLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId()); + LocalDateTime now = LocalDateTime.now(); + queryClockLog.getParams().put("beginTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MIN)); + queryClockLog.getParams().put("endTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MAX)); + List wxClockLogList = wxClockLogMapper.selectWxClockLogList(queryClockLog); + if (wxClockLogList != null && wxClockLogList.size() > 0) { + // 直接获取最新的打卡记录 + WxClockLog saveClockLog = new WxClockLog(); + WxClockLog newWxClockLog = wxClockLogList.get(0); + // 获取打卡记录的使用过的仪器ID + List usedList = Arrays.asList(newWxClockLog.getInstrumentId().split(",")).stream().map(Long::valueOf).collect(Collectors.toList()); + if (!usedList.contains(instrumentId)) { + saveClockLog.setInstrumentId(newWxClockLog.getInstrumentId() + "," + instrumentId); + WxInstrument instrument = wxInstrumentMapper.selectWxInstrumentById(instrumentId); + if (instrument != null) { + saveClockLog.setInstrumentName(newWxClockLog.getInstrumentName() + "," + instrument.getName()); + } + saveClockLog.setId(newWxClockLog.getId()); + wxClockLogMapper.updateWxClockLog(saveClockLog); + } + } + } +}