Commit 229cd47a by 杨清松

职工岗位存储改为对象

parent c91f5e74
......@@ -17,4 +17,6 @@ public interface DinasOrganizationDao {
List<KObject> queryFollowerByStaffId(UUID id);
KObject load(UUID id);
List<UUID> queryStaffByPostId(String postId);
}
package com.xyst.dinas.biz.internal.dao;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -8,12 +9,15 @@ import java.util.UUID;
import javax.persistence.Tuple;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.NativeQuery;
import org.hibernate.query.Query;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.HibernateOperations;
import org.springframework.orm.hibernate5.HibernateTemplate;
import com.beecode.amino.common.Convert;
import com.beecode.bcp.type.KObject;
import com.xyst.dinas.biz.constant.DinasOrganizationConstant;
import com.xyst.dinas.biz.constant.PositionConstant;
......@@ -109,4 +113,28 @@ public class DinasOrganizationDaoImpl implements DinasOrganizationDao, DinasOrga
}
private static final String queryStaffSql = "SELECT id FROM bap_staff WHERE CASE WHEN JSON_VALID(duty) THEN JSON_EXTRACT(duty,'$.id') =:postId ELSE NULL END ";
@Override
public List<UUID> queryStaffByPostId(String postId) {
return template.execute(new HibernateCallback<List<UUID>>() {
List<UUID> uuids = new ArrayList<>();
@Override
public List<UUID> doInHibernate(Session session) throws HibernateException {
//List<Tuple> uuids1 = session.createSQLQuery(queryStaffSql).addEntity(Tuple.class).setParameter("postId", postId).list();
Query<Tuple> query = session.createNativeQuery(queryStaffSql, Tuple.class);
query.setParameter("postId", postId);
List<Tuple> result = query.getResultList();
for (Tuple tuple : result) {
System.out.println(Convert.toUUID(tuple.get(0)));
uuids.add(Convert.toUUID(tuple.get(0)));
}
return uuids;
}
});
}
}
......@@ -55,6 +55,12 @@ public class DinasOrganizationServiceImpl implements DinasOrganizationService {
return dinasOrganizationDao.load(id);
}
@Override
public List<UUID> queryStaffByPostId(String postId) {
List<UUID> staffList = dinasOrganizationDao.queryStaffByPostId(postId);
return staffList;
}
}
......@@ -5,6 +5,8 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.persistence.Tuple;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -59,8 +61,18 @@ public class PositionServiceImpl implements PositionService, PositionConstant {
KObject kObject = positionDao.load(UUID.fromString(jsonObject.getString("id")));
//如果岗位名称更改,更改已经关联的岗位名称
// if (!kObject.getString("name").equals(jsonObject.getString("name"))) {
// List<KObject> allStaffByDeptList = staffService.getAllByDept(department.getUuid("id"));
if (!kObject.getString("name").equals(jsonObject.getString("name"))) {
//根据岗位id查询职工表里 哪些在使用该岗位,并更改
List<UUID> staffList = dinasOrganizationService.queryStaffByPostId(jsonObject.getString("id"));
for (UUID staffId : staffList) {
//更改职位名称
KObject updateStaff = staffService.getById(staffId);
updateStaff.set("duty", new JSONObject()
.put("name", jsonObject.getString("name"))
.put("id", jsonObject.getString("id"))
.toString());
}
// List<KObject> allStaffByDeptList = staffService.getAllByDept(department.getUuid("id"));
// if (allStaffByDeptList.size() > 0 && allStaffByDeptList != null) {
// for (int i = 0; i < allStaffByDeptList.size(); i++) {
// KObject staffByDept = allStaffByDeptList.get(i);
......@@ -75,7 +87,7 @@ public class PositionServiceImpl implements PositionService, PositionConstant {
// }
// }
// }
// }
}
kObject.set("modifyTime", new Date());
kObject.set("modifier", staff);
kObject.set("name", jsonObject.getString("name"));
......@@ -91,16 +103,16 @@ public class PositionServiceImpl implements PositionService, PositionConstant {
@Override
public Object queryPositionByDept() {
KObject staff = AminoContextHolder.getContext().getStaff();
KObject department = staff.get("department");
List<KObject> positionList = positionDao.queryPositionByDept(department.getUuid("id"));
KObject currentRegionalCompany = getCurrentLoginRegionalCompany();
//KObject department = staff.get("department");
List<KObject> positionList = positionDao.queryPositionByDept(currentRegionalCompany.getUuid("id"));
return ResponseObj.success("操作成功", positionList);
}
@Override
public Object queryPositionIsUse(String name) {
KObject staff = AminoContextHolder.getContext().getStaff();
List<KObject> staffList = positionDao.queryStaffByPosition(name, staff.get("department").getUuid("id"));
KObject currentRegionalCompany = getCurrentLoginRegionalCompany();
List<KObject> staffList = positionDao.queryStaffByPosition(name, currentRegionalCompany.getUuid("id"));
if (staffList != null && staffList.size() > 0) {
return ResponseObj.error("该岗位已经被使用,不支持删除操作");
}
......@@ -109,10 +121,10 @@ public class PositionServiceImpl implements PositionService, PositionConstant {
@Override
public Boolean verifyPositionName(String name) {
KObject staff = AminoContextHolder.getContext().getStaff();
KObject currentRegionalCompany = getCurrentLoginRegionalCompany();
//当前登录人所在区域公司
KObject department = staff.get("department");
List<KObject> list = positionDao.queryPositionByName(name, department.getUuid("id"));
//KObject department = staff.get("department");
List<KObject> list = positionDao.queryPositionByName(name, currentRegionalCompany.getUuid("id"));
Boolean flag = false;
if (list != null && list.size() > 0 ) {
flag = true;
......
......@@ -16,4 +16,6 @@ public interface DinasOrganizationService {
List<KObject> queryFollowerByUserName(String name);
KObject load(UUID id);
List<UUID> queryStaffByPostId(String postId);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment