|
@@ -1,12 +1,19 @@
|
|
|
package cn.fastfun.service.impl;
|
|
|
|
|
|
+import cn.fastfun.controller.dto.DeviceAttrDTO;
|
|
|
import cn.fastfun.service.AppDeviceService;
|
|
|
+import cn.fastfun.service.ProductService;
|
|
|
import cn.fastfun.service.entity.AppDevice;
|
|
|
+import cn.fastfun.service.entity.Product;
|
|
|
+import cn.fastfun.service.entity.SysDict;
|
|
|
+import cn.fastfun.service.repository.AppDeviceRepository;
|
|
|
+import com.bridge.dto.QueryParamExp;
|
|
|
import com.bridge.exception.ApiRuntimeException;
|
|
|
+import com.bridge.service.JpaService;
|
|
|
import com.bridge.service.impl.JpaServiceImp;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -18,16 +25,49 @@ import java.util.Map;
|
|
|
@Service("appDeviceService")
|
|
|
public class AppDeviceServiceImp extends JpaServiceImp<AppDevice, String> implements AppDeviceService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ AppDeviceRepository deviceRepository;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ ProductService productService;
|
|
|
+
|
|
|
@Override
|
|
|
public void importDevice(List<Map<String, Object>> list) {
|
|
|
List<AppDevice> devices = new ArrayList<>();
|
|
|
- String diffBatchNum = "";
|
|
|
+ DeviceAttrDTO diffAttrDTO = null;
|
|
|
for (Map<String, Object> p : list) {
|
|
|
AppDevice device = new AppDevice(p);
|
|
|
- if (StringUtils.isEmpty(diffBatchNum)) diffBatchNum = device.getBatchNum();
|
|
|
- if (!diffBatchNum.equals(device.getBatchNum())) new ApiRuntimeException("存在不同的批次号");
|
|
|
+ // 数据效验
|
|
|
+ if (null == diffAttrDTO) diffAttrDTO = new DeviceAttrDTO(device.getBatchNum(), device.getSn());
|
|
|
+ DeviceAttrDTO temp = new DeviceAttrDTO(device.getBatchNum(), device.getSn());
|
|
|
+ if (!temp.getBatchNum().equals(diffAttrDTO.getBatchNum())) new ApiRuntimeException("存在不同的批次号");
|
|
|
+ if (!temp.getPack().equals(diffAttrDTO.getPack())) new ApiRuntimeException("存在不同的PACK厂");
|
|
|
+ if (!temp.getType().equals(diffAttrDTO.getType())) new ApiRuntimeException("存在不同的电池类型");
|
|
|
devices.add(device);
|
|
|
}
|
|
|
save(devices);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public AppDeviceRepository getRepository() {
|
|
|
+ return deviceRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DeviceAttrDTO sn2Attr(String sn) {
|
|
|
+ DeviceAttrDTO dto = new DeviceAttrDTO(sn);
|
|
|
+
|
|
|
+ dto.setTypeTitle(getProductTitle("产品类型", dto.getType()));
|
|
|
+ dto.setPackTitle(getProductTitle("PACK制造商", dto.getPack()));
|
|
|
+
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getProductTitle(String typeName, String code) {
|
|
|
+ Product product = productService.getOne(
|
|
|
+ QueryParamExp.eq("snType", typeName),
|
|
|
+ QueryParamExp.eq("snTypeCode", code));
|
|
|
+ if (null != product) return product.getSnTypeDesc();
|
|
|
+ return "未知";
|
|
|
+ }
|
|
|
}
|