Commit 59366644 by 高晓磊

砂石类型管理功能提交

parent 8f27df25
...@@ -21,4 +21,7 @@ public interface DinasTypeDao extends BaseDao { ...@@ -21,4 +21,7 @@ public interface DinasTypeDao extends BaseDao {
void modify(KObject kobject); void modify(KObject kobject);
boolean checkedStation(UUID dinasTypeId, UUID stationId);
boolean unCheckedStation(UUID dinasTypeId, UUID stationId);
} }
...@@ -10,6 +10,7 @@ import com.xyst.dinas.biz.constant.DinasTypeConstant; ...@@ -10,6 +10,7 @@ import com.xyst.dinas.biz.constant.DinasTypeConstant;
import com.xyst.dinas.biz.dao.DinasTypeDao; import com.xyst.dinas.biz.dao.DinasTypeDao;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.query.NativeQuery;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
...@@ -22,6 +23,14 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D ...@@ -22,6 +23,14 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
@Autowired @Autowired
private HibernateTemplate template; private HibernateTemplate template;
private String insertOrUpdateDinasTypeStationHql=" inz_kunlun01.xyst_dinas_biz_station_dinas_type " +
"set station_id = :stationId , dinas_type_id =:dinasTypeId ";
private String deleteOrSelectDinasTypeStationHql=" from inz_kunlun01.xyst_dinas_biz_station_dinas_type " +
"where station_id= :stationId and dinas_type_id=:dinasTypeId";
/** /**
* 抽象方法,需要实现类提供HibernateTemplate * 抽象方法,需要实现类提供HibernateTemplate
* *
...@@ -56,7 +65,7 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D ...@@ -56,7 +65,7 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
detachedCriteria.add(Restrictions.eq("department.id", departmentId)); detachedCriteria.add(Restrictions.eq("department.id", departmentId));
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria,offset,page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize());
page.setDatas(list); page.setDatas(list);
page.setTotal(template.findByCriteria(detachedCriteria).size()); page.setTotal(template.findByCriteria(detachedCriteria).size());
return page; return page;
...@@ -71,7 +80,7 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D ...@@ -71,7 +80,7 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
detachedCriteria.add(Restrictions.eq("department.id", departmentId)); detachedCriteria.add(Restrictions.eq("department.id", departmentId));
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.add(Restrictions.eq("dinasTypeName", name)); detachedCriteria.add(Restrictions.eq("dinasTypeName", name));
if(id!=null){ if (id != null) {
detachedCriteria.add(Restrictions.ne("id", id)); detachedCriteria.add(Restrictions.ne("id", id));
} }
...@@ -81,34 +90,79 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D ...@@ -81,34 +90,79 @@ public class DinasTypeDaoImpl extends AbstractBaseDao implements DinasTypeDao, D
@Override @Override
public void modify(KObject kobject) { public void modify(KObject kobject) {
KObject id = load(kobject.getUuid("id")); KObject id = load(kobject.getUuid("id"));
kobject.set("creator",id.get("creator")); kobject.set("creator", id.get("creator"));
kobject.set("createTime",id.getDate("createTime")); kobject.set("createTime", id.getDate("createTime"));
KObject staff = AminoContextHolder.getContext().getStaff(); KObject staff = AminoContextHolder.getContext().getStaff();
kobject.set("modifyTime",new Date()); kobject.set("modifyTime", new Date());
kobject.set("modifier",staff.getUuid("id")); kobject.set("modifier", staff.getUuid("id"));
kobject.set("del",true); kobject.set("del", true);
template.merge(kobject); template.merge(kobject);
} }
@Override
public boolean checkedStation(UUID dinasTypeId, UUID stationId) {
Boolean hasCount = getHasCount(dinasTypeId, stationId);
if(hasCount){
return template.executeWithNativeSession(session -> {
NativeQuery<Integer> nativeQuery = session.createNativeQuery(
"insert into " + insertOrUpdateDinasTypeStationHql, Integer.class);
nativeQuery.setParameter("stationId", stationId);
nativeQuery.setParameter("dinasTypeId", dinasTypeId);
int count = nativeQuery.executeUpdate();
return count == 1;
});
}
else{ return false;
}
}
@Override
public boolean unCheckedStation(UUID dinasTypeId, UUID stationId) {
Boolean hasCount = getHasCount(dinasTypeId, stationId);
if(hasCount){
return template.executeWithNativeSession(session -> {
NativeQuery<Integer> nativeQuery = session.createNativeQuery(
"delete " + deleteOrSelectDinasTypeStationHql, Integer.class);
nativeQuery.setParameter("stationId", stationId);
nativeQuery.setParameter("dinasTypeId", dinasTypeId);
int count = nativeQuery.executeUpdate();
return count == 1;
});
}
return false;
}
private Boolean getHasCount(UUID dinasTypeId, UUID stationId) {
return template.executeWithNativeSession(session -> {
NativeQuery<Integer> nativeQuery = session.createNativeQuery(
"select count(1) "+deleteOrSelectDinasTypeStationHql, Integer.class);
nativeQuery.setParameter("stationId", stationId);
nativeQuery.setParameter("dinasTypeId", dinasTypeId);
Integer singleResult = nativeQuery.getSingleResult();
return singleResult != null && singleResult == 0;
});
}
@Override @Override
public UUID create(KObject kObject) { public UUID create(KObject kObject) {
KObject staff = AminoContextHolder.getContext().getStaff(); KObject staff = AminoContextHolder.getContext().getStaff();
kObject.set("department", staff.get("department")); kObject.set("department", staff.get("department"));
kObject.set("id",UUID.randomUUID()); kObject.set("id", UUID.randomUUID());
kObject.set("creator",staff); kObject.set("creator", staff);
kObject.set("createTime", new Date()); kObject.set("createTime", new Date());
kObject.set("del",false); kObject.set("del", false);
return ((UUID)template.save(kObject)); return ((UUID) template.save(kObject));
} }
@Override @Override
public void deleteById(UUID id) { public void deleteById(UUID id) {
KObject staff = AminoContextHolder.getContext().getStaff(); KObject staff = AminoContextHolder.getContext().getStaff();
KObject kobject = (KObject) template.load(ENTITY, id); KObject kobject = (KObject) template.load(ENTITY, id);
kobject.set("modifyTime",new Date()); kobject.set("modifyTime", new Date());
kobject.set("modifier",staff); kobject.set("modifier", staff);
kobject.set("del",true); kobject.set("del", true);
template.update(kobject); template.update(kobject);
} }
......
...@@ -68,7 +68,7 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat ...@@ -68,7 +68,7 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
KObject staff = AminoContextHolder.getContext().getStaff(); KObject staff = AminoContextHolder.getContext().getStaff();
kobject.set("modifyTime",new Date()); kobject.set("modifyTime",new Date());
kobject.set("modifier",staff.getUuid("id")); kobject.set("modifier",staff.getUuid("id"));
kobject.set("del",true); kobject.set("del",false);
template.merge(kobject); template.merge(kobject);
} }
...@@ -77,7 +77,7 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat ...@@ -77,7 +77,7 @@ public class StationDaoImpl extends AbstractBaseDao implements StationDao, Stat
public UUID create(KObject kObject) { public UUID create(KObject kObject) {
KObject staff = AminoContextHolder.getContext().getStaff(); KObject staff = AminoContextHolder.getContext().getStaff();
kObject.set("department", staff.get("department")); kObject.set("department", staff.get("department"));
kObject.set("id",UUID.randomUUID()); // kObject.set("id",UUID.randomUUID());
kObject.set("creator",staff); kObject.set("creator",staff);
kObject.set("createTime", new Date()); kObject.set("createTime", new Date());
kObject.set("del",false); kObject.set("del",false);
......
...@@ -51,4 +51,14 @@ public class DinasTypeServiceImpl implements DinasTypeService { ...@@ -51,4 +51,14 @@ public class DinasTypeServiceImpl implements DinasTypeService {
public void deleteById(UUID id) { public void deleteById(UUID id) {
dinasTypeDao.deleteById(id); dinasTypeDao.deleteById(id);
} }
@Override
public boolean checkedStation(UUID dinasTypeId, UUID stationId) {
return dinasTypeDao.checkedStation(dinasTypeId,stationId);
}
@Override
public boolean unCheckedStation(UUID dinasTypeId, UUID stationId) {
return dinasTypeDao.unCheckedStation(dinasTypeId,stationId);
}
} }
...@@ -19,4 +19,8 @@ public interface DinasTypeService { ...@@ -19,4 +19,8 @@ public interface DinasTypeService {
void update(KObject kobject); void update(KObject kobject);
void deleteById(UUID id); void deleteById(UUID id);
boolean checkedStation(UUID dinasTypeId, UUID stationId);
boolean unCheckedStation(UUID dinasTypeId, UUID stationId);
} }
...@@ -115,4 +115,38 @@ public class DinasTypeController { ...@@ -115,4 +115,38 @@ public class DinasTypeController {
return ResponseObj.success(); return ResponseObj.success();
} }
/**
* 勾选场站
* @return
*/
@PostMapping("/checkedStation")
public ResponseObj checkedStation(@RequestParam("dinasTypeId") UUID dinasTypeId, @RequestParam("stationId") UUID stationId){
if(null==dinasTypeId){
return ResponseObj.error("未查询到砂石类型信息!");
}
if(null==stationId){
return ResponseObj.error("未查询到场站信息!");
}
boolean aBoolean = dinasTypeService.checkedStation(dinasTypeId,stationId);
return aBoolean?ResponseObj.success("勾选成功"):ResponseObj.error("勾选失败");
}
/**
* 取消勾选场站
*/
@PostMapping("/unCheckedStation")
public ResponseObj unCheckedStation(@RequestParam("dinasTypeId") UUID dinasTypeId, @RequestParam("stationId") UUID stationId){
if(null==dinasTypeId){
return ResponseObj.error("未查询到砂石类型信息!");
}
if(null==stationId){
return ResponseObj.error("未查询到场站信息!");
}
boolean aBoolean = dinasTypeService.unCheckedStation(dinasTypeId,stationId);
return aBoolean?ResponseObj.success("取消勾选成功"):ResponseObj.error("取消勾选失败");
}
} }
...@@ -76,6 +76,9 @@ public class StationController { ...@@ -76,6 +76,9 @@ public class StationController {
if(StringUtils.isEmpty(kobject.getString("telephone"))){ if(StringUtils.isEmpty(kobject.getString("telephone"))){
return ResponseObj.error(400,"联系人电话不能为空"); return ResponseObj.error(400,"联系人电话不能为空");
} }
if(kobject.getUuid("id") == null){
return ResponseObj.error(400,"'id' must be not null!");
}
UUID id = stationService.addStation(kobject); UUID id = stationService.addStation(kobject);
return ResponseObj.success("保存成功", id); return ResponseObj.success("保存成功", id);
} }
......
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