5 Commits f0780ca6bd ... b1c5515417

Author SHA1 Message Date
  liuchuanwei b1c5515417 test:调试接口脚本 1 month ago
  liuchuanwei 1a74b1eb21 feat:新增人情明细批量删除接口 1 month ago
  liuchuanwei 68caf7b3f7 refactor:重构人情明细分页接口 1 month ago
  liuchuanwei 14be4d5051 feat:修改人情事件分页列表和删除接口 1 month ago
  liuchuanwei 363da6865b refactor:修改接口分页参数 1 month ago

+ 5 - 0
http-client.env.json

@@ -0,0 +1,5 @@
+{
+  "dev": {
+    "api_url": "http://localhost:8080"
+  }
+}

+ 6 - 0
pom.xml

@@ -114,5 +114,11 @@
             <version>2.6</version>
             <version>2.6</version>
         </dependency>
         </dependency>
 
 
+        <!--google guava -->
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>33.2.1-jre</version>
+        </dependency>
     </dependencies>
     </dependencies>
 </project>
 </project>

+ 7 - 7
src/main/java/com/anyway/favor/controller/FavorController.java

@@ -1,8 +1,8 @@
 package com.anyway.favor.controller;
 package com.anyway.favor.controller;
 
 
-import com.anyway.favor.model.dto.FavorDto;
 import com.anyway.favor.model.Favor;
 import com.anyway.favor.model.Favor;
 import com.anyway.favor.model.User;
 import com.anyway.favor.model.User;
+import com.anyway.favor.model.dto.FavorDto;
 import com.anyway.favor.service.FavorService;
 import com.anyway.favor.service.FavorService;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageQuery;
 import com.anyway.util.R;
 import com.anyway.util.R;
