|
@@ -13,6 +13,7 @@ import com.zcxk.core.oauth2.pojo.LoginUser;
|
|
|
import com.zcxk.core.oauth2.util.UserUtil;
|
|
|
import com.zcxk.core.utils.BigDecimalUtils;
|
|
|
import com.zcxk.core.utils.ZoniotIntegerUtils;
|
|
|
+import com.zcxk.core.utils.export.EasyExcelUtil;
|
|
|
import com.zcxk.rmcp.api.dto.device.DeviceInputDto;
|
|
|
import com.zcxk.rmcp.api.enums.DeviceStatusEnum;
|
|
|
import com.zcxk.rmcp.api.enums.RmcpErrorEnum;
|
|
@@ -20,14 +21,21 @@ import com.zcxk.rmcp.api.enums.ValveStatusEnum;
|
|
|
import com.zcxk.rmcp.api.query.CommonQueryCondition;
|
|
|
import com.zcxk.rmcp.api.vo.*;
|
|
|
import com.zcxk.rmcp.core.dao.DeviceMapper;
|
|
|
+import com.zcxk.rmcp.core.entity.Community;
|
|
|
import com.zcxk.rmcp.core.entity.Device;
|
|
|
+import com.zcxk.rmcp.core.entity.Org;
|
|
|
+import com.zcxk.rmcp.core.entity.Product;
|
|
|
import com.zcxk.rmcp.web.excel.download.WaterDownloadExcelTemplate;
|
|
|
import com.zcxk.rmcp.web.excel.download.service.WaterDownloadExcelService;
|
|
|
import com.zcxk.rmcp.web.excel.model.DeviceImportData;
|
|
|
import com.zcxk.rmcp.web.excel.model.DownloadExcelData;
|
|
|
import com.zcxk.rmcp.web.excel.model.ExcelData;
|
|
|
+import com.zcxk.rmcp.web.service.CommunityService;
|
|
|
import com.zcxk.rmcp.web.service.DeviceService;
|
|
|
+import com.zcxk.rmcp.web.service.OrgService;
|
|
|
+import com.zcxk.rmcp.web.service.ProductService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -56,6 +64,12 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
private SnowflakeIdWorker idWorker;
|
|
|
@Autowired
|
|
|
private WaterDownloadExcelService waterDownloadExcelService;
|
|
|
+ @Autowired
|
|
|
+ private CommunityService communityService;
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+ @Autowired
|
|
|
+ private OrgService orgService;
|
|
|
|
|
|
@Override
|
|
|
public int insertSelective(Device record) {
|
|
@@ -86,6 +100,31 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
return new Pagination<>(list);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getDeviceListExcel(CommonQueryCondition condition, HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ List<DeviceVo> list = deviceMapper.findList(condition,UserUtil.getCurrentUser().getUserCondition());
|
|
|
+
|
|
|
+ EasyExcelUtil.excelWrite(response,DownloadDeviceVo.class,"设备列表",convert(list));
|
|
|
+ }catch (Exception e){
|
|
|
+ throw BusinessException.builder(RmcpErrorEnum.RMCP_DOWNLOAD_ERROR);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<DownloadDeviceVo> convert (List<DeviceVo> list){
|
|
|
+ List<DownloadDeviceVo> results = new ArrayList<>();
|
|
|
+ for (DeviceVo deviceVo : list) {
|
|
|
+ DownloadDeviceVo vo = new DownloadDeviceVo();
|
|
|
+ BeanCopyUtils.copyProperties(deviceVo, vo, DownloadDeviceVo.class);
|
|
|
+ vo.setDeviceTypeName(deviceVo.getManufacturerName()+"/"+deviceVo.getProductName()+"/"+deviceVo.getProductModel());
|
|
|
+ vo.setValveStatusName(ValveStatusEnum.getMessage(deviceVo.getValveStatus()));
|
|
|
+ vo.setDeviceStatusName(DeviceStatusEnum.getMessage(deviceVo.getDeviceStatus().toString()));
|
|
|
+ results.add(vo);
|
|
|
+ }
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void add(DeviceInputDto dto) {
|
|
@@ -99,11 +138,14 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
throw BusinessException.builder(RmcpErrorEnum.RMCP_METER_NO_UNIQUE_ERROR);
|
|
|
}
|
|
|
|
|
|
+ Product product = productService.findById(dto.getProductId());
|
|
|
+
|
|
|
//保存数据
|
|
|
Device device = new Device();
|
|
|
BeanCopyUtils.copyProperties(dto, device, Device.class);
|
|
|
device.setId(idWorker.nextId());
|
|
|
device.setTenantId(user.getTenantId());
|
|
|
+ device.setCategoryId(product.getProductCategoryId());
|
|
|
device.setDeviceStatus(DeviceStatusEnum.UNUSED.getCode());
|
|
|
device.setValveStatus(ValveStatusEnum.ON.getCode());
|
|
|
device.setStatus(StatusEnum.OK.getCode());
|
|
@@ -122,9 +164,12 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
if (deviceMapper.findByMeterNoUnique(dto.getId(), dto.getMeterNo()) > 0) {
|
|
|
throw BusinessException.builder(RmcpErrorEnum.RMCP_METER_NO_UNIQUE_ERROR);
|
|
|
}
|
|
|
+
|
|
|
+ Product product = productService.findById(dto.getProductId());
|
|
|
//更新数据
|
|
|
Device device = new Device();
|
|
|
BeanCopyUtils.copyProperties(dto, device, Device.class);
|
|
|
+ device.setCategoryId(product.getProductCategoryId());
|
|
|
this.updateByPrimaryKeySelective(device);
|
|
|
log.info("end DeviceServiceImpl edit ");
|
|
|
}
|
|
@@ -139,6 +184,8 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
public void batchDel(List<Integer> ids) {
|
|
|
log.info("begin DeviceServiceImpl batchDel ids = {}", JSON.toJSON(ids));
|
|
|
deviceMapper.delByIds(ids);
|
|
|
+ // TODO: 2021/7/26 清除计划清单
|
|
|
+ // TODO: 2021/7/26 删除告警记录
|
|
|
log.info("end DeviceServiceImpl batchDel ");
|
|
|
}
|
|
|
|
|
@@ -197,16 +244,6 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public ResultMessage saveExcelData(DeviceImportData data, ExcelData excelData) {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void getDeviceListExcel(CommonQueryCondition condition, HttpServletResponse httpServletResponse) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* @author Andy
|
|
@@ -246,4 +283,88 @@ public class DeviceServiceImpl implements DeviceService{
|
|
|
WaterDownloadExcelTemplate template = new WaterDownloadExcelTemplate(waterDownloadExcelService);
|
|
|
template.build(downloadExcelData).downloadExcel();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultMessage saveExcelData(DeviceImportData data, ExcelData excelData) {
|
|
|
+ log.info("saveExcelData data = {}",JSON.toJSONString(data));
|
|
|
+ ResultMessage resultMessage = new ResultMessage();
|
|
|
+ resultMessage.setStatus(false);
|
|
|
+ try {
|
|
|
+ // 1、校验检查
|
|
|
+ if (deviceMapper.findByDeviceNoUnique(null, data.getDeviceNo()) > 0) {
|
|
|
+ resultMessage.setMessage(RmcpErrorEnum.RMCP_DEVICE_NO_UNIQUE_ERROR.getMessage());
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+ if (deviceMapper.findByMeterNoUnique(null, data.getMeterNo()) > 0) {
|
|
|
+ resultMessage.setMessage(RmcpErrorEnum.RMCP_METER_NO_UNIQUE_ERROR.getMessage());
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2、小区查询
|
|
|
+ Community community = null;
|
|
|
+ if(StringUtils.isNotEmpty(data.getCommunityName())){
|
|
|
+ community = communityService.findByName(excelData.getImportFile().getTenantId(),data.getCommunityName());
|
|
|
+ if (community == null) {
|
|
|
+ resultMessage.setMessage("小区不存在");
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 3、公司部门查询
|
|
|
+ Org companyOrg = orgService.findByName(excelData.getImportFile().getTenantId(),data.getCompanyOrgName());
|
|
|
+ if (companyOrg == null) {
|
|
|
+ resultMessage.setMessage("公司不存在");
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+ Org deptOrg = null;
|
|
|
+ if(StringUtils.isNotEmpty(data.getDeptOrgName())){
|
|
|
+ deptOrg = orgService.findByParentIdAndName(companyOrg.getId(),data.getDeptOrgName());
|
|
|
+ if (deptOrg == null) {
|
|
|
+ resultMessage.setMessage("部门不存在");
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4、产品(设备类型)查询
|
|
|
+ String[] deviceType = StringUtils.split(data.getDeviceTypeName(),"/");
|
|
|
+ System.out.println(JSON.toJSONString(deviceType));
|
|
|
+ Product product = productService.getByName(deviceType[1],deviceType[2]);
|
|
|
+ if (product == null) {
|
|
|
+ resultMessage.setMessage("设备型号不存在");
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5、保存数据
|
|
|
+ Device device = new Device();
|
|
|
+ device.setId(idWorker.nextId());
|
|
|
+ device.setTenantId(excelData.getImportFile().getTenantId());
|
|
|
+ device.setDeviceNo(data.getDeviceNo());
|
|
|
+ device.setMeterNo(data.getMeterNo());
|
|
|
+ device.setFileNo(data.getFileNo());
|
|
|
+ device.setSealNo(data.getSealNo());
|
|
|
+ device.setProductId(product.getId());
|
|
|
+ device.setCategoryId(product.getProductCategoryId());
|
|
|
+ device.setCompanyOrgId(companyOrg.getId());
|
|
|
+ if (deptOrg != null) device.setDeptOrgId(deptOrg.getId());
|
|
|
+ if (community != null) device.setCommunityId(community.getId());
|
|
|
+ device.setUserName(data.getUsername());
|
|
|
+ device.setUserPhone(data.getPhone());
|
|
|
+ device.setIdCard(data.getIdCard());
|
|
|
+ device.setOldEndDegree(data.getReadData());
|
|
|
+ device.setAddress(data.getAddress());
|
|
|
+ device.setDeviceStatus(DeviceStatusEnum.UNUSED.getCode());
|
|
|
+ device.setValveStatus(ValveStatusEnum.ON.getCode());
|
|
|
+ device.setStatus(StatusEnum.OK.getCode());
|
|
|
+ this.insertSelective(device);
|
|
|
+
|
|
|
+ resultMessage.setStatus(true);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("导入数据异常 e : {} {}",e.getMessage(),e);
|
|
|
+ resultMessage.setMessage("数据异常");
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultMessage;
|
|
|
+ }
|
|
|
}
|