package net.mingsoft.tf.www; import cn.hutool.core.util.StrUtil; import net.mingsoft.base.entity.ResultData; import net.mingsoft.tf.biz.IBrowseBiz; import net.mingsoft.tf.biz.IBrowseRecordsBiz; import net.mingsoft.tf.entity.BrowseRecordsEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/tf/browse") public class BrowseAction { @Autowired private IBrowseRecordsBiz browseRecordsBiz; @Autowired private IBrowseBiz browseBiz; /** * 记录访问量 */ @RequestMapping(value = "/visits", method = {RequestMethod.GET, RequestMethod.POST}) @ResponseBody public ResultData visits(@RequestBody BrowseRecordsEntity entity) { saveBrowseRecordsEntity(entity); browseBiz.addBrowseVisits(); incrementVisits(entity); return ResultData.build().success(); } private void saveBrowseRecordsEntity(BrowseRecordsEntity entity) { browseRecordsBiz.save(entity); 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); } private void incrementVisits(BrowseRecordsEntity entity) { if (StrUtil.isNotBlank(entity.getRecordsEnterpriseId())) { browseBiz.update("update mdiy_form_enterprise set ENTERPRISE_VISITS = ifnull(ENTERPRISE_VISITS, 0) + 1 where id = ?", entity.getRecordsEnterpriseId()); } if (StrUtil.isNotBlank(entity.getRecordsDesignId())) { browseBiz.update("update mdiy_form_design set DESIGN_VISITS = ifnull(DESIGN_VISITS, 0) + 1 where id = ?", entity.getRecordsDesignId()); } if (StrUtil.isNotBlank(entity.getRecordsProductsId())) { browseBiz.update("update mdiy_form_enterprise_products set PRODUCT_VISITS = ifnull(PRODUCT_VISITS, 0) + 1 where id = ?", entity.getRecordsProductsId()); } } }