@@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
 
 
@@ -61,19 +62,18 @@ public class FavorController {
      * @param pageQuery
      * @param pageQuery
      * @return
      * @return
      */
      */
-    @ResponseBody
-    @RequestMapping("/listPage")
+    @GetMapping("/listPage")
     public R<List<Favor>> listPage(@RequestBody PageQuery<Map<String, Object>> pageQuery) {
     public R<List<Favor>> listPage(@RequestBody PageQuery<Map<String, Object>> pageQuery) {
         User currentUser = SessionUtils.currentUser();
         User currentUser = SessionUtils.currentUser();
-        Map<String, Object> mapCondition = pageQuery.getTerms();
+        Map<String, Object> mapCondition = pageQuery.getTerms(new HashMap<>());
         //查询和当前登录用户相关的人员
         //查询和当前登录用户相关的人员
-        mapCondition.put("relatedId", currentUser.getId());
+        mapCondition.put("createBy", currentUser.getId());
         List<Favor> favorList = favorService.findPage(pageQuery);
         List<Favor> favorList = favorService.findPage(pageQuery);
         return R.page(favorList, pageQuery.getPage());
         return R.page(favorList, pageQuery.getPage());
     }
     }
 
 
     /**
     /**
-     * 跳转人情详情页面
+     * 人情事件详情
      *
      *
      * @return
      * @return
      */
      */
@@ -89,7 +89,7 @@ public class FavorController {
      * @return
      * @return
      */
      */
     @PostMapping("/delete/{id}")
     @PostMapping("/delete/{id}")
-    public R delete(@PathVariable Long id) {
+    public R<Boolean> delete(@PathVariable Long id) {
         boolean b = favorService.deleteById(id);
         boolean b = favorService.deleteById(id);
         return b ? R.ok() : R.fail("删除失败");
         return b ? R.ok() : R.fail("删除失败");
     }
     }

+ 49 - 27
src/main/java/com/anyway/favor/controller/FavorItemController.java

@@ -2,19 +2,20 @@ package com.anyway.favor.controller;
 
 
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.User;
 import com.anyway.favor.model.User;
+import com.anyway.favor.model.vo.FavorItemVo;
 import com.anyway.favor.service.FavorItemService;
 import com.anyway.favor.service.FavorItemService;
+import com.anyway.favor.service.FavorService;
+import com.anyway.favor.service.GiftService;
+import com.anyway.favor.service.PersonService;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageQuery;
 import com.anyway.util.R;
 import com.anyway.util.R;
 import com.anyway.util.SessionUtils;
 import com.anyway.util.SessionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 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.ResponseBody;
-import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.bind.annotation.*;
 
 
-import java.util.List;
-import java.util.Map;
+import javax.validation.constraints.NotBlank;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * 人情明细控制器
  * 人情明细控制器
@@ -22,38 +23,59 @@ import java.util.Map;
  * @author liuchuanwei
  * @author liuchuanwei
  * @date 2024-02-24
  * @date 2024-02-24
  */
  */
-@Controller
+@RestController
 @RequestMapping("/favorItem")
 @RequestMapping("/favorItem")
 public class FavorItemController {
 public class FavorItemController {
     @Autowired
     @Autowired
     private FavorItemService favorItemService;
     private FavorItemService favorItemService;
-
+    @Autowired
+    private PersonService personService;
+    @Autowired
+    private FavorService favorService;
+    @Autowired
+    private GiftService giftService;
     /**
     /**
-     * 跳转列表页面
+     * 人情明细分页
      *
      *
-     * @param mv
+     * @param pageQuery
      * @return
      * @return
      */
      */
-    @RequestMapping("/toList")
-    public ModelAndView toList(ModelAndView mv) {
-        mv.setViewName("/favorItem/list");
-        return mv;
+    @GetMapping("/listPage")
+    public R<List<FavorItemVo>> listPage(@RequestBody PageQuery<Map<String, Object>> pageQuery) {
+        User currentUser = SessionUtils.currentUser();
+        Map<String, Object> mapCondition = pageQuery.getTerms(new HashMap<>());
+        //查询和当前登录用户相关的人员
+        mapCondition.put("createBy", currentUser.getId());
+        mapCondition.put("sortName", "id");
+        mapCondition.put("sortOrder", "asc");
+        List<FavorItem> favorItemList = favorItemService.findPage(pageQuery);
+        //补充人情明细的关联信息
+        List<FavorItemVo> favorItemVoList = new ArrayList<>();
+        for (FavorItem favorItem : favorItemList) {
+            FavorItemVo favorItemVo = new FavorItemVo(favorItem);
+            favorItemVo.setFavor(favorService.findById(favorItem.getFavorId()));
+            favorItemVo.setHoldPerson(personService.findById(favorItemVo.getFavor().getHoldPersonId()));
+            favorItemVo.setReceivePerson(personService.findById(favorItem.getReceivePersonId()));
+            favorItemVo.setReturnGift(giftService.findById(favorItem.getReturnGiftId()));
+            favorItemVo.setGivePerson(personService.findById(favorItem.getGivePersonId()));
+            favorItemVo.setGiveGift(giftService.findById(favorItem.getGiveGiftId()));
+            favorItemVoList.add(favorItemVo);
+        }
+        return R.page(favorItemVoList, pageQuery.getPage());
     }
     }
 
 
     /**
     /**
-     * 人情往来记录列表
+     * 批量删除
      *
      *
-     * @param pageQuery
+     * @param ids
      * @return
      * @return
      */
      */
-    @ResponseBody
-    @RequestMapping("/listPage")
-    public R listPage(@RequestBody PageQuery<Map<String, Object>> pageQuery) {
-        User currentUser = SessionUtils.currentUser();
-        Map<String, Object> mapCondition = pageQuery.getTerms();
-        //查询和当前登录用户相关的人员
-//        mapCondition.put("createBy", currentUser.getId());
-        List<FavorItem> favorItemList = favorItemService.findPage(pageQuery);
-        return R.page(favorItemList, pageQuery.getPage());
+    @PostMapping("/delete")
+    public R<Boolean> delete(@RequestParam("ids") @NotBlank String ids) {
+        String[] arr = ids.split(",");
+        List<Long> idList = Arrays.stream(arr).map(Long::valueOf).collect(Collectors.toList());
+        boolean b = favorItemService.deleteByIds(idList);
+        return b ? R.ok() : R.fail("删除失败");
     }
     }
-}
+
+}

+ 8 - 0
src/main/java/com/anyway/favor/dao/FavorItemDao.java

@@ -47,6 +47,14 @@ public interface FavorItemDao {
     FavorItem findById(Long id);
     FavorItem findById(Long id);
 
 
     /**
     /**
+     * 根据主键ID集合查询
+     *
+     * @param id
+     * @return
+     */
+    List<FavorItem> findByIds(Collection<Long> id);
+
+    /**
      * 插入
      * 插入
      *
      *
      * @param favorItemList
      * @param favorItemList

+ 1 - 2
src/main/java/com/anyway/favor/dao/GiftDao.java

@@ -1,6 +1,5 @@
 package com.anyway.favor.dao;
 package com.anyway.favor.dao;
 
 
-import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.Gift;
 import com.anyway.favor.model.Gift;
 
 
 import java.util.Collection;
 import java.util.Collection;
@@ -19,7 +18,7 @@ public interface GiftDao {
      * @param id
      * @param id
      * @return
      * @return
      */
      */
-    FavorItem findById(Long id);
+    Gift findById(Long id);
 
 
     /**
     /**
      * 插入
      * 插入

+ 3 - 0
src/main/java/com/anyway/favor/model/BaseModel.java

@@ -1,5 +1,6 @@
 package com.anyway.favor.model;
 package com.anyway.favor.model;
 
 
+import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Getter;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.Setter;
 
 
@@ -15,12 +16,14 @@ import java.util.Date;
 @Getter
 @Getter
 public class BaseModel {
 public class BaseModel {
     /** 创建时间 */
     /** 创建时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
     private Date createTime;
     private Date createTime;
 
 
     /** 创建者 */
     /** 创建者 */
     private Long createBy;
     private Long createBy;
 
 
     /** 修改时间 */
     /** 修改时间 */
+    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
     private Date modifyTime;
     private Date modifyTime;
 
 
     /** 修改者 */
     /** 修改者 */

+ 4 - 2
src/main/java/com/anyway/favor/model/FavorItem.java

@@ -7,7 +7,7 @@ import javax.validation.constraints.NotNull;
 
 
 /**
 /**
  * 人情明细表(t_favor_item)
  * 人情明细表(t_favor_item)
- * 
+ *
  * @author anyway
  * @author anyway
  * @date 2024-02-20
  * @date 2024-02-20
  */
  */
@@ -33,4 +33,6 @@ public class FavorItem extends BaseModel implements java.io.Serializable {
     private Long giveGiftId;
     private Long giveGiftId;
     /** 备注 */
     /** 备注 */
     private String remark;
     private String remark;
-}
+    /** 排序 */
+    private int sort;
+}

+ 4 - 1
src/main/java/com/anyway/favor/model/dto/FavorDto.java

@@ -25,7 +25,10 @@ public class FavorDto extends Favor {
 
 
     /** 人情明细 */
     /** 人情明细 */
     List<FavorItemDto> favorItemList;
     List<FavorItemDto> favorItemList;
-
+    /**
+     * 初始化人情明细
+     * @param favorItemList
+     */
     public void initFavorItemList(List<FavorItem> favorItemList) {
     public void initFavorItemList(List<FavorItem> favorItemList) {
         if (this.favorItemList == null) {
         if (this.favorItemList == null) {
             this.favorItemList = new ArrayList<>();
             this.favorItemList = new ArrayList<>();

+ 34 - 0
src/main/java/com/anyway/favor/model/vo/FavorItemVo.java

@@ -0,0 +1,34 @@
+package com.anyway.favor.model.vo;
+
+import com.anyway.favor.model.Favor;
+import com.anyway.favor.model.FavorItem;
+import com.anyway.favor.model.Gift;
+import com.anyway.favor.model.Person;
+import lombok.Data;
+import org.springframework.beans.BeanUtils;
+
+/**
+ * 人情明细
+ *
+ * @author liuchuanwei
+ * @date 2024-08-12
+ */
+@Data
+public class FavorItemVo extends FavorItem {
+    /** 人情事件 */
+    private Favor favor;
+    /** 举办人 */
+    private Person holdPerson;
+    /** 收礼人 */
+    private Person receivePerson;
+    /** 回赠礼物 */
+    private Gift returnGift;
+    /** 送礼人 */
+    private Person givePerson;
+    /** 赠送礼物 */
+    private Gift giveGift;
+
+    public FavorItemVo(FavorItem favorItem) {
+        BeanUtils.copyProperties(favorItem, this);
+    }
+}

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

@@ -62,5 +62,29 @@ public interface FavorItemService {
      */
      */
     FavorItem findById(Long id);
     FavorItem findById(Long id);
 
 
+    /**
+     * 根据IDS删除
+     *
+     * @param ids
+     * @return
+     */
+    boolean deleteByIds(List<Long> ids);
+
+    /**
+     * 根据人情事件ID删除
+     *
+     * @param favorId
+     * @return
+     */
+    boolean deleteByFavorId(Long favorId);
+
+    /**
+     * 批量删除
+     *
+     * @param favorItemList
+     * @return
+     */
+    boolean batchDelete(List<? extends FavorItem> favorItemList);
+
 
 
 }
 }

+ 8 - 0
src/main/java/com/anyway/favor/service/FavorService.java

@@ -62,4 +62,12 @@ public interface FavorService {
      * @return
      * @return
      */
      */
     boolean deleteById(Long id);
     boolean deleteById(Long id);
+
+    /**
+     * 根据ID查询
+     *
+     * @param id
+     * @return
+     */
+    Favor findById(Long id);
 }
 }

+ 44 - 0
src/main/java/com/anyway/favor/service/GiftService.java

@@ -0,0 +1,44 @@
+package com.anyway.favor.service;
+
+import com.anyway.favor.model.Gift;
+
+/**
+ * 礼物接口
+ *
+ * @author anyway
+ * @date 2024-08-12
+ */
+public interface GiftService {
+
+    /**
+     * 添加
+     *
+     * @param person
+     * @return
+     */
+    boolean add(Gift person);
+
+    /**
+     * 更新
+     *
+     * @param person
+     * @return
+     */
+    boolean update(Gift person);
+
+    /**
+     * 根据ID查询
+     *
+     * @param id
+     * @return
+     */
+    Gift findById(Long id);
+
+    /**
+     * 根据ID删除
+     * @param id
+     * @return
+     */
+    int delete(Long id);
+
+}

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

@@ -1,36 +1,43 @@
 package com.anyway.favor.service.impl;
 package com.anyway.favor.service.impl;
 
 
 import com.anyway.favor.dao.FavorItemDao;
 import com.anyway.favor.dao.FavorItemDao;
+import com.anyway.favor.dao.GiftDao;
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.FavorItem;
+import com.anyway.favor.model.dto.FavorItemDto;
 import com.anyway.favor.service.FavorItemService;
 import com.anyway.favor.service.FavorItemService;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageUtils;
 import com.anyway.util.PageUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import java.util.*;
 
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 /**
 /**
  * 人情明细业务实现类
  * 人情明细业务实现类
  *
  *
  * @author liuchuanwei
  * @author liuchuanwei
  * @date 2024-02-24
  * @date 2024-02-24
  */
  */
+@Slf4j
 @Service
 @Service
 public class FavorItemServiceImpl implements FavorItemService {
 public class FavorItemServiceImpl implements FavorItemService {
     @Autowired
     @Autowired
-    private FavorItemDao favorItemMapper;
+    private FavorItemDao favorItemDao;
+    @Autowired
+    private GiftDao giftDao;
 
 
     @Override
     @Override
     public List<FavorItem> findByCondition(Map<String, Object> map) {
     public List<FavorItem> findByCondition(Map<String, Object> map) {
-        return favorItemMapper.findByCondition(map);
+        return favorItemDao.findByCondition(map);
     }
     }
     @Override
     @Override
     public List<FavorItem> findPage(PageQuery<Map<String, Object>> pageQuery) {
     public List<FavorItem> findPage(PageQuery<Map<String, Object>> pageQuery) {
-        PageUtils.startPage(pageQuery);
-        List<FavorItem> favorItemList = favorItemMapper.findByCondition(pageQuery.getTerms());
-        PageUtils.setPageTotal(favorItemList, pageQuery);
+        PageUtils.startPage(pageQuery.getPage());
+        List<FavorItem> favorItemList = favorItemDao.findByCondition(pageQuery.getTerms());
+        PageUtils.setPageTotal(favorItemList, pageQuery.getPage());
         return favorItemList;
         return favorItemList;
     }
     }
 
 
@@ -42,7 +49,7 @@ public class FavorItemServiceImpl implements FavorItemService {
             map.put("sortName", "create_time");
             map.put("sortName", "create_time");
             map.put("sortOrder", "asc");
             map.put("sortOrder", "asc");
         }
         }
-        return favorItemMapper.findByCondition(map);
+        return favorItemDao.findByCondition(map);
     }
     }
 
 
     @Override
     @Override
@@ -59,4 +66,44 @@ public class FavorItemServiceImpl implements FavorItemService {
     public FavorItem findById(Long id) {
     public FavorItem findById(Long id) {
         return null;
         return null;
     }
     }
+
+    @Transactional
+    @Override
+    public boolean deleteByIds(List<Long> ids) {
+        List<FavorItem> favorItemList = favorItemDao.findByIds(ids);
+        return this.batchDelete(favorItemList);
+    }
+
+    @Transactional
+    @Override
+    public boolean deleteByFavorId(Long favorId) {
+        List<FavorItemDto> favorItemDtoList = favorItemDao.findByFavorId(favorId);
+        return this.batchDelete(favorItemDtoList);
+    }
+
+    @Transactional
+    @Override
+    public boolean batchDelete(List<? extends FavorItem> favorItemList) {
+        if(CollectionUtils.isEmpty(favorItemList)) {
+            log.warn("删除失败,人情明细列表为空");
+            return false;
+        }
+        Set<Long> favorItemIdSet = new HashSet<>();
+        //删除礼物
+        Set<Long> giftIdSet = new HashSet<>();
+        for (FavorItem favorItem : favorItemList) {
+            favorItemIdSet.add(favorItem.getId());
+            giftIdSet.add(favorItem.getGiveGiftId());
+            if (favorItem.getReturnGiftId() != null) {
+                giftIdSet.add(favorItem.getReturnGiftId());
+            }
+        }
+        giftDao.deleteByIds(giftIdSet);
+        int r = favorItemDao.deleteByIds(favorItemIdSet);
+        if (r <= 0) {
+            log.error("人情明细删除失败:{}", favorItemIdSet);
+            return false;
+        }
+        return true;
+    }
 }
 }

+ 48 - 16
src/main/java/com/anyway/favor/service/impl/FavorServiceImpl.java

@@ -1,23 +1,30 @@
 package com.anyway.favor.service.impl;
 package com.anyway.favor.service.impl;
 
 
-import com.anyway.favor.model.dto.FavorDto;
-import com.anyway.favor.model.dto.FavorItemDto;
+import com.anyway.favor.BusinessException;
 import com.anyway.favor.dao.FavorDao;
 import com.anyway.favor.dao.FavorDao;
 import com.anyway.favor.dao.FavorItemDao;
 import com.anyway.favor.dao.FavorItemDao;
 import com.anyway.favor.dao.GiftDao;
 import com.anyway.favor.dao.GiftDao;
 import com.anyway.favor.model.Favor;
 import com.anyway.favor.model.Favor;
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.FavorItem;
 import com.anyway.favor.model.Gift;
 import com.anyway.favor.model.Gift;
+import com.anyway.favor.model.dto.FavorDto;
+import com.anyway.favor.model.dto.FavorItemDto;
+import com.anyway.favor.service.FavorItemService;
 import com.anyway.favor.service.FavorService;
 import com.anyway.favor.service.FavorService;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageUtils;
 import com.anyway.util.PageUtils;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
+import javax.annotation.PostConstruct;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
@@ -33,10 +40,31 @@ public class FavorServiceImpl implements FavorService {
     @Autowired
     @Autowired
     private FavorDao favorDao;
     private FavorDao favorDao;
     @Autowired
     @Autowired
+    private FavorItemService favorItemService;
+    @Autowired
     private FavorItemDao favorItemDao;
     private FavorItemDao favorItemDao;
     @Autowired
     @Autowired
     private GiftDao giftDao;
     private GiftDao giftDao;
 
 
+    /**
+     * 人员缓存
+     */
+    private LoadingCache<Long, Favor> favorCache;
+
+    @PostConstruct
+    public void init() {
+        favorCache = CacheBuilder.newBuilder()
+                .maximumSize(100)
+                .expireAfterWrite(5, TimeUnit.MINUTES)
+                .build(new CacheLoader<Long, Favor>() {
+                    @Override
+                    public Favor load(Long id) {
+                        return favorDao.findById(id);
+                    }
+                });
+    }
+
+
     @Override
     @Override
     public List<Favor> findByCondition(Map<String, Object> map) {
     public List<Favor> findByCondition(Map<String, Object> map) {
         return favorDao.findByCondition(map);
         return favorDao.findByCondition(map);
@@ -44,9 +72,9 @@ public class FavorServiceImpl implements FavorService {
 
 
     @Override
     @Override
     public List<Favor> findPage(PageQuery<Map<String, Object>> pageQuery) {
     public List<Favor> findPage(PageQuery<Map<String, Object>> pageQuery) {
-        PageUtils.startPage(pageQuery);
+        PageUtils.startPage(pageQuery.getPage());
         List<Favor> favorList = favorDao.findByCondition(pageQuery.getTerms());
         List<Favor> favorList = favorDao.findByCondition(pageQuery.getTerms());
-        PageUtils.setPageTotal(favorList, pageQuery);
+        PageUtils.setPageTotal(favorList, pageQuery.getPage());
         return favorList;
         return favorList;
     }
     }
 
 
@@ -165,21 +193,25 @@ public class FavorServiceImpl implements FavorService {
         return favorDto;
         return favorDto;
     }
     }
 
 
+    @Transactional
     @Override
     @Override
     public boolean deleteById(Long id) {
     public boolean deleteById(Long id) {
         int i = favorDao.deleteById(id);
         int i = favorDao.deleteById(id);
-        if (i>0) {
-            List<FavorItemDto> favorItemList = favorItemDao.findByFavorId(id);
-            Set<Long> giftIdSet = new HashSet<>();
-            for (FavorItem favorItem : favorItemList) {
-                giftIdSet.add(favorItem.getGiveGiftId());
-                if (favorItem.getReturnGiftId() != null) {
-                    giftIdSet.add(favorItem.getReturnGiftId());
-                }
-            }
-            giftDao.deleteByIds(giftIdSet);
-            favorItemDao.deleteByFavorId(id);
+        if (i <= 0) {
+            log.error("删除人情事件失败,人情事件:{}", id);
+            return false;
         }
         }
-        return i>0;
+        //删除人情明细
+        boolean b = favorItemService.deleteByFavorId(id);
+        if (!b) {
+            log.error("删除人情明细失败,人情事件:{}", id);
+            throw new BusinessException("删除人情明细失败");
+        }
+        return true;
+    }
+
+    @Override
+    public Favor findById(Long id) {
+        return favorCache.getUnchecked(id);
     }
     }
 }
 }

+ 59 - 0
src/main/java/com/anyway/favor/service/impl/GiftServiceImpl.java

@@ -0,0 +1,59 @@
+package com.anyway.favor.service.impl;
+
+import com.anyway.favor.dao.GiftDao;
+import com.anyway.favor.model.Gift;
+import com.anyway.favor.service.GiftService;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class GiftServiceImpl implements GiftService {
+
+    @Autowired
+    private GiftDao giftDao;
+
+    /**
+     * 人员缓存
+     */
+    private LoadingCache<Long, Gift> giftCache;
+
+    @PostConstruct
+    public void init() {
+        giftCache = CacheBuilder.newBuilder()
+                .maximumSize(100)
+                .expireAfterWrite(5, TimeUnit.MINUTES)
+                .build(new CacheLoader<Long, Gift>() {
+                    @Override
+                    public Gift load(Long id) {
+                        return giftDao.findById(id);
+                    }
+                });
+    }
+
+
+    @Override
+    public boolean add(Gift person) {
+        return false;
+    }
+
+    @Override
+    public boolean update(Gift person) {
+        return false;
+    }
+
+    @Override
+    public Gift findById(Long id) {
+        return null;
+    }
+
+    @Override
+    public int delete(Long id) {
+        return 0;
+    }
+}

+ 25 - 3
src/main/java/com/anyway/favor/service/impl/PersonServiceImpl.java

@@ -5,13 +5,18 @@ import com.anyway.favor.model.Person;
 import com.anyway.favor.service.PersonService;
 import com.anyway.favor.service.PersonService;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageQuery;
 import com.anyway.util.PageUtils;
 import com.anyway.util.PageUtils;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import javax.annotation.PostConstruct;
 import java.util.Arrays;
 import java.util.Arrays;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 
 /**
 /**
  * 人员业务实现类
  * 人员业务实现类
@@ -25,6 +30,23 @@ public class PersonServiceImpl implements PersonService {
 
 
     @Autowired
     @Autowired
     private PersonDao personMapper;
     private PersonDao personMapper;
+    /**
+     * 人员缓存
+     */
+    private LoadingCache<Long, Person> personCache;
+
+    @PostConstruct
+    public void init() {
+        personCache = CacheBuilder.newBuilder()
+                .maximumSize(100)
+                .expireAfterWrite(5, TimeUnit.MINUTES)
+                .build(new CacheLoader<Long, Person>() {
+                    @Override
+                    public Person load(Long id) {
+                        return personMapper.findById(id);
+                    }
+                });
+    }
 
 
     @Override
     @Override
     public List<Person> findAll() {
     public List<Person> findAll() {
@@ -38,9 +60,9 @@ public class PersonServiceImpl implements PersonService {
 
 
     @Override
     @Override
     public List<Person> findPage(PageQuery<Map<String, Object>> pageQuery) {
     public List<Person> findPage(PageQuery<Map<String, Object>> pageQuery) {
-        PageUtils.startPage(pageQuery);
+        PageUtils.startPage(pageQuery.getPage());
         List<Person> personList = personMapper.findByCondition(pageQuery.getTerms());
         List<Person> personList = personMapper.findByCondition(pageQuery.getTerms());
-        PageUtils.setPageTotal(personList, pageQuery);
+        PageUtils.setPageTotal(personList, pageQuery.getPage());
         return personList;
         return personList;
     }
     }
 
 
@@ -59,7 +81,7 @@ public class PersonServiceImpl implements PersonService {
 
 
     @Override
     @Override
     public Person findById(Long id) {
     public Person findById(Long id) {
-        return personMapper.findById(id);
+        return personCache.getUnchecked(id);
     }
     }
 
 
     @Override
     @Override

+ 5 - 0
src/main/java/com/anyway/util/Page.java

@@ -28,4 +28,9 @@ public class Page {
     private long total;
     private long total;
     /** 总页数 */
     /** 总页数 */
     private int totalPage;
     private int totalPage;
+
+    public Page(int pageNo, int pageSize) {
+        this.pageNo = pageNo;
+        this.pageSize = pageSize;
+    }
 }
 }

+ 17 - 8
src/main/java/com/anyway/util/PageQuery.java

@@ -13,7 +13,12 @@ import lombok.Setter;
  */
  */
 @Setter
 @Setter
 @Getter
 @Getter
-public class PageQuery<T> extends Page{
+public class PageQuery<T> {
+    /**
+     * 分页信息
+     */
+    private Page page;
+
     /**
     /**
      * 查询条件
      * 查询条件
      */
      */
@@ -21,13 +26,17 @@ public class PageQuery<T> extends Page{
     @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
     @JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
     private T terms;
     private T terms;
 
 
-    /**
-     * 返回分页对象
-     *
-     * @return
-     */
-    public Page getPage() {
-        return new Page(this.getPageNo(), this.getPageSize(), this.getSortName(), this.getSortOrder(), this.getTotal(), this.getTotalPage());
+    public T getTerms(T t) {
+        if (terms == null) {
+            terms = t;
+        }
+        return terms;
     }
     }
 
 
+    public Page getPage() {
+        if (page == null) {
+            page = new Page(0, 10);
+        }
+        return this.page;
+    }
 }
 }

+ 14 - 4
src/main/resources/mapper/FavorItemMapper.xml

@@ -76,10 +76,10 @@
             <if test="holdDate != null">
             <if test="holdDate != null">
                 AND f.holdDate = #{holdDate}
                 AND f.holdDate = #{holdDate}
             </if>
             </if>
-            <if test="sortName != null">
-                ORDER BY fi.${sortName} ${sortOrder}
-            </if>
         </where>
         </where>
+        <if test="sortName != null">
+            ORDER BY fi.${sortName} ${sortOrder}
+        </if>
     </select>
     </select>
 
 
     <!-- 根据主键查询人情明细表信息 -->
     <!-- 根据主键查询人情明细表信息 -->
@@ -89,6 +89,16 @@
         FROM t_favor_item fi WHERE fi.id = #{id}
         FROM t_favor_item fi WHERE fi.id = #{id}
     </select>
     </select>
 
 
+    <!-- 根据主键查询人情明细表信息 -->
+    <select id="findByIds" resultMap="favorItemMap">
+        SELECT
+        <include refid="allColumns" />
+        FROM t_favor_item fi WHERE fi.id in
+        <foreach collection="collection" item="id" separator="," open="(" close=")">
+            #{id}
+        </foreach>
+    </select>
+
     <!-- 批量新增人情明细表信息 -->
     <!-- 批量新增人情明细表信息 -->
     <insert id="batchAdd" parameterType="list">
     <insert id="batchAdd" parameterType="list">
         INSERT INTO t_favor_item (
         INSERT INTO t_favor_item (
@@ -153,4 +163,4 @@
         DELETE FROM t_favor_item WHERE favor_id = #{favorId}
         DELETE FROM t_favor_item WHERE favor_id = #{favorId}
     </delete>
     </delete>
 
 
-</mapper>
+</mapper>

+ 2 - 2
src/main/resources/mapper/FavorMapper.xml

@@ -17,7 +17,7 @@
             <include refid="allColumns" />,
             <include refid="allColumns" />,
             concat(p.name, '(', p.call_name, ')') as person_name
             concat(p.name, '(', p.call_name, ')') as person_name
         FROM t_favor f
         FROM t_favor f
-        LEFT JOIN t_person p ON p.id=f.person_id
+        LEFT JOIN t_person p ON p.id=f.hold_person_id
         WHERE 1 = 1
         WHERE 1 = 1
         <if test="holdDate != null">
         <if test="holdDate != null">
             AND f.hold_date = #{holdDate}
             AND f.hold_date = #{holdDate}
@@ -85,4 +85,4 @@
         DELETE FROM t_favor WHERE id = #{id}
         DELETE FROM t_favor WHERE id = #{id}
     </delete>
     </delete>
 
 
-</mapper>
+</mapper>

+ 2 - 2
src/main/resources/mapper/GiftMapper.xml

@@ -13,7 +13,7 @@
     <select id="findById" resultMap="giftMap">
     <select id="findById" resultMap="giftMap">
         SELECT
         SELECT
             <include refid="allColumns" />
             <include refid="allColumns" />
-        FROM t_gift fi WHERE fi.id = #{id}
+        FROM t_gift g WHERE g.id = #{id}
     </select>
     </select>
 
 
     <!-- 新增礼物表信息 -->
     <!-- 新增礼物表信息 -->
@@ -49,4 +49,4 @@
             #{id}
             #{id}
         </foreach>
         </foreach>
     </delete>
     </delete>
-</mapper>
+</mapper>

+ 5 - 12
src/main/resources/mapper/PersonDao.xml

@@ -4,12 +4,12 @@
 <!-- 人员表(t_person) -->
 <!-- 人员表(t_person) -->
 <mapper namespace="com.anyway.favor.dao.PersonDao">
 <mapper namespace="com.anyway.favor.dao.PersonDao">
     <!-- 字段映射 -->
     <!-- 字段映射 -->
-    <resultMap id="personMap" type="com.anyway.favor.model.Person"></resultMap>
+    <resultMap id="personMap" type="com.anyway.favor.model.Person" />
 
 
     <!-- 表查询字段 -->
     <!-- 表查询字段 -->
     <sql id="allColumns">
     <sql id="allColumns">
-        p.id, p.name, p.card_id, p.call_name, p.gender, p.birthday, p.death_date, p.marital_status, 
-        p.mate_id, p.mother_id, p.father_id, p.sort, p.related_id, p.address, p.remark, p.create_time, p.create_by, p.modify_time,
+        p.id, p.name, p.card_id, p.call_name, p.gender, p.birthday, p.death_date, p.marital_status,
+        p.mate_id, p.mother_id, p.father_id, p.sort, p.address, p.remark, p.create_time, p.create_by, p.modify_time,
         p.modify_by
         p.modify_by
     </sql>
     </sql>
 
 
@@ -62,9 +62,6 @@
         <if test="address != null and address != ''">
         <if test="address != null and address != ''">
             AND p.address = #{address}
             AND p.address = #{address}
         </if>
         </if>
-        <if test="relatedId != null">
-            AND p.related_id = #{relatedId}
-        </if>
         <if test="familyPersonId != null and familyPersonId != ''">
         <if test="familyPersonId != null and familyPersonId != ''">
             AND (
             AND (
                 p.id=#{familyPersonId} OR p.mate_id=#{familyPersonId} OR p.mother_id=#{familyPersonId} OR p.father_id=#{familyPersonId}
                 p.id=#{familyPersonId} OR p.mate_id=#{familyPersonId} OR p.mother_id=#{familyPersonId} OR p.father_id=#{familyPersonId}
@@ -102,7 +99,7 @@
     <insert id="add" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
     <insert id="add" keyColumn="id" keyProperty="id" useGeneratedKeys="true">
         INSERT INTO t_person (
         INSERT INTO t_person (
             name, card_id, call_name, gender, birthday, death_date, marital_status,
             name, card_id, call_name, gender, birthday, death_date, marital_status,
-            mate_id, mother_id, father_id, sort, related_id, address, remark, create_by
+            mate_id, mother_id, father_id, sort, address, remark, create_by
         ) VALUES (
         ) VALUES (
             #{name},
             #{name},
             #{cardId},
             #{cardId},
@@ -115,7 +112,6 @@
             #{motherId},
             #{motherId},
             #{fatherId},
             #{fatherId},
             #{sort},
             #{sort},
-            #{relatedId},
             #{address},
             #{address},
             #{remark},
             #{remark},
             #{createBy}
             #{createBy}
@@ -159,9 +155,6 @@
             <if test="sort != null">
             <if test="sort != null">
                 sort = #{sort},
                 sort = #{sort},
             </if>
             </if>
-            <if test="relatedId != null">
-                related_id = #{relatedId},
-            </if>
             <if test="address != null">
             <if test="address != null">
                 address = #{address},
                 address = #{address},
             </if>
             </if>
@@ -195,4 +188,4 @@
     <update id="updateNullFather">
     <update id="updateNullFather">
         UPDATE t_person p set p.father_id=Null WHERE p.father_id=#{id}
         UPDATE t_person p set p.father_id=Null WHERE p.father_id=#{id}
     </update>
     </update>
-</mapper>
+</mapper>

+ 33 - 18
api-test.http → 人情事件.http

@@ -1,5 +1,5 @@
 ### 新增人情事件
 ### 新增人情事件
-POST http://localhost:8080/favor/add
+POST {{api_url}}/favor/add
 Content-Type: application/json
 Content-Type: application/json
 
 
 {
 {
@@ -44,7 +44,7 @@ Content-Type: application/json
 }
 }
 
 
 ### 查询人情事件详情
 ### 查询人情事件详情
-GET http://localhost:8080/favor/detail/1
+GET {{api_url}}/favor/detail/2
 
 
 ### 修改人情事件
 ### 修改人情事件
 POST http://localhost:8080/favor/update
 POST http://localhost:8080/favor/update
@@ -60,39 +60,54 @@ Content-Type: application/json
   "remark": "祝贺1",
   "remark": "祝贺1",
   "favorItemList": [
   "favorItemList": [
     {
     {
-      "id": 1,
+      "id": 9,
       "favorId": 1,
       "favorId": 1,
       "receivePersonId": 1,
       "receivePersonId": 1,
-      "givePersonId": 2,
-      "remark": "恭喜1",
+      "givePersonId": 6,
+      "remark": "恭喜恭喜恭喜",
       "returnGift": {
       "returnGift": {
-        "id": 2,
-        "title": "1000斤猪肉",
+        "id": 16,
+        "title": "10斤牛肉",
         "type": "T",
         "type": "T",
-        "amount": 10300.00
+        "amount": 160.00
       },
       },
       "giveGift": {
       "giveGift": {
-        "id": 1,
-        "title": "11万",
+        "id": 15,
+        "title": "¥2000",
         "type": "M",
         "type": "M",
-        "amount": 110000.00
+        "amount": 2000.00
       }
       }
     },
     },
     {
     {
       "favorId": 1,
       "favorId": 1,
       "receivePersonId": 1,
       "receivePersonId": 1,
-      "givePersonId": 6,
-      "remark": "恭喜3",
+      "givePersonId": 7,
+      "remark": "恭喜发财",
       "returnGift": {
       "returnGift": {
-        "title": "300斤猪肉",
+        "title": "面粉",
         "type": "T",
         "type": "T",
-        "amount": 3300.00
+        "amount": 25.00
       },
       },
       "giveGift": {
       "giveGift": {
-        "title": "3万",
+        "title": "¥400",
         "type": "M",
         "type": "M",
-        "amount": 30000.00
+        "amount": 400.00
       }
       }
     }
     }
   ]
   ]
-}
+}
+
+
+### 删除人情事件
+POST {{api_url}}/favor/delete/1
+
+### 查询人情事件列表
+GET {{api_url}}/favor/listPage
+Content-Type: application/json
+
+{
+  "page": {
+    "pageNo": 1,
+    "pageSize": 10
+  }
+}

+ 15 - 0
人情明细.http

@@ -0,0 +1,15 @@
+### 分页查询
+GET {{api_url}}/favorItem/listPage
+Content-Type: application/json
+
+{
+  "page": {
+    "pageNo": 1,
+    "pageSize": 10
+  }
+}
+
+
+### 删除人情事件
+POST {{api_url}}/favorItem/delete?ids=7
+Content-Type: application/json