zqy
2 天以前 5418ea7855d16dcc0169d5ed554f7a23c4b55532
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) {
@@ -230,7 +250,7 @@
            fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId();
        Long motherFaId = 0L;
        if(myself.getMomId()!=null)
            motherFaId = zInfoUserService.getInfoBysysId(myself.getMomId()).getFamilyId();
            motherFaId = zInfoUserService.getInfoById(myself.getMomId()).getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
@@ -241,7 +261,11 @@
        //加上父母家族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);
@@ -307,7 +331,7 @@
            fatherFaId = zInfoUserService.getInfoById(myself.getFatherId()).getFamilyId();
        Long motherFaId = 0L;
        if(myself.getMomId()!=null)
            motherFaId = zInfoUserService.getInfoBysysId(myself.getMomId()).getFamilyId();
            motherFaId = zInfoUserService.getInfoById(myself.getMomId()).getFamilyId();
        //也要查别人授权的
        List<ZAuthority> authority = zAuthorityService.getAuthority();
@@ -318,7 +342,11 @@
        //加上父母家族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);
@@ -338,7 +366,7 @@
    public List<ZfEconomy> markOwnData(Long familyId,Long fatherFamilyId, Long motherFamilyId,List<ZfEconomy> beanRecords){
        return beanRecords.stream().peek(
                bean -> {
                    if (bean.getFamilyId() == familyId||(fatherFamilyId!=0L && fatherFamilyId==familyId)||(motherFamilyId!=0L && motherFamilyId==familyId)) {
                    if (Objects.equals(bean.getFamilyId(), familyId) ||(fatherFamilyId!=0L && fatherFamilyId.equals(familyId))||(motherFamilyId!=0L && motherFamilyId.equals(familyId))) {
                        bean.setOwnData(1);
                    } else {
                        bean.setOwnData(0);
@@ -406,6 +434,9 @@
    @Override
    public AjaxResult addData(ZfEconomy zfEconomy) {
        //清除redis中zfEconomy的缓存
        clearAllCache();
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
@@ -460,6 +491,9 @@
    @Override
    public AjaxResult updateData(ZfEconomy zfEconomy) {
        //清除redis中zfEconomy的缓存
        clearAllCache();
        ZInfoUser myself = zInfoUserService.getMyself();
        Long familyId = myself.getFamilyId();
@@ -549,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中的数据
@@ -579,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("清除所有经济搜索缓存");
    }
}