• 通用删除接口

com.yyjz.icop.pubapp.platform.template.DeleteTemplate<E extends SuperEntity>

@Component
public class DeleteTemplate<E extends SuperEntity> extends AbstractCommonTeplate<E> {

    @Autowired
    private BillDelete<SuperEntity> delete;

    @SuppressWarnings("unchecked")
    @Override
    public E[] operateDB(E[] entitys) {
        Class<SuperEntity> clazz = (Class<SuperEntity>) entitys[0].getClass();
        List<String> primaryKeys = new ArrayList<String>();
        for (E entity : entitys) {
            primaryKeys.add(MetaDataUtil.getPrimaryKey(entity));
        }
        E[] backEntitys = (E[]) delete.delete(primaryKeys, clazz);
        return backEntitys;
    }

}
  • 通用插入接口

com.yyjz.icop.pubapp.platform.template.InsertTemplate<E extends SuperEntity>

@Component
public class InsertTemplate<E extends SuperEntity> extends AbstractCommonTeplate<E> {

    @Override
    public E[] operateDB(E[] entitys) {
        E[] backEntitys = (E[]) dao.batchInsert(entitys);
        return backEntitys;
    }

}
  • 通用更新接口

com.yyjz.icop.pubapp.platform.template.UpdateTemplate<E extends SuperEntity>

@Component
public class UpdateTemplate<E extends SuperEntity> extends AbstractCommonTeplate<E> {

    @SuppressWarnings("unchecked")
    @Override
    public E[] operateDB(E[] entitys) {
        for (E entity : entitys) {
            List<JSONObject> subfiledlst = MetaDataUtil.getChildFileds(entity.getClass());
            for (JSONObject subfiledobj : subfiledlst) {
                List<SuperSubEntity> sublst = (List<SuperSubEntity>) entity
                        .getAttributeValue(subfiledobj.getString(MetaDataUtil.CHILD_FIELDNAME));
                for (SuperSubEntity subEntity : sublst) {
                    // 新增和修改暂时不需要处理,删除设置子表状态
                    if (!StringUtil.isEmpty(subEntity.getRowState())
                            && subEntity.getRowState().equals(EntityStatus.DEL.getStatus())) {
                        subEntity.setDr(SuperEntity.IS_DELETE_YES);
                    }
                }
            }
        }
        return (E[]) dao.batchUpdate(entitys, (Class<E>) entitys[0].getClass());

    }

}

results matching ""

    No results matching ""