zqy
2 天以前 cedaeeed6d401aefebf93ea6ea21cc9e06d5f5db
zhang-content/src/main/java/com/ruoyi/service/impl/ZfEconomyServiceImpl.java
@@ -18,6 +18,8 @@
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -40,7 +42,7 @@
 */
@Service
@Slf4j
public class ZfEconomyServiceImpl extends ServiceImpl<ZfEconomyMapper, ZfEconomy> implements ZfEconomyService {
public class ZfEconomyServiceImpl extends ServiceImpl<ZfEconomyMapper, ZfEconomy> implements ZfEconomyService,ModuleSearchable{
    @Resource
    ZfEconomyService zfEconomyService;
@@ -59,6 +61,12 @@
    @Resource
    RestHighLevelClient restHighLevelClient;
    @Resource
    ZfEconomyShaService zfEconomyShaService;
    @Resource
    ZfEconomyDownlService zfEconomyDownlService;
    private LambdaQueryWrapper<ZfEconomy> buildCondition(ZfEconomy zfEconomy,List<Long> familyIdList) {
        LambdaQueryWrapper<ZfEconomy> lqw = new LambdaQueryWrapper<>();
        lqw.orderByDesc(ZfEconomy::getCreateTime);
@@ -70,8 +78,15 @@
        lqw.like(StringUtils.isNotEmpty(zfEconomy.getUsePeople()),ZfEconomy::getUsePeople,zfEconomy.getUsePeople());
        lqw.like(StringUtils.isNotEmpty(zfEconomy.getBalance()),ZfEconomy::getBalance,zfEconomy.getBalance());
        lqw.like(StringUtils.isNotEmpty(zfEconomy.getRemark()),ZfEconomy::getRemark,zfEconomy.getRemark());
        lqw.like(StringUtils.isNotEmpty(zfEconomy.getCompanion()),ZfEconomy::getCompanion,zfEconomy.getCompanion());
//        if (zfEconomy.getYear() != 0) {
//            System.out.println("pppppppppppppppppppppppppppppppppppppppppppppppppppp"+zfEconomy.getYear());
//            lqw.apply("YEAR(happen_time) = {0}", zfEconomy.getYear());
//        }
        lqw.eq(zfEconomy.getHappenTime() != null, ZfEconomy::getHappenTime, zfEconomy.getHappenTime());
        lqw.between(zfEconomy.getHappenStartTime() != null && zfEconomy.getHappenEndTime() != null, ZfEconomy::getHappenTime, zfEconomy.getHappenStartTime(), zfEconomy.getHappenEndTime());
        System.out.println("查询条件: " + lqw.getCustomSqlSegment());
        return lqw;
    }
@@ -87,6 +102,11 @@
        lqw.eq(zfEconomy.getFamilyId()!=null,ZfEconomy::getFamilyId,zfEconomy.getFamilyId());
        lqw.eq(zfEconomy.getHappenTime() != null, ZfEconomy::getHappenTime, zfEconomy.getHappenTime());
        return lqw;
    }
    @Override
    public List<ZfEconomy> change(){
        ZfEconomy zfEconomy = new ZfEconomy();
       return list(buildCondition(zfEconomy,null));
    }
//    private LambdaQueryWrapper<ZfEconomy> buildCondition(ZfEconomy zfEconomy, String familyIds, String secondFamilyAuthority) {
@@ -223,16 +243,33 @@
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
        //查看父母的数据:
        Long fatherFaId = 0L;
        if(myself.getFatherId()!=null)
            fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId();
        Long motherFaId = 0L;
        if(myself.getMomId()!=null)
            motherFaId = zInfoUserService.getInfoById(myself.getMomId()).getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(ECONOMY_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
        //加上自己家庭的id
        idList.add(familyId);
        //加上父母家族id
        idList.add(fatherFaId);
        idList.add(motherFaId);
        List<Long> fms = zInfoUserService.findByUaidToFaid(myself.getUaid()).stream().map(ZInfoUser::getFamilyId).collect(Collectors.toList());
        if(!fms.isEmpty())
        {
            idList.addAll(fms);
        }
        LambdaQueryWrapper<ZfEconomy> lambdaQueryWrapper = buildCondition(zfEconomy, idList);
        List<ZfEconomy> beanRecords = list(lambdaQueryWrapper);
        log.info("从数据库中查到的为:{}", beanRecords);
        return markOwnData(familyId, beanRecords);
        return markOwnData(familyId,fatherFaId, motherFaId, beanRecords);
    }
    @Override
@@ -287,11 +324,29 @@
            return AjaxResult.success("您没加入到对应的家庭,请联系管理员");
        }
        Long familyId = myself.getFamilyId();
        //查看父母的数据:
        Long fatherFaId = 0L;
        if(myself.getFatherId()!=null)
            fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId();
        Long motherFaId = 0L;
        if(myself.getMomId()!=null)
            motherFaId = zInfoUserService.getInfoById(myself.getMomId()).getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
        List<Long> idList = authority.stream().filter(auth -> auth.getAuthority().toString().equals(ECONOMY_LIST)).map(ZAuthority::getFid).collect(Collectors.toList());
        //加上自己家庭的id
        idList.add(familyId);
        //加上父母家族id
        idList.add(fatherFaId);
        idList.add(motherFaId);
        List<Long> fms = zInfoUserService.findByUaidToFaid(myself.getUaid()).stream().map(ZInfoUser::getFamilyId).collect(Collectors.toList());
        if(!fms.isEmpty())
        {
            idList.addAll(fms);
        }
