用户打卡只保留一条数据

master
382696293@qq.com 2 years ago
parent 7e37d48f50
commit f4fbb8d0c4

@ -59,4 +59,6 @@ public interface WxClockImgMapper {
* @return * @return
*/ */
public int deleteWxClockImgByIds(Long[] ids); public int deleteWxClockImgByIds(Long[] ids);
void deleteByUserClockId(Long userClockId);
} }

@ -65,6 +65,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from wx_clock_img where id = #{id} delete from wx_clock_img where id = #{id}
</delete> </delete>
<delete id="deleteByUserClockId" parameterType="Long">
delete from wx_clock_img where user_clock_id = #{userClockId}
</delete>
<delete id="deleteWxClockImgByIds" parameterType="String"> <delete id="deleteWxClockImgByIds" parameterType="String">
delete from wx_clock_img where id in delete from wx_clock_img where id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">

@ -51,6 +51,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<insert id="insertWxClockLog" parameterType="WxClockLog" useGeneratedKeys="true" keyProperty="id"> <insert id="insertWxClockLog" parameterType="WxClockLog" useGeneratedKeys="true" keyProperty="id">
<selectKey keyProperty="id" resultType="Long" order="AFTER">
SELECT LAST_INSERT_ID()
</selectKey>
insert into wx_clock_log insert into wx_clock_log
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if> <if test="userId != null">user_id,</if>

@ -46,21 +46,22 @@ public class WxClockLogServiceImpl implements IWxClockLogService {
WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember(); WxUserMember wxUserMember = SecurityUtils.getLoginUser().getWxUserMember();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
// 首次打卡奖励 /* 查询当天是否有打卡 */
WxClockLog queryClockLog = new WxClockLog(); WxClockLog queryClockLog = new WxClockLog();
queryClockLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId()); queryClockLog.setUserId(SecurityUtils.getLoginUser().getWxUserMember().getId());
queryClockLog.getParams().put("beginTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MIN)); queryClockLog.getParams().put("beginTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MIN));
queryClockLog.getParams().put("endTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MAX)); queryClockLog.getParams().put("endTime", LocalDateTime.of(now.toLocalDate(), LocalTime.MAX));
Integer count = wxClockLogMapper.selectCountByUserId(queryClockLog); List<WxClockLog> wxClockLogList = wxClockLogMapper.selectWxClockLogList(queryClockLog);
if (count == null || count == 0) { WxClockLog wxClockLog = new WxClockLog();
if (wxClockLogList != null && wxClockLogList.size() == 1) {
// 打卡记录一天只有一条
wxClockLog.setId(wxClockLogList.get(0).getId());
} else {
/** /**
* TODO * TODO
*/ */
} }
wxClockLog.setClockContent(wxClockLogReq.getClockContent());
// 打卡记录
WxClockLog wxClockLog = new WxClockLog();
BeanUtils.copyProperties(wxClockLogReq, wxClockLog);
wxClockLog.setUserId(wxUserMember.getId()); wxClockLog.setUserId(wxUserMember.getId());
wxClockLog.setCreateBy(wxUserMember.getNickname()); wxClockLog.setCreateBy(wxUserMember.getNickname());
wxClockLog.setCreateTime(DateUtils.getNowDate()); wxClockLog.setCreateTime(DateUtils.getNowDate());
@ -85,10 +86,15 @@ public class WxClockLogServiceImpl implements IWxClockLogService {
.collect(Collectors.joining(",")); .collect(Collectors.joining(","));
wxClockLog.setInstrumentName(instrumentNameList); wxClockLog.setInstrumentName(instrumentNameList);
} }
wxClockLogMapper.insertWxClockLog(wxClockLog); if (wxClockLog.getId() == null) {
wxClockLogMapper.insertWxClockLog(wxClockLog);
} else {
wxClockLogMapper.updateWxClockLog(wxClockLog);
}
// 打卡图片 /* 先删除当天的打卡图片,保存打卡图片 */
if (wxClockLogReq.getClockImageList() != null && wxClockLogReq.getClockImageList().size() > 0) { if (wxClockLogReq.getClockImageList() != null && wxClockLogReq.getClockImageList().size() > 0) {
wxClockImgMapper.deleteByUserClockId(wxClockLog.getId());
for (String image : wxClockLogReq.getClockImageList()) { for (String image : wxClockLogReq.getClockImageList()) {
WxClockImg wxClockImg = new WxClockImg(); WxClockImg wxClockImg = new WxClockImg();
wxClockImg.setUserClockId(wxClockLog.getId()); wxClockImg.setUserClockId(wxClockLog.getId());
@ -125,18 +131,18 @@ public class WxClockLogServiceImpl implements IWxClockLogService {
List<WxClockLog> wxClockLogList = wxClockLogMapper.selectWxClockLogList(queryClockLog); List<WxClockLog> wxClockLogList = wxClockLogMapper.selectWxClockLogList(queryClockLog);
if (wxClockLogList != null && wxClockLogList.size() > 0) { if (wxClockLogList != null && wxClockLogList.size() > 0) {
// 直接获取最新的打卡记录 // 直接获取最新的打卡记录
WxClockLog saveClockLog = new WxClockLog(); WxClockLog updateClockLog = new WxClockLog();
WxClockLog newWxClockLog = wxClockLogList.get(0); WxClockLog newWxClockLog = wxClockLogList.get(0);
// 获取打卡记录的使用过的仪器ID // 获取打卡记录的使用过的仪器ID
List<Long> usedList = Arrays.asList(newWxClockLog.getInstrumentId().split(",")).stream().map(Long::valueOf).collect(Collectors.toList()); List<Long> usedList = Arrays.asList(newWxClockLog.getInstrumentId().split(",")).stream().map(Long::valueOf).collect(Collectors.toList());
if (!usedList.contains(instrumentId)) { if (!usedList.contains(instrumentId)) {
saveClockLog.setInstrumentId(newWxClockLog.getInstrumentId() + "," + instrumentId); updateClockLog.setInstrumentId(newWxClockLog.getInstrumentId() + "," + instrumentId);
WxInstrument instrument = wxInstrumentMapper.selectWxInstrumentById(instrumentId); WxInstrument instrument = wxInstrumentMapper.selectWxInstrumentById(instrumentId);
if (instrument != null) { if (instrument != null) {
saveClockLog.setInstrumentName(newWxClockLog.getInstrumentName() + "," + instrument.getName()); updateClockLog.setInstrumentName(newWxClockLog.getInstrumentName() + "," + instrument.getName());
} }
saveClockLog.setId(newWxClockLog.getId()); updateClockLog.setId(newWxClockLog.getId());
wxClockLogMapper.updateWxClockLog(saveClockLog); wxClockLogMapper.updateWxClockLog(updateClockLog);
} }
} }
} }

Loading…
Cancel
Save