| | |
| | | */ |
| | | package org.springblade.modules.house.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import cn.hutool.core.util.IdcardUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import org.springblade.common.param.CommonParamSet; |
| | | import org.springblade.common.utils.NodeTreeUtil; |
| | | import org.springblade.common.utils.SpringUtils; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.modules.house.entity.HouseholdEntity; |
| | | import org.springblade.modules.house.entity.UserHouseLabelEntity; |
| | | import org.springblade.modules.house.excel.HouseHoldExcel; |
| | | import org.springblade.modules.house.excel.ImportHouseholdExcel; |
| | | import org.springblade.modules.house.mapper.HouseholdMapper; |
| | | import org.springblade.modules.house.service.IHouseService; |
| | | import org.springblade.modules.house.service.IHouseholdService; |
| | | import org.springblade.modules.house.service.IUserHouseLabelService; |
| | | import org.springblade.modules.house.vo.HouseholdLabelVO; |
| | |
| | | import org.springblade.modules.house.vo.HouseholdVO; |
| | | import org.springblade.modules.label.entity.LabelEntity; |
| | | import org.springblade.modules.label.service.ILabelService; |
| | | import org.springblade.modules.label.vo.LabelVO; |
| | | import org.springblade.modules.place.entity.PlaceEntity; |
| | | import org.springblade.modules.place.service.IPlaceService; |
| | | import org.springblade.modules.system.entity.DictBiz; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StopWatch; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<HouseHoldExcel> export(HouseholdVO household) { |
| | | List<HouseHoldExcel> userHouseHoldExcels = baseMapper.export(household); |
| | | public List<ImportHouseholdExcel> export(HouseholdVO household) { |
| | | List<ImportHouseholdExcel> userHouseHoldExcels = baseMapper.export(household); |
| | | return userHouseHoldExcels; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 导入住户数据 |
| | | * @param data |
| | | * @param isCovered |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importUserHouseHold(List<HouseHoldExcel> data, Boolean isCovered) { |
| | | data.forEach(houseHoldExcel -> { |
| | | HouseholdEntity houseHoldEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class)); |
| | | this.save(houseHoldEntity); |
| | | }); |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public void importUserHouseHold(List<ImportHouseholdExcel> data, Boolean isCovered) { |
| | | IHouseService houseService = SpringUtils.getBean(IHouseService.class); |
| | | int errorNum = 0; |
| | | for (ImportHouseholdExcel houseHoldExcel : data) { |
| | | HouseholdEntity householdEntity = Objects.requireNonNull(BeanUtil.copy(houseHoldExcel, HouseholdEntity.class)); |
| | | // 判断姓名,手机号 |
| | | if (Strings.isBlank(householdEntity.getName()) || Strings.isBlank(householdEntity.getPhoneNumber())){ |
| | | errorNum ++; |
| | | continue; |
| | | } |
| | | // 查询库中是否已存在 |
| | | QueryWrapper<HouseholdEntity> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("house_code", householdEntity.getHouseCode()) |
| | | .eq("is_deleted", 0) |
| | | .eq("phone_number", householdEntity.getPhoneNumber()) |
| | | .eq("name", householdEntity.getName()); |
| | | HouseholdEntity one = this.getOne(wrapper); |
| | | // 与角色关系 |
| | | if (!Strings.isBlank(houseHoldExcel.getRelationship())) { |
| | | householdEntity.setRelationship(Integer.parseInt(houseHoldExcel.getRelationship())); |
| | | // 如果是业主,则需要往用户表插入用户 |
| | | if (householdEntity.getRelationship() == 1) { |
| | | houseService.saveOrUpdateUser(householdEntity); |
| | | } |
| | | } |
| | | /// 是否主要联系人 |
| | | if (!Strings.isBlank(houseHoldExcel.getIsPrimaryContact())) { |
| | | householdEntity.setIsPrimaryContact(Integer.parseInt(houseHoldExcel.getIsPrimaryContact())); |
| | | } |
| | | // 居住状态 |
| | | if (!Strings.isBlank(houseHoldExcel.getResidentialStatus())) { |
| | | householdEntity.setResidentialStatus(Integer.parseInt(houseHoldExcel.getResidentialStatus())); |
| | | } |
| | | // 性别 |
| | | if (!Strings.isBlank(houseHoldExcel.getGender())) { |
| | | householdEntity.setGender(Short.parseShort(houseHoldExcel.getGender())); |
| | | } |
| | | // 居民身份证 |
| | | if (!Strings.isBlank(houseHoldExcel.getIdCard())) { |
| | | if (IdcardUtil.isValidCard(houseHoldExcel.getIdCard())) { |
| | | // 身份证类型为居民身份证 |
| | | householdEntity.setCardType(111); |
| | | } |
| | | } |
| | | // 党员 |
| | | if (!Strings.isBlank(houseHoldExcel.getPartyEmber())) { |
| | | householdEntity.setPartyEmber(Integer.parseInt(houseHoldExcel.getPartyEmber())); |
| | | } |
| | | // 民族 |
| | | if (!Strings.isBlank(houseHoldExcel.getEthnicity())) { |
| | | householdEntity.setEthnicity(Integer.parseInt(houseHoldExcel.getEthnicity())); |
| | | } |
| | | // 学历 |
| | | if (!Strings.isBlank(houseHoldExcel.getEducation())) { |
| | | householdEntity.setEducation(Integer.parseInt(houseHoldExcel.getEducation())); |
| | | } |
| | | // 健康状况 |
| | | if (!Strings.isBlank(houseHoldExcel.getHealthStatus())) { |
| | | householdEntity.setHealthStatus(Integer.parseInt(houseHoldExcel.getHealthStatus())); |
| | | } |
| | | // 工作状态 |
| | | if (!Strings.isBlank(houseHoldExcel.getWorkStatus())) { |
| | | householdEntity.setWorkStatus(Integer.parseInt(houseHoldExcel.getWorkStatus())); |
| | | } |
| | | // 外出时间 |
| | | if (!Strings.isBlank(houseHoldExcel.getGoOutTime())) { |
| | | try { |
| | | Date date = new SimpleDateFormat("yyyy-MM-dd").parse(houseHoldExcel.getGoOutTime()); |
| | | householdEntity.setGoOutTime(date); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | // 婚姻状态 |
| | | if (!Strings.isBlank(houseHoldExcel.getMaritalStatus())) { |
| | | householdEntity.setMaritalStatus(Integer.parseInt(houseHoldExcel.getMaritalStatus())); |
| | | } |
| | | |
| | | if (one==null){ |
| | | // 新增 |
| | | this.save(householdEntity); |
| | | // 处理标签 |
| | | handleLabel(householdEntity,houseHoldExcel); |
| | | }else { |
| | | if (isCovered){ |
| | | // 覆盖更新 |
| | | householdEntity.setId(one.getId()); |
| | | // 更新 |
| | | updateById(householdEntity); |
| | | // 处理标签 |
| | | handleLabel(householdEntity,houseHoldExcel); |
| | | } |
| | | } |
| | | } |
| | | if (errorNum>0){ |
| | | throw new ServiceException("导入完成,其中共有 " + errorNum + " 条数据由于无姓名或手机号信息未导入!"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 标签处理 |
| | | * @param householdEntity |
| | | * @param houseHoldExcel |
| | | */ |
| | | public void handleLabel(HouseholdEntity householdEntity, ImportHouseholdExcel houseHoldExcel) { |
| | | if (!Strings.isBlank(houseHoldExcel.getLabelName())){ |
| | | // 查询对应的label集合信息 |
| | | List<UserHouseLabelEntity> userHouseLabelList = userHouseLabelService.getLabelList(houseHoldExcel.getLabelName()); |
| | | if (userHouseLabelList.size()>0){ |
| | | for (UserHouseLabelEntity userHouseLabelEntity : userHouseLabelList) { |
| | | userHouseLabelEntity.setHouseCode(householdEntity.getHouseCode()); |
| | | userHouseLabelEntity.setHouseholdId(householdEntity.getId()); |
| | | userHouseLabelEntity.setUserId(householdEntity.getAssociatedUserId()); |
| | | userHouseLabelEntity.setLableType(1); |
| | | userHouseLabelEntity.setColor("green"); |
| | | userHouseLabelService.saveOrUpdateHouseholdLabel(userHouseLabelEntity); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |