Browse Source

用户网格访问记录修改

master
wangchao 5 years ago
parent
commit
b74c5f7f92
  1. 7
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/GridVisitedDao.java
  2. 28
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/GridVisitedServiceImpl.java
  3. 16
      epmet-user/epmet-user-server/src/main/resources/mapper/GridVisitedDao.xml

7
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/GridVisitedDao.java

@ -23,6 +23,9 @@ import com.epmet.dto.GridVisitedDTO;
import com.epmet.entity.GridLatestEntity;
import com.epmet.entity.GridVisitedEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 网格访问记录表 用户对网格访问的一个记录只有在访问网格首页时才存储数据,一个用户一天对一个网格的访问只有一条记录
@ -33,6 +36,8 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface GridVisitedDao extends BaseDao<GridVisitedEntity> {
GridVisitedDTO selectGridVisitedByGridIdAndUserId(GridVisitedDTO formDTO);
List<GridVisitedDTO> selectGridVisitedByGridIdAndUserId(GridVisitedDTO formDTO);
int updateByVisitedId(GridVisitedDTO dto);
void deleteBatch(@Param("ids") List<String> ids);
}

28
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/GridVisitedServiceImpl.java

@ -21,6 +21,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl;
import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.ConvertUtils;
@ -42,10 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* 网格访问记录表 用户对网格访问的一个记录只有在访问网格首页时才存储数据,一个用户一天对一个网格的访问只有一条记录
@ -165,16 +163,26 @@ public class GridVisitedServiceImpl extends BaseServiceImpl<GridVisitedDao, Grid
gridVisitedDTO.setVisitTime(date);
gridVisitedDTO.setUpdatedTime(date);
//查询是否存在历史数据( 一个用户一天对一个网格只存在一条访问记录)
GridVisitedDTO dto = baseDao.selectGridVisitedByGridIdAndUserId(gridVisitedDTO);
List<GridVisitedDTO> dto = baseDao.selectGridVisitedByGridIdAndUserId(gridVisitedDTO);
GridVisitedEntity entity = null;
if (dto == null || dto.getId() == null) {
boolean result = false;
if(null == dto || dto.size() <= NumConstant.ZERO){
entity = ConvertUtils.sourceToTarget(gridVisitedDTO, GridVisitedEntity.class);
return insert(entity);
} else {
dto.setUpdatedBy(visitedFormDTO.getUserId());
dto.setUpdatedTime(date);
return BaseServiceImpl.retBool(gridVisitedDao.updateByVisitedId(dto));
}else{
dto.get(NumConstant.ZERO).setUpdatedBy(visitedFormDTO.getUserId());
dto.get(NumConstant.ZERO).setUpdatedTime(date);
result = BaseServiceImpl.retBool(gridVisitedDao.updateByVisitedId(dto.get(NumConstant.ZERO)));
if(dto.size() > NumConstant.ONE){
List<String> ids = new LinkedList<>();
dto.subList(NumConstant.ONE,dto.size()).forEach(obj -> {
ids.add(obj.getId());
});
baseDao.deleteBatch(ids);
}
}
return result;
}
/**

16
epmet-user/epmet-user-server/src/main/resources/mapper/GridVisitedDao.xml

@ -48,13 +48,27 @@
<if test='visitTime != null'>
AND to_days(vi.visit_time) = to_days(#{visitTime})
</if>
ORDER BY
vi.visit_time DESC
</select>
<update id="updateByVisitedId">
UPDATE grid_visited
SET updated_by = #{updatedBy},
SET
visit_time = #{updatedTime},
updated_by = #{updatedBy},
updated_time = #{updatedTime}
WHERE id = #{id}
</update>
<update id="deleteBatch" parameterType="java.util.List">
UPDATE grid_visited
SET del_flag = '1',
updated_time = now()
WHERE
<foreach collection="ids" item="id" open="" separator="OR" close="">
ID = #{id}
</foreach>
</update>
</mapper>
Loading…
Cancel
Save