/* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.house.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.logging.log4j.util.Strings; import org.springblade.common.utils.SpringUtils; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.modules.house.dto.UserHouseLabelDTO; import org.springblade.modules.house.entity.UserHouseLabelEntity; import org.springblade.modules.house.excel.UserHouseLabelExcel; import org.springblade.modules.house.mapper.UserHouseLabelMapper; import org.springblade.modules.house.service.IUserHouseLabelService; import org.springblade.modules.house.vo.HouseholdLabelVO; import org.springblade.modules.house.vo.UserHouseLabelVO; import org.springblade.modules.label.entity.LabelEntity; import org.springblade.modules.label.service.ILabelService; import org.springblade.modules.label.service.impl.LabelServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; /** * 住户-标签 服务实现类 * * @author BladeX * @since 2023-10-28 */ @Service public class UserHouseLabelServiceImpl extends ServiceImpl implements IUserHouseLabelService { @Autowired private ILabelService labelService; @Override public IPage selectHouseholdLabelPage(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.selectHouseLabelPage(page, householdLabel)); } /** * 住户-标签 自定义新增或修改 * * @param householdLabel * @return */ @Override public boolean saveOrUpdateHouseholdLabel(UserHouseLabelEntity householdLabel) { // 查询标签名称 if (!Strings.isBlank(householdLabel.getLabelName())) { LabelEntity labelEntity = labelService.getById(householdLabel.getLabelId()); householdLabel.setLabelName(labelEntity.getLabelName()); } // 判断同一个住户同一个标签是否已存在,已存在则更新,不存在则新增 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("household_id", householdLabel.getHouseholdId()) .eq("label_id", householdLabel.getLabelId()); UserHouseLabelEntity one = getOne(queryWrapper); if (null != one) { householdLabel.setId(one.getId()); // 更新 return updateById(householdLabel); } // 插入 return saveOrUpdate(householdLabel); } @Override public List selectUserLabelList(UserHouseLabelDTO userHouseLabelDTO) { List userLabelList = baseMapper.getUserLabelList(userHouseLabelDTO); return userLabelList; } @Override public void importUserHouseLabel(List data, Boolean isCovered) { data.forEach(houseHoldExcel -> { UserHouseLabelEntity userHouseLabelEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, UserHouseLabelEntity.class)); this.save(userHouseLabelEntity); }); } @Override public IPage statisticalLabels(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.statisticalLabels(page, householdLabel)); } @Override public IPage orgStatisticalLabels(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.orgStatisticalLabels(page, householdLabel)); } @Override public IPage unitedFrontStatisticalLabels(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.unitedFrontStatisticalLabels(page, householdLabel)); } @Override public IPage followStatisticalLabels(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.followStatisticalLabels(page, householdLabel)); } @Override public IPage getCommunityStatisticalLabels(IPage page, HouseholdLabelVO householdLabel) { return page.setRecords(baseMapper.getCommunityStatisticalLabels(page, householdLabel)); } /** * 房屋-标签 房屋自定义新增或修改 * * @param userHouseLabelEntity * @return */ @Override public boolean saveOrUpdateHouseLabel(UserHouseLabelEntity userHouseLabelEntity) { // 查询标签名称 LabelEntity labelEntity = labelService.getById(userHouseLabelEntity.getLabelId()); if (labelEntity != null) { userHouseLabelEntity.setLabelName(labelEntity.getLabelName()); } // 先删除之前的房屋绑定的标签 QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("house_code", userHouseLabelEntity.getHouseCode()) .eq("lable_type", 2); // 删除 remove(queryWrapper); // 插入 return save(userHouseLabelEntity); } /** * 查询对应的label集合信息 * @param labelName * @return */ @Override public List getLabelList(String labelName) { return baseMapper.getLabelList(labelName); } @Override public List getUserHouseLabelList(UserHouseLabelVO userHouseLabelVO) { return baseMapper.getUserHouseLabelList(userHouseLabelVO); } }