|
|
@@ -5,14 +5,14 @@ import com.iformall.common.ErrorCode; |
|
|
import com.iformall.common.Result; |
|
|
import com.iformall.common.Result; |
|
|
import com.iformall.common.ResultData; |
|
|
import com.iformall.common.ResultData; |
|
|
import com.iformall.controller.base.BaseController; |
|
|
import com.iformall.controller.base.BaseController; |
|
|
import com.iformall.domain.po.KwBox; |
|
|
|
|
|
import com.iformall.domain.po.KwMeter; |
|
|
|
|
|
import com.iformall.domain.po.KwMeterData; |
|
|
|
|
|
|
|
|
import com.iformall.domain.po.*; |
|
|
import com.iformall.enums.EnumBoxStatus; |
|
|
import com.iformall.enums.EnumBoxStatus; |
|
|
|
|
|
import com.iformall.enums.EnumMerchantMeterStatus; |
|
|
import com.iformall.enums.EnumMeterBindStatus; |
|
|
import com.iformall.enums.EnumMeterBindStatus; |
|
|
import com.iformall.enums.EnumMeterStatus; |
|
|
import com.iformall.enums.EnumMeterStatus; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.exception.MallinkException; |
|
|
import com.iformall.service.ExcelService; |
|
|
import com.iformall.service.ExcelService; |
|
|
|
|
|
import com.iformall.service.WxMerchantService; |
|
|
import com.iformall.service.kw.KwBoxService; |
|
|
import com.iformall.service.kw.KwBoxService; |
|
|
import com.iformall.service.kw.KwMerchantMeterService; |
|
|
import com.iformall.service.kw.KwMerchantMeterService; |
|
|
import com.iformall.service.kw.KwMeterDataService; |
|
|
import com.iformall.service.kw.KwMeterDataService; |
|
|
@@ -21,6 +21,12 @@ import io.swagger.annotations.Api; |
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@@ -31,6 +37,7 @@ import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
@RestController |
|
|
@RestController |
|
|
@RequestMapping("kwMeter") |
|
|
@RequestMapping("kwMeter") |
|
|
@@ -47,9 +54,15 @@ public class KwMeterController extends BaseController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private KwMerchantMeterService kwMerchantMeterService; |
|
|
private KwMerchantMeterService kwMerchantMeterService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private KwBoxService kwBoxService; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private ExcelService excelService; |
|
|
private ExcelService excelService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private WxMerchantService wxMerchantService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("设备列表") |
|
|
@ApiOperation("设备列表") |
|
|
@GetMapping("list") |
|
|
@GetMapping("list") |
|
|
@@ -132,10 +145,97 @@ public class KwMeterController extends BaseController { |
|
|
return new ResultData(kwMeter); |
|
|
return new ResultData(kwMeter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private KwBox addOrBind(KwBox kwBox) { |
|
|
|
|
|
|
|
|
|
|
|
KwBox record = new KwBox(); |
|
|
|
|
|
record.setImei(kwBox.getImei()); |
|
|
|
|
|
record.setStatus(EnumBoxStatus.VALID.getCode()); |
|
|
|
|
|
List<KwBox> list = kwBoxService.findList(record); |
|
|
|
|
|
if (list.size() > 0) return list.get(0); |
|
|
|
|
|
kwBox.setTenantId(getTenantId()); |
|
|
|
|
|
kwBox.setStatus(EnumBoxStatus.VALID.getCode()); |
|
|
|
|
|
kwBoxService.saveOrUpdate(kwBox); |
|
|
|
|
|
return kwBox; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addOrBind(KwMerchantMeter kwMerchantMeter) { |
|
|
|
|
|
|
|
|
|
|
|
if (kwMerchantMeter == null)return; |
|
|
|
|
|
if (kwMerchantMeter.getMerchantId() == null)return; |
|
|
|
|
|
if (kwMerchantMeter.getMeterId() == null)return; |
|
|
|
|
|
|
|
|
|
|
|
KwMerchantMeter record = new KwMerchantMeter(); |
|
|
|
|
|
record.setMeterId(kwMerchantMeter.getMeterId()); |
|
|
|
|
|
record.setStatus(EnumMerchantMeterStatus.VALID.getCode()); |
|
|
|
|
|
if (kwMerchantMeterService.selectCount(record) > 0) return; |
|
|
|
|
|
|
|
|
|
|
|
kwMerchantMeter.setStatus(EnumMerchantMeterStatus.VALID.getCode()); |
|
|
|
|
|
kwMerchantMeterService.saveOrUpdate(kwMerchantMeter); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ApiOperation("导入设备") |
|
|
@ApiOperation("导入设备") |
|
|
@PostMapping(value = "import", consumes = "multipart/*") |
|
|
@PostMapping(value = "import", consumes = "multipart/*") |
|
|
@SystemControllerLog(description = "电表管理-导入数据") |
|
|
@SystemControllerLog(description = "电表管理-导入数据") |
|
|
public Result importData(@RequestParam("file") MultipartFile mFile) { |
|
|
public Result importData(@RequestParam("file") MultipartFile mFile) { |
|
|
|
|
|
if (mFile == null) { |
|
|
|
|
|
return new ResultData(ErrorCode.EXCEL_IMPORT_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(mFile.getInputStream())); |
|
|
|
|
|
HSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
|
|
for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { |
|
|
|
|
|
HSSFRow row = sheet.getRow(i); |
|
|
|
|
|
KwMeter kwMeter = new KwMeter(); |
|
|
|
|
|
Cell c = row.getCell(0,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) { |
|
|
|
|
|
kwMeter.setAddress(c.getStringCellValue()); |
|
|
|
|
|
} else { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
c = row.getCell(1,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) {kwMeter.setPlace(c.getStringCellValue());} |
|
|
|
|
|
c = row.getCell(2,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) {kwMeter.setBrand(c.getStringCellValue());} |
|
|
|
|
|
c = row.getCell(3,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) {kwMeter.setModel(c.getStringCellValue());} |
|
|
|
|
|
c = row.getCell(4,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) {kwMeter.setProtocol(Integer.parseInt(c.getStringCellValue()));} |
|
|
|
|
|
else kwMeter.setProtocol(0); |
|
|
|
|
|
c = row.getCell(5,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) {kwMeter.setBandrate(Integer.parseInt(c.getStringCellValue()));} |
|
|
|
|
|
else kwMeter.setBandrate(1200); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c = row.getCell(6,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) { |
|
|
|
|
|
String imei = c.getStringCellValue(); |
|
|
|
|
|
KwBox kwBox = new KwBox(); |
|
|
|
|
|
kwBox.setImei(imei); |
|
|
|
|
|
kwBox = addOrBind(kwBox); |
|
|
|
|
|
kwMeter.setBindStatus(EnumMeterBindStatus.BIND.getCode()); |
|
|
|
|
|
kwMeter.setBoxId(kwBox.getId()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
add(kwMeter); |
|
|
|
|
|
|
|
|
|
|
|
c = row.getCell(7,Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); |
|
|
|
|
|
if (c != null) { |
|
|
|
|
|
String merchantName = c.getStringCellValue(); |
|
|
|
|
|
Optional<WxMerchant> wxMerchant = wxMerchantService.findByName(merchantName); |
|
|
|
|
|
if (wxMerchant.isPresent()) { |
|
|
|
|
|
KwMerchantMeter kwMerchantMeter = new KwMerchantMeter(); |
|
|
|
|
|
kwMerchantMeter.setMerchantId(wxMerchant.get().getId()); |
|
|
|
|
|
kwMerchantMeter.setMeterId(kwMeter.getId()); |
|
|
|
|
|
addOrBind(kwMerchantMeter); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}catch(Exception e) { |
|
|
|
|
|
return new ResultData(ErrorCode.EXCEL_IMPORT_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return new ResultData(); |
|
|
return new ResultData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|