|
|
@ -29,8 +29,9 @@ import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.IdentityNoUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.StreamUtils; |
|
|
|
import com.elink.esua.epdc.config.QrCodeProperties; |
|
|
|
import com.elink.esua.epdc.dto.CompleteDeptDTO; |
|
|
|
import com.elink.esua.epdc.dto.UploadToOssDTO; |
|
|
|
import com.elink.esua.epdc.dto.epidemic.DictOptionDTO; |
|
|
|
import com.elink.esua.epdc.dto.house.result.EpdcPopulationErrorResultDTO; |
|
|
|
import com.elink.esua.epdc.dto.personroom.EpidemicBuildingUnitDTO; |
|
|
@ -41,12 +42,14 @@ import com.elink.esua.epdc.vaccine.epidemic.entity.EpidemicUserErrorEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.epidemic.entity.EpidemicUserInfoEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.epidemic.service.EpidemicUserErrorService; |
|
|
|
import com.elink.esua.epdc.vaccine.epidemic.service.EpidemicUserInfoService; |
|
|
|
import com.elink.esua.epdc.vaccine.epidemic.utils.HouseQRcodeUtils; |
|
|
|
import com.elink.esua.epdc.vaccine.epidemic.utils.StreamUtils; |
|
|
|
import com.elink.esua.epdc.vaccine.feign.VimAdminFeignClient; |
|
|
|
import com.elink.esua.epdc.vaccine.feign.VimOssFeignClient; |
|
|
|
import com.elink.esua.epdc.vaccine.house.excel.BaseResidentInformationUpdateExcel; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.dao.EpidemicBuildingUnitDao; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.dao.EpidemicUnitOwnerDao; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.entity.EpidemicBuildingUnitEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.entity.EpidemicPlotBuildingEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.entity.EpidemicUnitOwnerEntity; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.redis.EpidemicBuildingUnitRedis; |
|
|
|
import com.elink.esua.epdc.vaccine.personroom.service.EpidemicBuildingUnitService; |
|
|
@ -59,9 +62,15 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.*; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.zip.ZipEntry; |
|
|
|
import java.util.zip.ZipOutputStream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 楼栋,房屋信息 |
|
|
@ -94,6 +103,15 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui |
|
|
|
@Autowired |
|
|
|
private EpidemicUnitOwnerDao epidemicUnitOwnerDao; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private VimOssFeignClient ossFeignClient; |
|
|
|
//
|
|
|
|
// @Autowired
|
|
|
|
// private HouseQRcodeUtils houseQRcodeUtils;
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
private QrCodeProperties qrCodeProperties; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<EpidemicBuildingUnitDTO> page(Map<String, Object> params) { |
|
|
|
IPage<EpidemicBuildingUnitDTO> page = getPage(params); |
|
|
@ -317,6 +335,88 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result createBatchHouseCodeAndUrl() { |
|
|
|
epidemicPlotBuildingService.updateMaCode(); |
|
|
|
this.updateMaCode(); |
|
|
|
List<EpidemicBuildingUnitDTO> list = baseDao.listUnitHasNotUrl(); |
|
|
|
if (!list.isEmpty()) { |
|
|
|
list.forEach(item -> { |
|
|
|
String url = ""; |
|
|
|
try { |
|
|
|
url = createHouseQrcodeUrl(item); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RenException("房屋码上传失败"); |
|
|
|
} |
|
|
|
item.setMaUrl(url); |
|
|
|
}); |
|
|
|
List<EpidemicBuildingUnitEntity> updateList = ConvertUtils.sourceToTarget(list, EpidemicBuildingUnitEntity.class); |
|
|
|
updateBatchById(updateList); |
|
|
|
} |
|
|
|
return new Result().ok("批量生成成功"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void downloadZip(HttpServletResponse response) throws Exception { |
|
|
|
//response
|
|
|
|
response.reset(); |
|
|
|
//文件的名称
|
|
|
|
String downloadFilename = "二维码压缩包.zip"; |
|
|
|
//转换中文否则可能会产生乱码
|
|
|
|
downloadFilename = URLEncoder.encode(downloadFilename, "UTF-8"); |
|
|
|
// 指明response的返回对象是文件流
|
|
|
|
response.setContentType("application/octet-stream; charset=UTF-8"); |
|
|
|
//设置下载格式和名称
|
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + downloadFilename); |
|
|
|
ZipOutputStream zip = new ZipOutputStream(response.getOutputStream()); |
|
|
|
|
|
|
|
List<EpidemicBuildingUnitDTO> houseList = baseDao.listUnitHasUrl(); |
|
|
|
|
|
|
|
for (EpidemicBuildingUnitDTO house : houseList) { |
|
|
|
|
|
|
|
BufferedImage image = HouseQRcodeUtils.drawHouseQRImage(house.getBuildingName() + house.getUnit() + house.getRoomNo(), |
|
|
|
qrCodeProperties.getPre() + house.getRoomCode()); |
|
|
|
|
|
|
|
try { |
|
|
|
byte[] buf = new byte[8192]; |
|
|
|
int len; |
|
|
|
//添加到zip
|
|
|
|
zip.putNextEntry(new ZipEntry(getFileName(house))); |
|
|
|
InputStream inputStream = bufferedImageToInputStream(image); |
|
|
|
//输出压缩包
|
|
|
|
while ((len = inputStream.read(buf)) > 0) { |
|
|
|
zip.write(buf, 0, len); |
|
|
|
} |
|
|
|
inputStream.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RenException("组装zip失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
zip.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 将BufferedImage转换为InputStream |
|
|
|
* |
|
|
|
* @param image: 图片流 |
|
|
|
* @date 2022/4/8 15:29 |
|
|
|
* @author YD |
|
|
|
*/ |
|
|
|
public static InputStream bufferedImageToInputStream(BufferedImage image) throws IOException { |
|
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(image, "png", os); |
|
|
|
try (InputStream input = new ByteArrayInputStream(os.toByteArray())) { |
|
|
|
return input; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取文件名 |
|
|
|
*/ |
|
|
|
public static String getFileName(EpidemicBuildingUnitDTO house) { |
|
|
|
return house.getPlotName() + File.separator + house.getBuildingName() + File.separator + house.getUnit() + File.separator + house.getRoomNo() + ".png"; |
|
|
|
} |
|
|
|
|
|
|
|
private void saveOrUpdateOwners(List<EpidemicUnitOwnerDTO> owners, Long unitId) { |
|
|
|
List<EpidemicUnitOwnerDTO> dtoList = owners.stream().filter(item -> StringUtils.isNotBlank(item.getIdCard())).collect(Collectors.toList()); |
|
|
|
List<EpidemicUnitOwnerEntity> list = ConvertUtils.sourceToTarget(dtoList, EpidemicUnitOwnerEntity.class); |
|
|
@ -435,19 +535,14 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui |
|
|
|
if (!updateList.isEmpty()) { |
|
|
|
epidemicUserInfoService.updateBatchById(updateList); |
|
|
|
} |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>A"); |
|
|
|
// 补充人房关系
|
|
|
|
int roomCode = getMaxCode(); |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>B" + roomCode); |
|
|
|
List<EpidemicUnitInfoResultDTO> unitList = listAllUnitInfo(parentAndAllDeptDTO.getGrid()); |
|
|
|
List<EpidemicUnitOwnerEntity> addOwner = new ArrayList<>(); |
|
|
|
for (EpidemicUserInfoEntity item : addList) { |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>C"); |
|
|
|
// 只有信息完整的才进行匹配
|
|
|
|
|
|
|
|
Optional<EpidemicUnitInfoResultDTO> unitOptional = unitList.stream().filter(unit -> unit.getPlotName().equals(item.getPlot()) && unit.getBuildingName().equals(item.getBuildingNo()) && unit.getUnit().equals(item.getUnit()) && unit.getRoomNo().equals(item.getRoomNo())).findFirst(); |
|
|
|
if (unitOptional.isPresent()) { |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>D"); |
|
|
|
EpidemicUnitOwnerEntity entity = new EpidemicUnitOwnerEntity(); |
|
|
|
entity.setIdCard(item.getIdCard()); |
|
|
|
entity.setUnitId(unitOptional.get().getUnitId()); |
|
|
@ -455,10 +550,8 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui |
|
|
|
entity.setMobile(item.getMobile()); |
|
|
|
addOwner.add(entity); |
|
|
|
} else { |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>E" + buildingList.toString()); |
|
|
|
Optional<EpidemicPlotBuildingResultDTO> buildingOptional = buildingList.stream().filter(build -> build.getPlotName().equals(item.getPlot()) && build.getBuildingName().equals(item.getBuildingNo())).findFirst(); |
|
|
|
if (buildingOptional.isPresent()) { |
|
|
|
log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>F" + buildingOptional.get()); |
|
|
|
EpidemicBuildingUnitEntity unitEntity = new EpidemicBuildingUnitEntity(); |
|
|
|
unitEntity.setBuildingId(buildingOptional.get().getId()); |
|
|
|
unitEntity.setUnit(item.getUnit().trim().toUpperCase()); |
|
|
@ -560,4 +653,26 @@ public class EpidemicBuildingUnitServiceImpl extends CrudServiceImpl<EpidemicBui |
|
|
|
return new Result<HouseInfoResultDTO>().ok(houseInfoResultDTO); |
|
|
|
} |
|
|
|
|
|
|
|
public String createHouseQrcodeUrl(EpidemicBuildingUnitDTO house) throws Exception { |
|
|
|
//url组成:小程序地址?房屋编码
|
|
|
|
String url = qrCodeProperties.getPre() + house.getRoomCode(); |
|
|
|
String fileName = house.getBuildingName() + house.getUnit() + house.getRoomNo() + ".png"; |
|
|
|
BufferedImage image = HouseQRcodeUtils.drawHouseQRImage(house.getBuildingName() + house.getUnit() + house.getRoomNo(), url); |
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
try { |
|
|
|
ImageIO.write(image, "png", out); |
|
|
|
UploadToOssDTO dto = new UploadToOssDTO(); |
|
|
|
dto.setFileName(fileName); |
|
|
|
dto.setFileByte(out.toByteArray()); |
|
|
|
Result<String> ossResult = ossFeignClient.uploadFile(dto); |
|
|
|
if (null == ossResult || !ossResult.success() || null == ossResult.getData()) { |
|
|
|
throw new RenException("房屋码上传失败"); |
|
|
|
} else { |
|
|
|
return ossResult.getData(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
throw new RenException("上传一户一档二维码失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|