albertshaw пре 8 година
родитељ
комит
f81fa92424

+ 1 - 6
src/main/java/com/goafanti/admin/controller/AdminTriggerController.java

@@ -11,7 +11,6 @@ import org.springframework.web.bind.annotation.RestController;
 
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.controller.BaseApiController;
-import com.goafanti.common.model.HtmlFragment;
 import com.goafanti.common.utils.StringUtils;
 import com.goafanti.crawler.RequestUtils;
 import com.goafanti.crawler.callback.TransitFutureCallback;
@@ -41,11 +40,7 @@ public class AdminTriggerController extends BaseApiController {
 					"http://sousuo.gov.cn/list.htm?n=40&p=0&t=paper&sort=pubtime&subchildtype=gc189&location=%E7%BB%BC%E5%90%88%E6%94%BF%E5%8A%A1%E5%85%B6%E4%BB%96&timetype=timeqb",
 					cb);
 			if (json.containsKey(year)) {
-				String id = "vacations" + year;
-				HtmlFragment hf = new HtmlFragment();
-				hf.setContent(json.get(year));
-				hf.setId(id);
-				fragmentService.save(id, hf);
+				fragmentService.save("vacations" + year, json.get(year));
 			}
 			res.setData(json);
 		} catch (Exception e) {

+ 3 - 9
src/main/java/com/goafanti/fragment/controller/FragmentController.java

@@ -6,9 +6,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.goafanti.common.bo.Result;
 import com.goafanti.common.controller.BaseApiController;
-import com.goafanti.common.model.HtmlFragment;
 import com.goafanti.fragment.service.FragmentService;
 
 @RestController
@@ -19,17 +17,13 @@ public class FragmentController extends BaseApiController {
 	FragmentService fragmentService;
 
 	@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
-	public Result get(@PathVariable String id) {
-		return new Result(fragmentService.selectById(id));
+	public String get(@PathVariable String id) {
+		return fragmentService.selectById(id);
 	}
 
 	@RequestMapping(value = "/json/{id}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
 	public String json(@PathVariable String id) {
-		HtmlFragment hf = fragmentService.selectById(id);
-		if (hf != null) {
-			return hf.getContent();
-		}
-		return "{}";
+		return fragmentService.selectById(id);
 	}
 
 }

+ 9 - 5
src/main/java/com/goafanti/fragment/service/FragmentService.java

@@ -17,14 +17,18 @@ public class FragmentService extends BaseMybatisDao<HtmlFragmentMapper> {
 	HtmlFragmentMapper htmlFragmentMapper;
 
 	@Cacheable(value = "HtmlFragmentCache", key = "'HtmlFragment:'+#id")
-	public HtmlFragment selectById(String id) {
-		return htmlFragmentMapper.selectByPrimaryKey(id);
+	public String selectById(String id) {
+		HtmlFragment hf = htmlFragmentMapper.selectByPrimaryKey(id);
+		return hf == null ? "" : hf.getContent();
 	}
 
 	@CachePut(value = "HtmlFragmentCache", key = "'HtmlFragment:'+#id")
-	public HtmlFragment save(String id, HtmlFragment record) {
-		htmlFragmentMapper.insert(record);
-		return record;
+	public String save(String id, String content) {
+		HtmlFragment hf = new HtmlFragment();
+		hf.setContent(content);
+		hf.setId(id);
+		htmlFragmentMapper.insert(hf);
+		return content;
 	}
 
 }