BrowseAction.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package net.mingsoft.tf.www;
  2. import cn.hutool.core.util.StrUtil;
  3. import net.mingsoft.base.entity.ResultData;
  4. import net.mingsoft.tf.biz.IBrowseBiz;
  5. import net.mingsoft.tf.biz.IBrowseRecordsBiz;
  6. import net.mingsoft.tf.entity.BrowseRecordsEntity;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestBody;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.ResponseBody;
  13. @Controller
  14. @RequestMapping("/tf/browse")
  15. public class BrowseAction {
  16. @Autowired
  17. private IBrowseRecordsBiz browseRecordsBiz;
  18. @Autowired
  19. private IBrowseBiz browseBiz;
  20. /**
  21. * 记录访问量
  22. */
  23. @RequestMapping(value = "/visits", method = {RequestMethod.GET, RequestMethod.POST})
  24. @ResponseBody
  25. public ResultData visits(@RequestBody BrowseRecordsEntity entity) {
  26. saveBrowseRecordsEntity(entity);
  27. browseBiz.addBrowseVisits();
  28. incrementVisits(entity);
  29. return ResultData.build().success();
  30. }
  31. private void saveBrowseRecordsEntity(BrowseRecordsEntity entity) {
  32. browseRecordsBiz.save(entity);
  33. browseRecordsBiz.update("DELETE FROM mdiy_form_browse_records WHERE id NOT IN (SELECT id FROM (SELECT id FROM mdiy_form_browse_records ORDER BY id desc LIMIT ?) AS tmp)", 30);
  34. }
  35. private void incrementVisits(BrowseRecordsEntity entity) {
  36. if (StrUtil.isNotBlank(entity.getRecordsEnterpriseId())) {
  37. browseBiz.update("update mdiy_form_enterprise set ENTERPRISE_VISITS = ifnull(ENTERPRISE_VISITS, 0) + 1 where id = ?", entity.getRecordsEnterpriseId());
  38. }
  39. if (StrUtil.isNotBlank(entity.getRecordsDesignId())) {
  40. browseBiz.update("update mdiy_form_design set DESIGN_VISITS = ifnull(DESIGN_VISITS, 0) + 1 where id = ?", entity.getRecordsDesignId());
  41. }
  42. if (StrUtil.isNotBlank(entity.getRecordsProductsId())) {
  43. browseBiz.update("update mdiy_form_enterprise_products set PRODUCT_VISITS = ifnull(PRODUCT_VISITS, 0) + 1 where id = ?", entity.getRecordsProductsId());
  44. }
  45. }
  46. }