Commit 97834e70 by 高晓磊

船舶管理增加校验code唯一的方法

parent dbccde40
......@@ -20,4 +20,6 @@ public interface ShipInfoDao extends BaseDao {
List<KObject> getByName(String name, UUID id);
void modify(KObject kobject);
List<KObject> getByCode(String code, UUID id);
}
......@@ -97,6 +97,17 @@ public class ShipInfoDaoImpl extends AbstractBaseDao implements ShipInfoDao, Shi
template.merge(kobject);
}
@Override
public List<KObject> getByCode(String code, UUID id) {
KClass bean = Amino.getStaticMetadataContext().getBean(ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.add(Restrictions.eq("shipCodeNum", code));
if (id != null) {
detachedCriteria.add(Restrictions.ne("id", id));
}
return (List<KObject>) template.findByCriteria(detachedCriteria);
}
@Override
......
......@@ -57,4 +57,12 @@ public class ShipInfoServiceImpl implements ShipInfoService {
public void deleteById(UUID id) {
shipInfoDao.deleteById(id);
}
@Override
public KObject getByCode(String code, UUID id) {
List<KObject> kObjects = shipInfoDao.getByCode(code,id);
if(CollectionUtils.isEmpty(kObjects)){
return null;
}
return kObjects.get(0); }
}
......@@ -18,4 +18,6 @@ public interface ShipInfoService {
void update(KObject kobject);
void deleteById(UUID id);
KObject getByCode(String code, UUID id);
}
......@@ -115,4 +115,23 @@ public class ShipInfoController {
}
/**
* 查询是否有重名
* @param name
* @return
*/
@GetMapping("/validateCode")
public ResponseObj validateCode(@RequestParam("code") String code, @RequestParam(value = "id",required = false) UUID id){
if(StringUtils.isEmpty(code)){
return ResponseObj.error(400,"编号不能为空");
}
KObject kObject = shipInfoService.getByCode(code,id);
if(kObject != null){
return ResponseObj.error("船舶名称已存在!");
}
return ResponseObj.success();
}
}
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