//        String familyIds = listFamilyIds();
//        String secondFamilyAuthority = listSecondFamilyIds();
        LambdaQueryWrapper<ZfEconomy> lqw = buildCondition(zfEconomy, idList);
@@ -302,16 +357,16 @@
        List<ZfEconomy> beanRecords = pageResult.getRecords();//得到查询出来的数据
        List<ZfEconomy> dtoResult = markOwnData(familyId, beanRecords);
        List<ZfEconomy> dtoResult = markOwnData(familyId, fatherFaId, motherFaId,beanRecords);
        HashMap<String, Object> data = MapUtils.getResult(pageResult, dtoResult);
        return AjaxResult.success(data);
    }
    public List<ZfEconomy> markOwnData(Long familyId,List<ZfEconomy> beanRecords){
    public List<ZfEconomy> markOwnData(Long familyId,Long fatherFamilyId, Long motherFamilyId,List<ZfEconomy> beanRecords){
        return beanRecords.stream().peek(
                bean -> {
                    if (bean.getFamilyId() == familyId) {
                    if (Objects.equals(bean.getFamilyId(), familyId) ||(fatherFamilyId!=0L && fatherFamilyId.equals(familyId))||(motherFamilyId!=0L && motherFamilyId.equals(familyId))) {
                        bean.setOwnData(1);
                    } else {
                        bean.setOwnData(0);
@@ -379,6 +434,9 @@
    @Override
    public AjaxResult addData(ZfEconomy zfEconomy) {
        //清除redis中zfEconomy的缓存
        clearAllCache();
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
@@ -433,6 +491,9 @@
    @Override
    public AjaxResult updateData(ZfEconomy zfEconomy) {
        //清除redis中zfEconomy的缓存
        clearAllCache();
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
@@ -522,7 +583,9 @@
            }
        }
        List<ZfEconomy> zfEconomys = listByIds(Arrays.asList(ids));
        if (! (zfEconomyDownlService.deleteData(ids) && zfEconomyShaService.deleteByContentId(ids)  ) ){
            return AjaxResult.error();
        }
        if (zfEconomyService.removeByIds(Arrays.asList(ids))) {
            //删除es中的数据
@@ -552,4 +615,24 @@
    }
    @Override
    public String getModuleCode() {
        return "2045";
    }
    @Override
    @Cacheable(value = "economy_search", key = "T(String).format('2045_%s_%s_%s',#companion != null ? #companion : 'null',#happenStartTime != null ? #happenStartTime.getTime() : 0,#happenEndTime != null ? #happenEndTime.getTime() : 0)")
    public List<?> search(String companion, Date happenStartTime,Date happenEndTime) {
        ZfEconomy zfEconomy = new ZfEconomy();
        zfEconomy.setCompanion(companion);
        zfEconomy.setHappenStartTime(happenStartTime);
        zfEconomy.setHappenEndTime(happenEndTime);
        System.out.println("ssssss"+zfEconomy);
        return selectByCondition(zfEconomy);
    }
    @CacheEvict(value = "economy_search", allEntries = true)
    public void clearAllCache() {
        System.out.println("清除所有经济搜索缓存");
    }
}