提交 dbdf2e22 authored 作者: yucaiwei's avatar yucaiwei

--no commit message

上级 29b3a0ac
......@@ -7,6 +7,8 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
......@@ -27,6 +29,7 @@ import com.zrqx.core.util.JsonUtil.JsonUtil;
*/
@Component
public class Redis {
private static final Logger logger = LoggerFactory.getLogger(Redis.class);
private static final String FG_TOKEN = "y-token";
private static final String BG_TOKEN = "x-token";
......@@ -61,6 +64,17 @@ public class Redis {
public String fmtObj(Object obj) throws IOException {
return obj instanceof String ? obj.toString():JsonUtil.bean2Json(obj);
}
public boolean isExistMember() {
try {
String token = getToken(FG_TOKEN);
String userInfo = get(token);
return StringUtils.isNotEmpty(userInfo);
} catch (Exception e) {
logger.info("未登录");
}
return false;
}
/**
* 添加到redis
* @param token
......
......@@ -350,18 +350,18 @@ public class FgPermissionsController {
}
redis.delete(form.getPhone());
if(mService.isExistByAccount(null,form.getAccount())) {
throw new BaseException(99,"已被注册");
throw new BaseException(99,"账号已被注册");
}
if(mService.isExistByPhone(null, form.getPhone())) {
throw new BaseException(99,"已被使用");
throw new BaseException(99,"手机号已被使用");
}
// 新增
synchronized (this) {
if(mService.isExistByAccount(null,form.getAccount())) {
throw new BaseException(99,"已被注册");
throw new BaseException(99,"账号已被注册");
}
if(mService.isExistByPhone(null, form.getPhone())) {
throw new BaseException(99,"已被使用");
throw new BaseException(99,"手机号已被使用");
}
Member m = new Member();
BeanUtils.copyProperties(form, m);
......@@ -391,12 +391,12 @@ public class FgPermissionsController {
throw new BaseException(14,"该机构可使用次数不足");
}
if(mService.isExistByAccount(null,form.getAccount())) {
throw new BaseException(99,"已存在");
throw new BaseException(99,"账号已存在");
}
// 新增
synchronized (this) {
if(mService.isExistByAccount(null,form.getAccount())) {
throw new BaseException(99,"已存在");
throw new BaseException(99,"账号已存在");
}
Member m = new Member();
BeanUtils.copyProperties(form, m);
......
package com.zrqx.member.fg.pm.service;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.model.member.PrivateMessage;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.datatype.ArrayUtils;
import com.zrqx.core.util.page.PageInfo;
import com.zrqx.core.util.page.PageParam;
import com.zrqx.core.vo.member.fg.pm.FgPrivateMessageListVO;
......@@ -27,6 +31,24 @@ public class FgPrivateMessageServiceImpl extends BaseServiceImpl<PrivateMessage,
@Override
public PageInfo<FgPrivateMessageListVO> page(Integer memberId, PageParam pageParam) {
startPage(pageParam);
return new PageInfo<FgPrivateMessageListVO>(mapper.page(memberId));
List<FgPrivateMessageListVO> list = mapper.page(memberId);
this.regEx(list);
return new PageInfo<FgPrivateMessageListVO>(list);
}
/**
* 去标签
* @param list
* @author ycw
* @date: 2019年4月18日 上午11:57:55
*/
private void regEx(List<FgPrivateMessageListVO> list){
if(ArrayUtils.isNotEmpty(list)){
list.forEach(li -> {
if(StringUtils.isNotBlank(li.getContent())){
li.setContent(li.getContent().replaceAll("\\<.*?>", ""));
}
});
}
}
}
package com.zrqx.member.fg.record.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Example;
import com.zrqx.core.constant.resource.ResourceRequestPath;
import com.zrqx.core.form.resource.fg.record.FgSaveRecordForm;
import com.zrqx.core.util.response.CallBack;
import com.zrqx.core.vo.resource.fg.record.FgMyRecordVO;
import com.zrqx.member.commons.redis.Redis;
import com.zrqx.member.fg.record.service.FgRecordService;
@RestController
@RequestMapping(ResourceRequestPath.FG + ResourceRequestPath.RECORD)
@Api(description = "前台-浏览记录")
public class FgRecordController {
@Autowired
private FgRecordService service;
@Autowired
private Redis redis;
@ApiOperation(value = "我的浏览记录" , notes = "我的浏览记录")
@GetMapping(value = ResourceRequestPath.LIST)
public CallBack<List<FgMyRecordVO>> getMyRecord() {
return CallBack.success(service.getMyRecord());
}
@ApiOperation(value = "批量删除" , notes = "删除浏览记录")
@PostMapping(value = ResourceRequestPath.BATCH_DELETE)
public CallBack<List<FgMyRecordVO>> batechDeleteMyRecord(@RequestBody List<Integer> ids) {
Example example = service.createExample();
example.createCriteria().andIn("id", ids);
service.deleteByExample(example);
return CallBack.success();
}
@ApiOperation(value = "添加浏览记录(跨服务调用)" , notes = "添加浏览记录")
@PostMapping(value = ResourceRequestPath.ADD)
public CallBack<Boolean> addRecord(@RequestBody FgSaveRecordForm form) {
return CallBack.success(service.saveOrUpdateRecord(form));
}
}
package com.zrqx.member.fg.record.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.model.member.Record;
/**
* 浏览记录
* @author ycw
* @date 2019年2月12日下午2:42:01
*/
public interface FgRecordMapper extends BaseMapper<Record> {
@Delete("<script>"
+ "DELETE FROM res_record WHERE "
+ "id NOT IN (SELECT t.id from (SELECT b.id FROM res_record b WHERE b.memberId = #{memberId} ORDER BY b.createTime DESC LIMIT 15) as t)"
+ "</script>")
boolean deleteOtherRecord(Integer memberId);
/**
* 个人中心-为你推荐
* @param memberId
* @param goodsType
* @return
* @author ycw
* @date: 2019年2月18日 下午3:39:30
*/
@Select("<script>"
+ "SELECT id,objectId,objectType,createTime "
+ "FROM res_record "
+ "WHERE b.memberId = #{memberId} "
+ "and goodsType = #{goodsType} "
+ "</script>")
List<Record> queryRecommendByAlgorithm(@Param("memberId")Integer memberId, @Param("goodsType")String goodsType);
}
package com.zrqx.member.fg.record.service;
import java.util.List;
import com.zrqx.core.form.resource.fg.record.FgSaveRecordForm;
import com.zrqx.core.model.member.Record;
import com.zrqx.core.service.BaseService;
import com.zrqx.core.vo.resource.fg.record.FgMyRecordVO;
public interface FgRecordService extends BaseService<Record, Integer> {
/**
* 保存浏览记录
* @param form
* @return
* @author ycw
* @date: 2019年2月12日 下午3:02:55
*/
boolean saveOrUpdateRecord(FgSaveRecordForm form);
/**
* 我的浏览记录
* @return
* @author ycw
* @date: 2019年2月12日 下午4:16:19
*/
List<FgMyRecordVO> getMyRecord();
}
package com.zrqx.member.fg.record.service;
import java.util.Date;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.zrqx.core.form.resource.fg.record.FgSaveRecordForm;
import com.zrqx.core.mapper.BaseMapper;
import com.zrqx.core.model.member.Record;
import com.zrqx.core.service.BaseServiceImpl;
import com.zrqx.core.util.bean.BeanUtils;
import com.zrqx.core.vo.resource.fg.record.FgMyRecordVO;
import com.zrqx.member.commons.redis.Redis;
import com.zrqx.member.fg.record.mapper.FgRecordMapper;
/**
* 浏览记录
* @author ycw
* @date 2019年2月12日下午2:41:27
*/
@Service
public class FgRecordServiceImpl extends BaseServiceImpl<Record, Integer>
implements FgRecordService {
@Autowired
private FgRecordMapper mapper;
@Autowired
private Redis redis;
@Override
public BaseMapper<Record> getMapper() {
return mapper;
}
/**
* 保存浏览记录
* @param goodsId
* @param goodsType 资源类型 电子书2-1 文章2-2
* @return
* @author ycw
* @date: 2019年2月12日 下午3:02:55
*/
@Override
public boolean saveOrUpdateRecord(FgSaveRecordForm form) {
if(!redis.isExistMember()){
return false;
}
Record re = new Record();
re.setObjectId(form.getObjectId());
re.setObjectType(form.getObjectType());
re.setMemberId(redis.getMember().getId());
re.setType(form.getType());
// 删除旧浏览记录
mapper.delete(re);
// 插入新记录
Record record = BeanUtils.copy(form, Record.class);
record.setCreateTime(new Date());
record.setMemberId(redis.getMember().getId());
mapper.insertSelective(record);
//如果浏览记录超过15条,按照浏览时间降序排列,删除多余的浏览记录
Record myRecord = new Record();
myRecord.setMemberId(redis.getMember().getId());
if(mapper.selectCount(myRecord) > 15){
mapper.deleteOtherRecord(redis.getMember().getId());
}
return true;
}
/**
* 我的浏览记录
* @param pageParam
* @return
* @author ycw
* @date: 2019年2月12日 下午4:17:49
*/
@Override
public List<FgMyRecordVO> getMyRecord(){
PageHelper.startPage(1, 15, "createTime desc");
Record record = new Record();
record.setMemberId(redis.getMember().getId());
List<Record> list = mapper.select(record);
if(list != null && list.size() > 0){
List<FgMyRecordVO> vos = BeanUtils.copyList(list, FgMyRecordVO.class, vo -> {
if(StringUtils.isNotBlank(vo.getIntro())){
vo.setIntro(vo.getIntro().replaceAll("\\<.*?>", ""));
}
});
return vos;
}
return null;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论