|
|
@ -3,12 +3,17 @@ package com.epmet.service.impl; |
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.enums.NeighborHoodUrlEnum; |
|
|
|
import com.epmet.commons.tools.enums.OrgTypeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.BarcodeUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.NeighborhoodConstant; |
|
|
|
import com.epmet.dao.CustomerGridDao; |
|
|
@ -24,6 +29,7 @@ import com.epmet.dto.form.IcNeighborHoodListFormDTO; |
|
|
|
import com.epmet.dto.form.IcUserBelongToChangedFormDTO; |
|
|
|
import com.epmet.dto.result.IcNeighborHoodResultDTO; |
|
|
|
import com.epmet.dto.result.OrganizationCommunityDTO; |
|
|
|
import com.epmet.dto.result.UploadImgResultDTO; |
|
|
|
import com.epmet.entity.IcHouseEntity; |
|
|
|
import com.epmet.entity.IcNeighborHoodEntity; |
|
|
|
import com.epmet.entity.IcNeighborHoodPropertyEntity; |
|
|
@ -32,6 +38,7 @@ import com.epmet.enums.OrganizationTypeEnums; |
|
|
|
import com.epmet.excel.IcNeighborHoodExcel; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.service.IcNeighborHoodPropertyService; |
|
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
|
import com.epmet.service.NeighborHoodService; |
|
|
@ -39,13 +46,21 @@ import com.epmet.util.ExcelPoiUtils; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.imageio.ImageIO; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -73,6 +88,8 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
|
private IcOrganizationCodeInfoDao icOrganizationCodeInfoDao; |
|
|
|
@Autowired |
|
|
|
private IcOrganizationCodeInfoServiceImpl icOrganizationCodeInfoServiceImpl; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -113,6 +130,63 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
|
icNeighborHoodPropertyDTO.setPropertyId(propertyId); |
|
|
|
icNeighborHoodPropertyService.save(icNeighborHoodPropertyDTO); |
|
|
|
} |
|
|
|
//生成小区码
|
|
|
|
IcNeighborHoodEntity neiEntity = new IcNeighborHoodEntity(); |
|
|
|
neiEntity.setId(entity.getId()); |
|
|
|
try { |
|
|
|
neiEntity.setQrcodeUrl(createNeiQrcodeUrl(entity.getId(),entity.getNeighborHoodName())); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败","二维码生成失败"); |
|
|
|
} |
|
|
|
baseDao.updateById(neiEntity); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @describe: 生成小区二维码地址 |
|
|
|
* @author wangtong |
|
|
|
* @date 2022/8/4 14:28 |
|
|
|
* @params [NeighborHood] |
|
|
|
* @return java.lang.String |
|
|
|
*/ |
|
|
|
private String createNeiQrcodeUrl(String NeighborHood,String neighborHoodName) throws Exception { |
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(NeighborHood)) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "小区id不可为空", "小区id不可为空"); |
|
|
|
} |
|
|
|
//二维码内容地址
|
|
|
|
String url = NeighborHoodUrlEnum.URL_PRE.getCode()+"?neiId="+NeighborHood; |
|
|
|
|
|
|
|
String fileName = neighborHoodName + ".png"; |
|
|
|
BufferedImage image = BarcodeUtils.drawQRImage(neighborHoodName, url); |
|
|
|
|
|
|
|
FileItem fileItem = new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, FileUtils.getAndCreateDirUnderEpmetFilesDir("temp").toFile()) |
|
|
|
.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); |
|
|
|
OutputStream os = fileItem.getOutputStream(); |
|
|
|
Result<UploadImgResultDTO> uploadResult = null; |
|
|
|
try { |
|
|
|
ImageIO.write(image, "png", os); |
|
|
|
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
|
} catch (Exception e) { |
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("上传小区二维码:{}", errormsg); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
os.close(); |
|
|
|
} catch (IOException e) { |
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("上传小区二维码关闭输出流:{}", errormsg); |
|
|
|
} |
|
|
|
try { |
|
|
|
fileItem.delete(); |
|
|
|
} catch (Exception e) { |
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("上传小区二维码删除临时文件:{}", errormsg); |
|
|
|
} |
|
|
|
} |
|
|
|
if (uploadResult == null || !uploadResult.success()) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "上传小区二维码失败", "上传小区二维码失败"); |
|
|
|
} else { |
|
|
|
return uploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -271,6 +345,28 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
|
ExcelPoiUtils.exportExcel(templatePath ,map,"小区信息录入表",response); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result createBatchNeiQrUrl(String customerId) { |
|
|
|
//查询该客户下没有二维码的小区
|
|
|
|
QueryWrapper<IcNeighborHoodEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.lambda().eq(IcNeighborHoodEntity::getCustomerId,customerId) |
|
|
|
.eq(IcNeighborHoodEntity::getDelFlag, NumConstant.ZERO_STR);; |
|
|
|
List<IcNeighborHoodEntity> neiList = baseDao.selectList(queryWrapper); |
|
|
|
//保存二维码地址
|
|
|
|
neiList.forEach(nei->{ |
|
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(nei.getQrcodeUrl())){ |
|
|
|
try { |
|
|
|
nei.setQrcodeUrl(createNeiQrcodeUrl(nei.getId(),nei.getNeighborHoodName())); |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败<neiId>:"+nei.getId(),"二维码生成失败<neiId>:"+nei.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
baseDao.updateById(nei); |
|
|
|
}); |
|
|
|
return new Result().ok("批量生成成功"); |
|
|
|
} |
|
|
|
|
|
|
|
private List<IcNeighborHoodExcel> searchAllNeighborhood(IcHouseListFormDTO formDTO) { |
|
|
|
IcNeighborHoodEntity neighbor = ConvertUtils.sourceToTarget(formDTO, IcNeighborHoodEntity.class); |
|
|
|
neighbor.setDelFlag("0"); |
|
|
|