Преглед на файлове

feat:新增人情往来记录分页接口

刘传伟 преди 5 месеца
родител
ревизия
401082f3a5

+ 15 - 72
src/main/java/com/anyway/favor/controller/FavorItemController.java

@@ -1,23 +1,18 @@
 package com.anyway.favor.controller;
 
-import com.anyway.favor.model.Favor;
 import com.anyway.favor.model.FavorItem;
-import com.anyway.favor.model.Person;
 import com.anyway.favor.model.User;
 import com.anyway.favor.service.FavorItemService;
-import com.anyway.favor.service.FavorService;
-import com.anyway.favor.service.PersonService;
+import com.anyway.util.PageQuery;
 import com.anyway.util.R;
 import com.anyway.util.SessionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -31,86 +26,34 @@ import java.util.Map;
 @RequestMapping("/favorItem")
 public class FavorItemController {
     @Autowired
-    private FavorService favorService;
-    @Autowired
     private FavorItemService favorItemService;
-    @Autowired
-    private PersonService personService;
-
-    /**
-     * 人情往来明细
-     *
-     * @param favorId
-     * @return
-     */
-    @RequestMapping("/listAll/{favorId}")
-    @ResponseBody
-    public R listAll(@PathVariable Long favorId) {
-        Map<String, Object> map = new HashMap<>();
-        map.put("favorId", favorId);
-        List<FavorItem> favorItemList = favorItemService.findByCondition(map);
-        return R.data(favorItemList);
-    }
 
     /**
-     * 跳转新增页面
+     * 跳转列表页面
      *
      * @param mv
      * @return
      */
-    @RequestMapping("/toAdd")
-    public ModelAndView toAdd(ModelAndView mv) {
-        mv.setViewName("edit");
-        //人员列表
-        Map<String, Object> map = new HashMap<>();
-        map.put("createBy", SessionUtils.currentUserId());
-        List<Person> personList = personService.findByCondition(map);
-        mv.addObject("personList", personList);
-        return mv;
-    }
-
-    /**
-     * 添加人情
-     *
-     * @param favor
-     * @return
-     */
-    @ResponseBody
-    @RequestMapping("/add")
-    public R add(@RequestBody Favor favor) {
-        User currentUser = SessionUtils.currentUser();
-        favor.setCreateBy(currentUser.getId());
-        favor.setModifyBy(currentUser.getId());
-        return favorService.add(favor) ? R.ok() : R.fail();
-    }
-
-    /**
-     * 跳转编辑人情页面
-     *
-     * @return
-     */
-    @RequestMapping("/edit/{id}")
-    public ModelAndView edit(@PathVariable Long id, ModelAndView mv) {
-        mv.setViewName("edit2");
-        Favor favor = favorService.findById(id);
-        mv.addObject("favor", favor);
-        //人员列表
-        List<Person> personList = personService.findAll();
-        mv.addObject("personList", personList);
+    @RequestMapping("/toList")
+    public ModelAndView toList(ModelAndView mv) {
+        mv.setViewName("/favorItem/list");
         return mv;
     }
 
     /**
-     * 更新人情
+     * 人情往来记录列表
      *
-     * @param favor
+     * @param pageQuery
      * @return
      */
     @ResponseBody
-    @RequestMapping("/update")
-    public R update(Favor favor) {
+    @RequestMapping("/listPage")
+    public R listPage(@RequestBody PageQuery<Map<String, Object>> pageQuery) {
         User currentUser = SessionUtils.currentUser();
-        favor.setModifyBy(currentUser.getId());
-        return favorService.update(favor) ? R.ok() : R.fail();
+        Map<String, Object> mapCondition = pageQuery.getTerms();
+        //查询和当前登录用户相关的人员
+//        mapCondition.put("createBy", currentUser.getId());
+        List<FavorItem> favorItemList = favorItemService.findPage(pageQuery);
+        return R.page(favorItemList, pageQuery.getPage());
     }
-}
+}

+ 9 - 0
src/main/java/com/anyway/favor/service/FavorItemService.java

@@ -1,6 +1,7 @@
 package com.anyway.favor.service;
 
 import com.anyway.favor.model.FavorItem;
+import com.anyway.util.PageQuery;
 
 import java.util.List;
 import java.util.Map;
@@ -22,6 +23,14 @@ public interface FavorItemService {
     List<FavorItem> findByCondition(Map<String, Object> map);
 
     /**
+     * 分页查询
+     *
+     * @param pageQuery
+     * @return
+     */
+    List<FavorItem> findPage(PageQuery<Map<String, Object>> pageQuery);
+
+    /**
      * 根据人情ID查询列表
      *
      * @param favorId

+ 9 - 0
src/main/java/com/anyway/favor/service/impl/FavorItemServiceImpl.java

@@ -3,6 +3,8 @@ package com.anyway.favor.service.impl;
 import com.anyway.favor.mapper.FavorItemMapper;
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.service.FavorItemService;
+import com.anyway.util.PageQuery;
+import com.anyway.util.PageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -24,6 +26,13 @@ public class FavorItemServiceImpl implements FavorItemService {
     public List<FavorItem> findByCondition(Map<String, Object> map) {
         return favorItemMapper.findByCondition(map);
     }
+    @Override
+    public List<FavorItem> findPage(PageQuery<Map<String, Object>> pageQuery) {
+        PageUtils.startPage(pageQuery);
+        List<FavorItem> favorItemList = favorItemMapper.findByCondition(pageQuery.getTerms());
+        PageUtils.setPageTotal(favorItemList, pageQuery);
+        return favorItemList;
+    }
 
     @Override
     public List<FavorItem> findByFavorId(Long favorId) {

+ 1 - 0
src/main/resources/mapper/FavorItemMapper.xml

@@ -29,6 +29,7 @@
             f.occur_date as "favor.occurDate",
             p.name as "person.name",
             p.call_name as "person.callName",
+            p.address as "person.address",
             ps.name as "sourcePerson.name",
             ps.call_name as "sourcePerson.callName",
             ps.address as "sourcePerson.address"