|
@@ -0,0 +1,92 @@
|
|
|
+package com.hb.proj.base.service;
|
|
|
+
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.hb.proj.model.SideTreeNode;
|
|
|
+import com.hb.proj.model.Well;
|
|
|
+import com.hb.proj.model.WellVO;
|
|
|
+import com.hb.xframework.dao.core.SpringJdbcDAO;
|
|
|
+import com.hb.xframework.dao.util.UUIDHexGenerator;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class WellService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SpringJdbcDAO dao;
|
|
|
+
|
|
|
+
|
|
|
+ private String tabName="tzl_well";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过父节点查询直接子节点---用于主页侧边树
|
|
|
+ * @param superId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<SideTreeNode> loadSideTreeSubNodes(String superId){
|
|
|
+ StringBuilder sql=new StringBuilder();
|
|
|
+ sql.append("select w.well_id id,w.well_name name,w.org_id super_id,'"+SideTreeNode.WELL_NODE+"' node_type,1 type_end,1 is_leaf ");
|
|
|
+ sql.append(" from tzl_well w");
|
|
|
+
|
|
|
+ sql.append(" where w.del_if=false and w.org_id=?");
|
|
|
+ return dao.queryForList(sql.toString(),SideTreeNode.class, superId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String insert(Well well) {
|
|
|
+ UUIDHexGenerator uuid = UUIDHexGenerator.getInstance();
|
|
|
+ well.setWellId(uuid.generate());
|
|
|
+ well.setCreateTime(new Date());
|
|
|
+ well.setModifyTime(well.getCreateTime());
|
|
|
+ well.setDelIf(false);
|
|
|
+ dao.insert(well, tabName);
|
|
|
+ return well.getWellId();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean update(Well well) {
|
|
|
+ well.setModifyTime(new Date());
|
|
|
+ return dao.update(well, "tzl_well", "well_id")>0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void delete(String wellId) {
|
|
|
+ dao.exeUpdate("update tzl_well set del_if=true,modify_time=now() where well_id=?",wellId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public WellVO get(String wellId){
|
|
|
+ String sql="""
|
|
|
+
|
|
|
+ select w.*,
|
|
|
+ (select group_concat(d.device_code) from tzl_gather_device d where d.well_id=w.well_id and d.del_if=false group by d.well_id) device_code
|
|
|
+ from tzl_well w
|
|
|
+ where w.well_id=?
|
|
|
+
|
|
|
+ """;
|
|
|
+ return dao.queryForPojo(sql,WellVO.class,wellId);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public boolean existWellName(String wellName,String wellId) {
|
|
|
+ if(StringUtils.isBlank(wellName)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String sql="select count(1) from tzl_well where del_if=false and well_name=?";
|
|
|
+ Object[] args={wellName.trim()};
|
|
|
+ if(StringUtils.isNotBlank(wellId)) {
|
|
|
+ sql+=" and well_id!=?";
|
|
|
+ args=new Object[]{wellName.trim(),wellId};
|
|
|
+ }
|
|
|
+ return dao.queryForObject(sql, Integer.class, args)>0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|