|
@@ -0,0 +1,93 @@
|
|
|
|
+package com.hb.proj.base.service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.hb.proj.model.DevicePO;
|
|
|
|
+import com.hb.proj.model.DeviceVO;
|
|
|
|
+import com.hb.xframework.dao.core.SpringJdbcDAO;
|
|
|
|
+import com.hb.xframework.dao.util.PageModel;
|
|
|
|
+import com.hb.xframework.dao.util.UUIDHexGenerator;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class DeviceService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SpringJdbcDAO dao;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public PageModel<DeviceVO> query(Map<String,Object> args,int pageNo,int pageSize){
|
|
|
|
+ List<Object> sqlParams=new ArrayList<Object>();
|
|
|
|
+ StringBuilder sql=new StringBuilder(100);
|
|
|
|
+ sql.append("select w.well_name,d.* ");
|
|
|
|
+ sql.append(" from tzl_gather_device d ");
|
|
|
|
+ sql.append(" left join tzl_well w on d.well_id=w.well_id and w.del_if=false");
|
|
|
|
+ sql.append(" where d.del_if=false ");
|
|
|
|
+
|
|
|
|
+ if(args!=null&&StringUtils.isNotBlank((String)args.get("deviceKey"))) {
|
|
|
|
+ sql.append(" and (device_name like ? or device_code like ?)");
|
|
|
|
+ sqlParams.add("%"+args.get("deviceKey")+"%");
|
|
|
|
+ sqlParams.add("%"+args.get("deviceKey")+"%");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ sql.append(" order by device_code");
|
|
|
|
+
|
|
|
|
+ Object[] sqlArgs=sqlParams.size()>0?sqlParams.toArray():null;
|
|
|
|
+ return dao.queryForPagedData(sql.toString(),pageNo, pageSize,DeviceVO.class ,sqlArgs);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String add(DevicePO device) {
|
|
|
|
+ UUIDHexGenerator uuid=UUIDHexGenerator.getInstance();
|
|
|
|
+ device.setDeviceId(uuid.generate());
|
|
|
|
+ device.setModifyTime(new Date());
|
|
|
|
+ device.setDelIf(false);
|
|
|
|
+ dao.insert(device,"tzl_gather_device");
|
|
|
|
+ return device.getDeviceId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean delete(String deviceId) {
|
|
|
|
+ String sql="update tzl_gather_device set del_if=true,modify_time=now() where device_id=?";
|
|
|
|
+ dao.exeUpdate(sql,deviceId);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public DeviceVO get(String deviceId) {
|
|
|
|
+ String sql="""
|
|
|
|
+ select w.well_name,d.* from tzl_gather_device d
|
|
|
|
+ left join tzl_well w on d.well_id=w.well_id and w.del_if=false
|
|
|
|
+ where d.device_id=?
|
|
|
|
+ """;
|
|
|
|
+ return dao.queryForPojo(sql,DeviceVO.class,deviceId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public boolean update(DevicePO device) {
|
|
|
|
+ device.setModifyTime(new Date());
|
|
|
|
+ device.setDelIf(false);
|
|
|
|
+ return dao.update(device, "tzl_gather_device", "device_id")>0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean existDevice(String deviceCode,String deviceId) {
|
|
|
|
+ if(StringUtils.isBlank(deviceId)) {
|
|
|
|
+ String sql="select count(1) from tzl_gather_device where del_if=false and device_code=?";
|
|
|
|
+ return dao.queryForObject(sql, Integer.class,deviceCode)>0;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ String sql="select count(1) from tzl_gather_device where del_if=false and device_code=? and device_id!=?";
|
|
|
|
+ return dao.queryForObject(sql, Integer.class, deviceCode,deviceId)>0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|